Chain.php 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. <?php
  2. namespace Gedmo\Mapping\Driver;
  3. use Gedmo\Mapping\Driver,
  4. Doctrine\ORM\Mapping\ClassMetadataInfo;
  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(ClassMetadataInfo $meta, array $config)
  45. {
  46. }
  47. /**
  48. * {@inheritDoc}
  49. */
  50. public function readExtendedMetadata(ClassMetadataInfo $meta, array &$config)
  51. {
  52. foreach ($this->_drivers as $namespace => $driver) {
  53. if (strpos($meta->name, $namespace) === 0) {
  54. $driver->readExtendedMetadata($meta, $config);
  55. return;
  56. }
  57. }
  58. throw \Gedmo\Mapping\DriverException::invalidEntity($meta->name);
  59. }
  60. }