public function loadClassMetadata(LoadClassMetadataEventArgs $eventArgs)
    {
        /** @var ClassMetadata $metadata */
        $metadata = $eventArgs->getClassMetadata();

        $reflectionClass = $metadata->getReflectionClass();

        if (!$reflectionClass || !$this->hasTrait($reflectionClass, 'Blast\BaseEntitiesBundle\Entity\Traits\Timestampable')) {
            return;
        } // return if current entity doesn't use Timestampable trait

        // Check if parents already have the Timestampable trait
        foreach ($metadata->parentClasses as $parent) {
            if ($this->classAnalyzer->hasTrait($parent, 'Blast\BaseEntitiesBundle\Entity\Traits\Timestampable')) {
                return;
            }
        }

        $this->logger->debug(
            '[TimestampableListener] Entering TimestampableListener for « loadClassMetadata » event'
        );

        // setting default mapping configuration for Timestampable

        // createdAt
        $metadata->mapField([
            'fieldName' => 'createdAt',
            'type'      => 'datetime',
        ]);

        // updatedAt
        $metadata->mapField([
            'fieldName' => 'updatedAt',
            'type'      => 'datetime',
        ]);

        $this->logger->debug(
            '[TimestampableListener] Added Timestampable mapping metadata to Entity',
            ['class' => $metadata->getName()]
        );
    }
public function loadClassMetadata(LoadClassMetadataEventArgs $eventArgs)
    {
        /** @var ClassMetadata $metadata */
        $metadata = $eventArgs->getClassMetadata();

        $reflectionClass = $metadata->getReflectionClass();

        if (!$reflectionClass || !$this->hasTrait($reflectionClass, 'Blast\BaseEntitiesBundle\Entity\Traits\Timestampable')) {
            return;
        } // return if current entity doesn't use Timestampable trait

        // Check if parents already have the Timestampable trait
        foreach ($metadata->parentClasses as $parent) {
            if ($this->classAnalyzer->hasTrait($parent, 'Blast\BaseEntitiesBundle\Entity\Traits\Timestampable')) {
                return;
            }
        }

        $this->logger->debug(
            '[TimestampableListener] Entering TimestampableListener for « loadClassMetadata » event'
        );

        // setting default mapping configuration for Timestampable

        // createdAt
        $metadata->mapField([
            'fieldName' => 'createdAt',
            'type'      => 'datetime',
        ]);

        // updatedAt
        $metadata->mapField([
            'fieldName' => 'updatedAt',
            'type'      => 'datetime',
        ]);

        $this->logger->debug(
            '[TimestampableListener] Added Timestampable mapping metadata to Entity',
            ['class' => $metadata->getName()]
        );
    }
public function loadClassMetadata ( LoadClassMetadataEventArgs $ eventArgs ) { /** @var ClassMetadata $metadata */ $ metadata = $ eventArgs -> getClassMetadata ( ) ; $ reflectionClass = $ metadata -> getReflectionClass ( ) ; if ( ! $ reflectionClass || ! $ this -> hasTrait ( $ reflectionClass , 'Blast\BaseEntitiesBundle\Entity\Traits\Timestampable' ) ) { return ; } // return if current entity doesn't use Timestampable trait // Check if parents already have the Timestampable trait foreach ( $ metadata -> parentClasses as $ parent ) { if ( $ this -> classAnalyzer -> hasTrait ( $ parent , 'Blast\BaseEntitiesBundle\Entity\Traits\Timestampable' ) ) { return ; } } $ this -> logger -> debug ( '[TimestampableListener] Entering TimestampableListener for « loadClassMetadata » event' ) ; // setting default mapping configuration for Timestampable // createdAt $ metadata -> mapField ( [ 'fieldName' => 'createdAt' , 'type' => 'datetime' , ] ) ; // updatedAt $ metadata -> mapField ( [ 'fieldName' => 'updatedAt' , 'type' => 'datetime' , ] ) ; $ this -> logger -> debug ( '[TimestampableListener] Added Timestampable mapping metadata to Entity' , [ 'class' => $ metadata -> getName ( ) ] ) ; }
define Timestampable mapping at runtime.

@param LoadClassMetadataEventArgs $eventArgs
define Timestampable mapping at runtime .