EventListener/DiscriminatorListener.php
public function loadClassMetadata(LoadClassMetadataEventArgs $eventArgs)
    {
        $metadata = $eventArgs->getClassMetadata();
        $class = $metadata->getReflectionClass();

        if ($class === null) {
            $class = new \ReflectionClass($metadata->getName());
        }

        if ($this->className && $class->getName() == "Hexmedia\\UserBundle\\Entity\\User") {
            $reader = new AnnotationReader();
            $discriminatorMap = [];
            $discriminatorMapAnnotation = $reader->getClassAnnotation($class, 'Doctrine\ORM\Mapping\DiscriminatorMap');

            if ($discriminatorMapAnnotation) {
                $discriminatorMap = $discriminatorMapAnnotation->value;
            }

            $discriminatorMap['users'] = $this->className;
            $discriminatorMap['users_base'] = "Hexmedia\\UserBundle\\Entity\\User";

            $metadata->setDiscriminatorColumn(["name" => "type", "length" => 255]);
            $metadata->setInheritanceType(ClassMetadataInfo::INHERITANCE_TYPE_SINGLE_TABLE);
            $metadata->setDiscriminatorMap($discriminatorMap);

        }
    }
public function loadClassMetadata(LoadClassMetadataEventArgs $eventArgs)
    {
        $metadata = $eventArgs->getClassMetadata();
        $class = $metadata->getReflectionClass();

        if ($class === null) {
            $class = new \ReflectionClass($metadata->getName());
        }

        if ($this->className && $class->getName() == "Hexmedia\\UserBundle\\Entity\\User") {
            $reader = new AnnotationReader();
            $discriminatorMap = [];
            $discriminatorMapAnnotation = $reader->getClassAnnotation($class, 'Doctrine\ORM\Mapping\DiscriminatorMap');

            if ($discriminatorMapAnnotation) {
                $discriminatorMap = $discriminatorMapAnnotation->value;
            }

            $discriminatorMap['users'] = $this->className;
            $discriminatorMap['users_base'] = "Hexmedia\\UserBundle\\Entity\\User";

            $metadata->setDiscriminatorColumn(["name" => "type", "length" => 255]);
            $metadata->setInheritanceType(ClassMetadataInfo::INHERITANCE_TYPE_SINGLE_TABLE);
            $metadata->setDiscriminatorMap($discriminatorMap);

        }
    }
public function loadClassMetadata ( LoadClassMetadataEventArgs $ eventArgs ) { $ metadata = $ eventArgs -> getClassMetadata ( ) ; $ class = $ metadata -> getReflectionClass ( ) ; if ( $ class === null ) { $ class = new \ ReflectionClass ( $ metadata -> getName ( ) ) ; } if ( $ this -> className && $ class -> getName ( ) == "Hexmedia\\UserBundle\\Entity\\User" ) { $ reader = new AnnotationReader ( ) ; $ discriminatorMap = [ ] ; $ discriminatorMapAnnotation = $ reader -> getClassAnnotation ( $ class , 'Doctrine\ORM\Mapping\DiscriminatorMap' ) ; if ( $ discriminatorMapAnnotation ) { $ discriminatorMap = $ discriminatorMapAnnotation -> value ; } $ discriminatorMap [ 'users' ] = $ this -> className ; $ discriminatorMap [ 'users_base' ] = "Hexmedia\\UserBundle\\Entity\\User" ; $ metadata -> setDiscriminatorColumn ( [ "name" => "type" , "length" => 255 ] ) ; $ metadata -> setInheritanceType ( ClassMetadataInfo :: INHERITANCE_TYPE_SINGLE_TABLE ) ; $ metadata -> setDiscriminatorMap ( $ discriminatorMap ) ; } }
Sets the discriminator map according to the config

@param LoadClassMetadataEventArgs $eventArgs
Sets the discriminator map according to the config