Chain.php 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  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. * @license MIT License (http://www.opensource.org/licenses/mit-license.php)
  10. */
  11. class Chain implements Driver
  12. {
  13. /**
  14. * The default driver
  15. *
  16. * @var Driver|null
  17. */
  18. private $defaultDriver;
  19. /**
  20. * List of drivers nested
  21. * @var Driver[]
  22. */
  23. private $_drivers = array();
  24. /**
  25. * Add a nested driver.
  26. *
  27. * @param Driver $nestedDriver
  28. * @param string $namespace
  29. */
  30. public function addDriver(Driver $nestedDriver, $namespace)
  31. {
  32. $this->_drivers[$namespace] = $nestedDriver;
  33. }
  34. /**
  35. * Get the array of nested drivers.
  36. *
  37. * @return Driver[] $drivers
  38. */
  39. public function getDrivers()
  40. {
  41. return $this->_drivers;
  42. }
  43. /**
  44. * Get the default driver.
  45. *
  46. * @return Driver|null
  47. */
  48. public function getDefaultDriver()
  49. {
  50. return $this->defaultDriver;
  51. }
  52. /**
  53. * Set the default driver.
  54. *
  55. * @param Driver $driver
  56. */
  57. public function setDefaultDriver(Driver $driver)
  58. {
  59. $this->defaultDriver = $driver;
  60. }
  61. /**
  62. * {@inheritDoc}
  63. */
  64. public function readExtendedMetadata($meta, array &$config)
  65. {
  66. foreach ($this->_drivers as $namespace => $driver) {
  67. if (strpos($meta->name, $namespace) === 0) {
  68. $driver->readExtendedMetadata($meta, $config);
  69. return;
  70. }
  71. }
  72. if (null !== $this->defaultDriver) {
  73. $this->defaultDriver->readExtendedMetadata($meta, $config);
  74. return;
  75. }
  76. // commenting it for customized mapping support, debugging of such cases might get harder
  77. //throw new \Gedmo\Exception\UnexpectedValueException('Class ' . $meta->name . ' is not a valid entity or mapped super class.');
  78. }
  79. /**
  80. * Passes in the mapping read by original driver
  81. *
  82. * @param $driver
  83. * @return void
  84. */
  85. public function setOriginalDriver($driver)
  86. {
  87. //not needed here
  88. }
  89. }