PHPDriver.php 905 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. <?php
  2. namespace Doctrine\Persistence\Mapping\Driver;
  3. use Doctrine\Persistence\Mapping\ClassMetadata;
  4. /**
  5. * The PHPDriver includes php files which just populate ClassMetadataInfo
  6. * instances with plain PHP code.
  7. */
  8. class PHPDriver extends FileDriver
  9. {
  10. /** @var ClassMetadata */
  11. protected $metadata;
  12. /**
  13. * {@inheritDoc}
  14. */
  15. public function __construct($locator)
  16. {
  17. parent::__construct($locator, '.php');
  18. }
  19. /**
  20. * {@inheritDoc}
  21. */
  22. public function loadMetadataForClass($className, ClassMetadata $metadata)
  23. {
  24. $this->metadata = $metadata;
  25. $this->loadMappingFile($this->locator->findMappingFile($className));
  26. }
  27. /**
  28. * {@inheritDoc}
  29. */
  30. protected function loadMappingFile($file)
  31. {
  32. $metadata = $this->metadata;
  33. include $file;
  34. return [$metadata->getName() => $metadata];
  35. }
  36. }