vendor/doctrine/orm/lib/Doctrine/ORM/Mapping/ClassMetadataFactory.php line 149

Open in your IDE?
  1. <?php
  2. /*
  3.  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  4.  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  5.  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  6.  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  7.  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  8.  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  9.  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  10.  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  11.  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  12.  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  13.  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  14.  *
  15.  * This software consists of voluntary contributions made by many individuals
  16.  * and is licensed under the MIT license. For more information, see
  17.  * <http://www.doctrine-project.org>.
  18.  */
  19. namespace Doctrine\ORM\Mapping;
  20. use Doctrine\Common\EventManager;
  21. use Doctrine\DBAL\Platforms;
  22. use Doctrine\DBAL\Platforms\AbstractPlatform;
  23. use Doctrine\ORM\EntityManagerInterface;
  24. use Doctrine\ORM\Event\LoadClassMetadataEventArgs;
  25. use Doctrine\ORM\Event\OnClassMetadataNotFoundEventArgs;
  26. use Doctrine\ORM\Events;
  27. use Doctrine\ORM\Id\AssignedGenerator;
  28. use Doctrine\ORM\Id\BigIntegerIdentityGenerator;
  29. use Doctrine\ORM\Id\IdentityGenerator;
  30. use Doctrine\ORM\Id\SequenceGenerator;
  31. use Doctrine\ORM\Id\UuidGenerator;
  32. use Doctrine\ORM\ORMException;
  33. use Doctrine\Persistence\Mapping\AbstractClassMetadataFactory;
  34. use Doctrine\Persistence\Mapping\ClassMetadata as ClassMetadataInterface;
  35. use Doctrine\Persistence\Mapping\Driver\MappingDriver;
  36. use Doctrine\Persistence\Mapping\ReflectionService;
  37. use ReflectionClass;
  38. use ReflectionException;
  39. use function array_map;
  40. use function class_exists;
  41. use function count;
  42. use function end;
  43. use function explode;
  44. use function is_subclass_of;
  45. use function strpos;
  46. use function strtolower;
  47. /**
  48.  * The ClassMetadataFactory is used to create ClassMetadata objects that contain all the
  49.  * metadata mapping information of a class which describes how a class should be mapped
  50.  * to a relational database.
  51.  */
  52. class ClassMetadataFactory extends AbstractClassMetadataFactory
  53. {
  54.     /** @var EntityManagerInterface|null */
  55.     private $em;
  56.     /** @var AbstractPlatform */
  57.     private $targetPlatform;
  58.     /** @var MappingDriver */
  59.     private $driver;
  60.     /** @var EventManager */
  61.     private $evm;
  62.     /** @var mixed[] */
  63.     private $embeddablesActiveNesting = [];
  64.     /**
  65.      * {@inheritDoc}
  66.      */
  67.     protected function loadMetadata($name)
  68.     {
  69.         $loaded parent::loadMetadata($name);
  70.         array_map([$this'resolveDiscriminatorValue'], array_map([$this'getMetadataFor'], $loaded));
  71.         return $loaded;
  72.     }
  73.     public function setEntityManager(EntityManagerInterface $em)
  74.     {
  75.         $this->em $em;
  76.     }
  77.     /**
  78.      * {@inheritDoc}
  79.      */
  80.     protected function initialize()
  81.     {
  82.         $this->driver      $this->em->getConfiguration()->getMetadataDriverImpl();
  83.         $this->evm         $this->em->getEventManager();
  84.         $this->initialized true;
  85.     }
  86.     /**
  87.      * {@inheritDoc}
  88.      */
  89.     protected function onNotFoundMetadata($className)
  90.     {
  91.         if (! $this->evm->hasListeners(Events::onClassMetadataNotFound)) {
  92.             return;
  93.         }
  94.         $eventArgs = new OnClassMetadataNotFoundEventArgs($className$this->em);
  95.         $this->evm->dispatchEvent(Events::onClassMetadataNotFound$eventArgs);
  96.         return $eventArgs->getFoundMetadata();
  97.     }
  98.     /**
  99.      * {@inheritDoc}
  100.      */
  101.     protected function doLoadMetadata($class$parent$rootEntityFound, array $nonSuperclassParents)
  102.     {
  103.         /** @var ClassMetadata $class */
  104.         /** @var ClassMetadata $parent */
  105.         if ($parent) {
  106.             $class->setInheritanceType($parent->inheritanceType);
  107.             $class->setDiscriminatorColumn($parent->discriminatorColumn);
  108.             $class->setIdGeneratorType($parent->generatorType);
  109.             $this->addInheritedFields($class$parent);
  110.             $this->addInheritedRelations($class$parent);
  111.             $this->addInheritedEmbeddedClasses($class$parent);
  112.             $class->setIdentifier($parent->identifier);
  113.             $class->setVersioned($parent->isVersioned);
  114.             $class->setVersionField($parent->versionField);
  115.             $class->setDiscriminatorMap($parent->discriminatorMap);
  116.             $class->setLifecycleCallbacks($parent->lifecycleCallbacks);
  117.             $class->setChangeTrackingPolicy($parent->changeTrackingPolicy);
  118.             if (! empty($parent->customGeneratorDefinition)) {
  119.                 $class->setCustomGeneratorDefinition($parent->customGeneratorDefinition);
  120.             }
  121.             if ($parent->isMappedSuperclass) {
  122.                 $class->setCustomRepositoryClass($parent->customRepositoryClassName);
  123.             }
  124.         }
  125.         // Invoke driver
  126.         try {
  127.             $this->driver->loadMetadataForClass($class->getName(), $class);
  128.         } catch (ReflectionException $e) {
  129.             throw MappingException::reflectionFailure($class->getName(), $e);
  130.         }
  131.         // If this class has a parent the id generator strategy is inherited.
  132.         // However this is only true if the hierarchy of parents contains the root entity,
  133.         // if it consists of mapped superclasses these don't necessarily include the id field.
  134.         if ($parent && $rootEntityFound) {
  135.             $this->inheritIdGeneratorMapping($class$parent);
  136.         } else {
  137.             $this->completeIdGeneratorMapping($class);
  138.         }
  139.         if (! $class->isMappedSuperclass) {
  140.             foreach ($class->embeddedClasses as $property => $embeddableClass) {
  141.                 if (isset($embeddableClass['inherited'])) {
  142.                     continue;
  143.                 }
  144.                 if (! (isset($embeddableClass['class']) && $embeddableClass['class'])) {
  145.                     throw MappingException::missingEmbeddedClass($property);
  146.                 }
  147.                 if (isset($this->embeddablesActiveNesting[$embeddableClass['class']])) {
  148.                     throw MappingException::infiniteEmbeddableNesting($class->name$property);
  149.                 }
  150.                 $this->embeddablesActiveNesting[$class->name] = true;
  151.                 $embeddableMetadata $this->getMetadataFor($embeddableClass['class']);
  152.                 if ($embeddableMetadata->isEmbeddedClass) {
  153.                     $this->addNestedEmbeddedClasses($embeddableMetadata$class$property);
  154.                 }
  155.                 $identifier $embeddableMetadata->getIdentifier();
  156.                 if (! empty($identifier)) {
  157.                     $this->inheritIdGeneratorMapping($class$embeddableMetadata);
  158.                 }
  159.                 $class->inlineEmbeddable($property$embeddableMetadata);
  160.                 unset($this->embeddablesActiveNesting[$class->name]);
  161.             }
  162.         }
  163.         if ($parent) {
  164.             if ($parent->isInheritanceTypeSingleTable()) {
  165.                 $class->setPrimaryTable($parent->table);
  166.             }
  167.             if ($parent) {
  168.                 $this->addInheritedIndexes($class$parent);
  169.             }
  170.             if ($parent->cache) {
  171.                 $class->cache $parent->cache;
  172.             }
  173.             if ($parent->containsForeignIdentifier) {
  174.                 $class->containsForeignIdentifier true;
  175.             }
  176.             if (! empty($parent->namedQueries)) {
  177.                 $this->addInheritedNamedQueries($class$parent);
  178.             }
  179.             if (! empty($parent->namedNativeQueries)) {
  180.                 $this->addInheritedNamedNativeQueries($class$parent);
  181.             }
  182.             if (! empty($parent->sqlResultSetMappings)) {
  183.                 $this->addInheritedSqlResultSetMappings($class$parent);
  184.             }
  185.             if (! empty($parent->entityListeners) && empty($class->entityListeners)) {
  186.                 $class->entityListeners $parent->entityListeners;
  187.             }
  188.         }
  189.         $class->setParentClasses($nonSuperclassParents);
  190.         if ($class->isRootEntity() && ! $class->isInheritanceTypeNone() && ! $class->discriminatorMap) {
  191.             $this->addDefaultDiscriminatorMap($class);
  192.         }
  193.         if ($this->evm->hasListeners(Events::loadClassMetadata)) {
  194.             $eventArgs = new LoadClassMetadataEventArgs($class$this->em);
  195.             $this->evm->dispatchEvent(Events::loadClassMetadata$eventArgs);
  196.         }
  197.         $this->validateRuntimeMetadata($class$parent);
  198.     }
  199.     /**
  200.      * Validate runtime metadata is correctly defined.
  201.      *
  202.      * @param ClassMetadata               $class
  203.      * @param ClassMetadataInterface|null $parent
  204.      *
  205.      * @return void
  206.      *
  207.      * @throws MappingException
  208.      */
  209.     protected function validateRuntimeMetadata($class$parent)
  210.     {
  211.         if (! $class->reflClass) {
  212.             // only validate if there is a reflection class instance
  213.             return;
  214.         }
  215.         $class->validateIdentifier();
  216.         $class->validateAssociations();
  217.         $class->validateLifecycleCallbacks($this->getReflectionService());
  218.         // verify inheritance
  219.         if (! $class->isMappedSuperclass && ! $class->isInheritanceTypeNone()) {
  220.             if (! $parent) {
  221.                 if (count($class->discriminatorMap) === 0) {
  222.                     throw MappingException::missingDiscriminatorMap($class->name);
  223.                 }
  224.                 if (! $class->discriminatorColumn) {
  225.                     throw MappingException::missingDiscriminatorColumn($class->name);
  226.                 }
  227.                 foreach ($class->subClasses as $subClass) {
  228.                     if ((new ReflectionClass($subClass))->name !== $subClass) {
  229.                         throw MappingException::invalidClassInDiscriminatorMap($subClass$class->name);
  230.                     }
  231.                 }
  232.             }
  233.         } elseif ($class->isMappedSuperclass && $class->name === $class->rootEntityName && (count($class->discriminatorMap) || $class->discriminatorColumn)) {
  234.             // second condition is necessary for mapped superclasses in the middle of an inheritance hierarchy
  235.             throw MappingException::noInheritanceOnMappedSuperClass($class->name);
  236.         }
  237.     }
  238.     /**
  239.      * {@inheritDoc}
  240.      */
  241.     protected function newClassMetadataInstance($className)
  242.     {
  243.         return new ClassMetadata($className$this->em->getConfiguration()->getNamingStrategy());
  244.     }
  245.     /**
  246.      * Populates the discriminator value of the given metadata (if not set) by iterating over discriminator
  247.      * map classes and looking for a fitting one.
  248.      *
  249.      * @return void
  250.      *
  251.      * @throws MappingException
  252.      */
  253.     private function resolveDiscriminatorValue(ClassMetadata $metadata)
  254.     {
  255.         if (
  256.             $metadata->discriminatorValue
  257.             || ! $metadata->discriminatorMap
  258.             || $metadata->isMappedSuperclass
  259.             || ! $metadata->reflClass
  260.             || $metadata->reflClass->isAbstract()
  261.         ) {
  262.             return;
  263.         }
  264.         // minor optimization: avoid loading related metadata when not needed
  265.         foreach ($metadata->discriminatorMap as $discriminatorValue => $discriminatorClass) {
  266.             if ($discriminatorClass === $metadata->name) {
  267.                 $metadata->discriminatorValue $discriminatorValue;
  268.                 return;
  269.             }
  270.         }
  271.         // iterate over discriminator mappings and resolve actual referenced classes according to existing metadata
  272.         foreach ($metadata->discriminatorMap as $discriminatorValue => $discriminatorClass) {
  273.             if ($metadata->name === $this->getMetadataFor($discriminatorClass)->getName()) {
  274.                 $metadata->discriminatorValue $discriminatorValue;
  275.                 return;
  276.             }
  277.         }
  278.         throw MappingException::mappedClassNotPartOfDiscriminatorMap($metadata->name$metadata->rootEntityName);
  279.     }
  280.     /**
  281.      * Adds a default discriminator map if no one is given
  282.      *
  283.      * If an entity is of any inheritance type and does not contain a
  284.      * discriminator map, then the map is generated automatically. This process
  285.      * is expensive computation wise.
  286.      *
  287.      * The automatically generated discriminator map contains the lowercase short name of
  288.      * each class as key.
  289.      *
  290.      * @throws MappingException
  291.      */
  292.     private function addDefaultDiscriminatorMap(ClassMetadata $class)
  293.     {
  294.         $allClasses $this->driver->getAllClassNames();
  295.         $fqcn       $class->getName();
  296.         $map        = [$this->getShortName($class->name) => $fqcn];
  297.         $duplicates = [];
  298.         foreach ($allClasses as $subClassCandidate) {
  299.             if (is_subclass_of($subClassCandidate$fqcn)) {
  300.                 $shortName $this->getShortName($subClassCandidate);
  301.                 if (isset($map[$shortName])) {
  302.                     $duplicates[] = $shortName;
  303.                 }
  304.                 $map[$shortName] = $subClassCandidate;
  305.             }
  306.         }
  307.         if ($duplicates) {
  308.             throw MappingException::duplicateDiscriminatorEntry($class->name$duplicates$map);
  309.         }
  310.         $class->setDiscriminatorMap($map);
  311.     }
  312.     /**
  313.      * Gets the lower-case short name of a class.
  314.      *
  315.      * @param string $className
  316.      *
  317.      * @return string
  318.      */
  319.     private function getShortName($className)
  320.     {
  321.         if (strpos($className'\\') === false) {
  322.             return strtolower($className);
  323.         }
  324.         $parts explode('\\'$className);
  325.         return strtolower(end($parts));
  326.     }
  327.     /**
  328.      * Adds inherited fields to the subclass mapping.
  329.      *
  330.      * @return void
  331.      */
  332.     private function addInheritedFields(ClassMetadata $subClassClassMetadata $parentClass)
  333.     {
  334.         foreach ($parentClass->fieldMappings as $mapping) {
  335.             if (! isset($mapping['inherited']) && ! $parentClass->isMappedSuperclass) {
  336.                 $mapping['inherited'] = $parentClass->name;
  337.             }
  338.             if (! isset($mapping['declared'])) {
  339.                 $mapping['declared'] = $parentClass->name;
  340.             }
  341.             $subClass->addInheritedFieldMapping($mapping);
  342.         }
  343.         foreach ($parentClass->reflFields as $name => $field) {
  344.             $subClass->reflFields[$name] = $field;
  345.         }
  346.     }
  347.     /**
  348.      * Adds inherited association mappings to the subclass mapping.
  349.      *
  350.      * @return void
  351.      *
  352.      * @throws MappingException
  353.      */
  354.     private function addInheritedRelations(ClassMetadata $subClassClassMetadata $parentClass)
  355.     {
  356.         foreach ($parentClass->associationMappings as $field => $mapping) {
  357.             if ($parentClass->isMappedSuperclass) {
  358.                 if ($mapping['type'] & ClassMetadata::TO_MANY && ! $mapping['isOwningSide']) {
  359.                     throw MappingException::illegalToManyAssociationOnMappedSuperclass($parentClass->name$field);
  360.                 }
  361.                 $mapping['sourceEntity'] = $subClass->name;
  362.             }
  363.             //$subclassMapping = $mapping;
  364.             if (! isset($mapping['inherited']) && ! $parentClass->isMappedSuperclass) {
  365.                 $mapping['inherited'] = $parentClass->name;
  366.             }
  367.             if (! isset($mapping['declared'])) {
  368.                 $mapping['declared'] = $parentClass->name;
  369.             }
  370.             $subClass->addInheritedAssociationMapping($mapping);
  371.         }
  372.     }
  373.     private function addInheritedEmbeddedClasses(ClassMetadata $subClassClassMetadata $parentClass)
  374.     {
  375.         foreach ($parentClass->embeddedClasses as $field => $embeddedClass) {
  376.             if (! isset($embeddedClass['inherited']) && ! $parentClass->isMappedSuperclass) {
  377.                 $embeddedClass['inherited'] = $parentClass->name;
  378.             }
  379.             if (! isset($embeddedClass['declared'])) {
  380.                 $embeddedClass['declared'] = $parentClass->name;
  381.             }
  382.             $subClass->embeddedClasses[$field] = $embeddedClass;
  383.         }
  384.     }
  385.     /**
  386.      * Adds nested embedded classes metadata to a parent class.
  387.      *
  388.      * @param ClassMetadata $subClass    Sub embedded class metadata to add nested embedded classes metadata from.
  389.      * @param ClassMetadata $parentClass Parent class to add nested embedded classes metadata to.
  390.      * @param string        $prefix      Embedded classes' prefix to use for nested embedded classes field names.
  391.      */
  392.     private function addNestedEmbeddedClasses(ClassMetadata $subClassClassMetadata $parentClass$prefix)
  393.     {
  394.         foreach ($subClass->embeddedClasses as $property => $embeddableClass) {
  395.             if (isset($embeddableClass['inherited'])) {
  396.                 continue;
  397.             }
  398.             $embeddableMetadata $this->getMetadataFor($embeddableClass['class']);
  399.             $parentClass->mapEmbedded(
  400.                 [
  401.                     'fieldName' => $prefix '.' $property,
  402.                     'class' => $embeddableMetadata->name,
  403.                     'columnPrefix' => $embeddableClass['columnPrefix'],
  404.                     'declaredField' => $embeddableClass['declaredField']
  405.                             ? $prefix '.' $embeddableClass['declaredField']
  406.                             : $prefix,
  407.                     'originalField' => $embeddableClass['originalField'] ?: $property,
  408.                 ]
  409.             );
  410.         }
  411.     }
  412.     /**
  413.      * Copy the table indices from the parent class superclass to the child class
  414.      *
  415.      * @return void
  416.      */
  417.     private function addInheritedIndexes(ClassMetadata $subClassClassMetadata $parentClass)
  418.     {
  419.         if (! $parentClass->isMappedSuperclass) {
  420.             return;
  421.         }
  422.         foreach (['uniqueConstraints''indexes'] as $indexType) {
  423.             if (isset($parentClass->table[$indexType])) {
  424.                 foreach ($parentClass->table[$indexType] as $indexName => $index) {
  425.                     if (isset($subClass->table[$indexType][$indexName])) {
  426.                         continue; // Let the inheriting table override indices
  427.                     }
  428.                     $subClass->table[$indexType][$indexName] = $index;
  429.                 }
  430.             }
  431.         }
  432.     }
  433.     /**
  434.      * Adds inherited named queries to the subclass mapping.
  435.      *
  436.      * @return void
  437.      */
  438.     private function addInheritedNamedQueries(ClassMetadata $subClassClassMetadata $parentClass)
  439.     {
  440.         foreach ($parentClass->namedQueries as $name => $query) {
  441.             if (! isset($subClass->namedQueries[$name])) {
  442.                 $subClass->addNamedQuery(
  443.                     [
  444.                         'name'  => $query['name'],
  445.                         'query' => $query['query'],
  446.                     ]
  447.                 );
  448.             }
  449.         }
  450.     }
  451.     /**
  452.      * Adds inherited named native queries to the subclass mapping.
  453.      *
  454.      * @return void
  455.      */
  456.     private function addInheritedNamedNativeQueries(ClassMetadata $subClassClassMetadata $parentClass)
  457.     {
  458.         foreach ($parentClass->namedNativeQueries as $name => $query) {
  459.             if (! isset($subClass->namedNativeQueries[$name])) {
  460.                 $subClass->addNamedNativeQuery(
  461.                     [
  462.                         'name'              => $query['name'],
  463.                         'query'             => $query['query'],
  464.                         'isSelfClass'       => $query['isSelfClass'],
  465.                         'resultSetMapping'  => $query['resultSetMapping'],
  466.                         'resultClass'       => $query['isSelfClass'] ? $subClass->name $query['resultClass'],
  467.                     ]
  468.                 );
  469.             }
  470.         }
  471.     }
  472.     /**
  473.      * Adds inherited sql result set mappings to the subclass mapping.
  474.      *
  475.      * @return void
  476.      */
  477.     private function addInheritedSqlResultSetMappings(ClassMetadata $subClassClassMetadata $parentClass)
  478.     {
  479.         foreach ($parentClass->sqlResultSetMappings as $name => $mapping) {
  480.             if (! isset($subClass->sqlResultSetMappings[$name])) {
  481.                 $entities = [];
  482.                 foreach ($mapping['entities'] as $entity) {
  483.                     $entities[] = [
  484.                         'fields'                => $entity['fields'],
  485.                         'isSelfClass'           => $entity['isSelfClass'],
  486.                         'discriminatorColumn'   => $entity['discriminatorColumn'],
  487.                         'entityClass'           => $entity['isSelfClass'] ? $subClass->name $entity['entityClass'],
  488.                     ];
  489.                 }
  490.                 $subClass->addSqlResultSetMapping(
  491.                     [
  492.                         'name'          => $mapping['name'],
  493.                         'columns'       => $mapping['columns'],
  494.                         'entities'      => $entities,
  495.                     ]
  496.                 );
  497.             }
  498.         }
  499.     }
  500.     /**
  501.      * Completes the ID generator mapping. If "auto" is specified we choose the generator
  502.      * most appropriate for the targeted database platform.
  503.      *
  504.      * @return void
  505.      *
  506.      * @throws ORMException
  507.      */
  508.     private function completeIdGeneratorMapping(ClassMetadataInfo $class)
  509.     {
  510.         $idGenType $class->generatorType;
  511.         if ($idGenType === ClassMetadata::GENERATOR_TYPE_AUTO) {
  512.             if ($this->getTargetPlatform()->prefersSequences()) {
  513.                 $class->setIdGeneratorType(ClassMetadata::GENERATOR_TYPE_SEQUENCE);
  514.             } elseif ($this->getTargetPlatform()->prefersIdentityColumns()) {
  515.                 $class->setIdGeneratorType(ClassMetadata::GENERATOR_TYPE_IDENTITY);
  516.             } else {
  517.                 $class->setIdGeneratorType(ClassMetadata::GENERATOR_TYPE_TABLE);
  518.             }
  519.         }
  520.         // Create & assign an appropriate ID generator instance
  521.         switch ($class->generatorType) {
  522.             case ClassMetadata::GENERATOR_TYPE_IDENTITY:
  523.                 $sequenceName null;
  524.                 $fieldName    $class->identifier $class->getSingleIdentifierFieldName() : null;
  525.                 // Platforms that do not have native IDENTITY support need a sequence to emulate this behaviour.
  526.                 if ($this->getTargetPlatform()->usesSequenceEmulatedIdentityColumns()) {
  527.                     $columnName     $class->getSingleIdentifierColumnName();
  528.                     $quoted         = isset($class->fieldMappings[$fieldName]['quoted']) || isset($class->table['quoted']);
  529.                     $sequencePrefix $class->getSequencePrefix($this->getTargetPlatform());
  530.                     $sequenceName   $this->getTargetPlatform()->getIdentitySequenceName($sequencePrefix$columnName);
  531.                     $definition     = [
  532.                         'sequenceName' => $this->getTargetPlatform()->fixSchemaElementName($sequenceName),
  533.                     ];
  534.                     if ($quoted) {
  535.                         $definition['quoted'] = true;
  536.                     }
  537.                     $sequenceName $this
  538.                         ->em
  539.                         ->getConfiguration()
  540.                         ->getQuoteStrategy()
  541.                         ->getSequenceName($definition$class$this->getTargetPlatform());
  542.                 }
  543.                 $generator $fieldName && $class->fieldMappings[$fieldName]['type'] === 'bigint'
  544.                     ? new BigIntegerIdentityGenerator($sequenceName)
  545.                     : new IdentityGenerator($sequenceName);
  546.                 $class->setIdGenerator($generator);
  547.                 break;
  548.             case ClassMetadata::GENERATOR_TYPE_SEQUENCE:
  549.                 // If there is no sequence definition yet, create a default definition
  550.                 $definition $class->sequenceGeneratorDefinition;
  551.                 if (! $definition) {
  552.                     $fieldName    $class->getSingleIdentifierFieldName();
  553.                     $sequenceName $class->getSequenceName($this->getTargetPlatform());
  554.                     $quoted       = isset($class->fieldMappings[$fieldName]['quoted']) || isset($class->table['quoted']);
  555.                     $definition = [
  556.                         'sequenceName'      => $this->getTargetPlatform()->fixSchemaElementName($sequenceName),
  557.                         'allocationSize'    => 1,
  558.                         'initialValue'      => 1,
  559.                     ];
  560.                     if ($quoted) {
  561.                         $definition['quoted'] = true;
  562.                     }
  563.                     $class->setSequenceGeneratorDefinition($definition);
  564.                 }
  565.                 $sequenceGenerator = new SequenceGenerator(
  566.                     $this->em->getConfiguration()->getQuoteStrategy()->getSequenceName($definition$class$this->getTargetPlatform()),
  567.                     $definition['allocationSize']
  568.                 );
  569.                 $class->setIdGenerator($sequenceGenerator);
  570.                 break;
  571.             case ClassMetadata::GENERATOR_TYPE_NONE:
  572.                 $class->setIdGenerator(new AssignedGenerator());
  573.                 break;
  574.             case ClassMetadata::GENERATOR_TYPE_UUID:
  575.                 $class->setIdGenerator(new UuidGenerator());
  576.                 break;
  577.             case ClassMetadata::GENERATOR_TYPE_TABLE:
  578.                 throw new ORMException('TableGenerator not yet implemented.');
  579.                 break;
  580.             case ClassMetadata::GENERATOR_TYPE_CUSTOM:
  581.                 $definition $class->customGeneratorDefinition;
  582.                 if ($definition === null) {
  583.                     throw new ORMException("Can't instantiate custom generator : no custom generator definition");
  584.                 }
  585.                 if (! class_exists($definition['class'])) {
  586.                     throw new ORMException("Can't instantiate custom generator : " .
  587.                         $definition['class']);
  588.                 }
  589.                 $class->setIdGenerator(new $definition['class']());
  590.                 break;
  591.             default:
  592.                 throw new ORMException('Unknown generator type: ' $class->generatorType);
  593.         }
  594.     }
  595.     /**
  596.      * Inherits the ID generator mapping from a parent class.
  597.      */
  598.     private function inheritIdGeneratorMapping(ClassMetadataInfo $classClassMetadataInfo $parent)
  599.     {
  600.         if ($parent->isIdGeneratorSequence()) {
  601.             $class->setSequenceGeneratorDefinition($parent->sequenceGeneratorDefinition);
  602.         } elseif ($parent->isIdGeneratorTable()) {
  603.             $class->tableGeneratorDefinition $parent->tableGeneratorDefinition;
  604.         }
  605.         if ($parent->generatorType) {
  606.             $class->setIdGeneratorType($parent->generatorType);
  607.         }
  608.         if ($parent->idGenerator) {
  609.             $class->setIdGenerator($parent->idGenerator);
  610.         }
  611.     }
  612.     /**
  613.      * {@inheritDoc}
  614.      */
  615.     protected function wakeupReflection(ClassMetadataInterface $classReflectionService $reflService)
  616.     {
  617.         /** @var ClassMetadata $class */
  618.         $class->wakeupReflection($reflService);
  619.     }
  620.     /**
  621.      * {@inheritDoc}
  622.      */
  623.     protected function initializeReflection(ClassMetadataInterface $classReflectionService $reflService)
  624.     {
  625.         /** @var ClassMetadata $class */
  626.         $class->initializeReflection($reflService);
  627.     }
  628.     /**
  629.      * {@inheritDoc}
  630.      */
  631.     protected function getFqcnFromAlias($namespaceAlias$simpleClassName)
  632.     {
  633.         return $this->em->getConfiguration()->getEntityNamespace($namespaceAlias) . '\\' $simpleClassName;
  634.     }
  635.     /**
  636.      * {@inheritDoc}
  637.      */
  638.     protected function getDriver()
  639.     {
  640.         return $this->driver;
  641.     }
  642.     /**
  643.      * {@inheritDoc}
  644.      */
  645.     protected function isEntity(ClassMetadataInterface $class)
  646.     {
  647.         return isset($class->isMappedSuperclass) && $class->isMappedSuperclass === false;
  648.     }
  649.     /**
  650.      * @return Platforms\AbstractPlatform
  651.      */
  652.     private function getTargetPlatform()
  653.     {
  654.         if (! $this->targetPlatform) {
  655.             $this->targetPlatform $this->em->getConnection()->getDatabasePlatform();
  656.         }
  657.         return $this->targetPlatform;
  658.     }
  659. }