ClassMetadataFactory.php 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. <?php
  2. namespace Doctrine\Bundle\DoctrineBundle\Mapping;
  3. use Doctrine\ORM\Id\AbstractIdGenerator;
  4. use Doctrine\ORM\Mapping\ClassMetadata;
  5. use Doctrine\ORM\Mapping\ClassMetadataFactory as BaseClassMetadataFactory;
  6. use Doctrine\ORM\Mapping\ClassMetadataInfo;
  7. use function assert;
  8. class ClassMetadataFactory extends BaseClassMetadataFactory
  9. {
  10. /**
  11. * {@inheritDoc}
  12. */
  13. protected function doLoadMetadata($class, $parent, $rootEntityFound, array $nonSuperclassParents): void
  14. {
  15. parent::doLoadMetadata($class, $parent, $rootEntityFound, $nonSuperclassParents);
  16. if (! $class instanceof ClassMetadataInfo) {
  17. return;
  18. }
  19. $customGeneratorDefinition = $class->customGeneratorDefinition;
  20. if (! isset($customGeneratorDefinition['instance'])) {
  21. return;
  22. }
  23. assert($customGeneratorDefinition['instance'] instanceof AbstractIdGenerator);
  24. $class->setIdGeneratorType(ClassMetadata::GENERATOR_TYPE_CUSTOM);
  25. $class->setIdGenerator($customGeneratorDefinition['instance']);
  26. unset($customGeneratorDefinition['instance']);
  27. $class->setCustomGeneratorDefinition($customGeneratorDefinition);
  28. }
  29. }