Chain.php 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. <?php
  2. namespace Gedmo\Mapping\Driver;
  3. use Gedmo\Mapping\Driver,
  4. Doctrine\Common\Persistence\Mapping\ClassMetadata;
  5. /**
  6. * The chain mapping driver enables chained
  7. * extension mapping driver support
  8. *
  9. * @author Gediminas Morkevicius <gediminas.morkevicius@gmail.com>
  10. * @package Gedmo.Mapping.Driver
  11. * @subpackage Chain
  12. * @link http://www.gediminasm.org
  13. * @license MIT License (http://www.opensource.org/licenses/mit-license.php)
  14. */
  15. class Chain implements Driver
  16. {
  17. /**
  18. * List of drivers nested
  19. * @var array
  20. */
  21. private $_drivers = array();
  22. /**
  23. * Add a nested driver.
  24. *
  25. * @param Driver $nestedDriver
  26. * @param string $namespace
  27. */
  28. public function addDriver(Driver $nestedDriver, $namespace)
  29. {
  30. $this->_drivers[$namespace] = $nestedDriver;
  31. }
  32. /**
  33. * Get the array of nested drivers.
  34. *
  35. * @return array $drivers
  36. */
  37. public function getDrivers()
  38. {
  39. return $this->_drivers;
  40. }
  41. /**
  42. * {@inheritDoc}
  43. */
  44. public function validateFullMetadata(ClassMetadata $meta, array $config) {}
  45. /**
  46. * {@inheritDoc}
  47. */
  48. public function readExtendedMetadata(ClassMetadata $meta, array &$config)
  49. {
  50. foreach ($this->_drivers as $namespace => $driver) {
  51. if (strpos($meta->name, $namespace) === 0) {
  52. $driver->readExtendedMetadata($meta, $config);
  53. return;
  54. }
  55. }
  56. throw new \Gedmo\Exception\UnexpectedValueException('Class ' . $meta->name . ' is not a valid entity or mapped super class.');
  57. }
  58. }