Chain.php 1.5 KB

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