Chain.php 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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. /**
  59. * Passes in the mapping read by original driver
  60. *
  61. * @param $driver
  62. * @return void
  63. */
  64. public function setOriginalDriver($driver)
  65. {
  66. //not needed here
  67. }
  68. }