Chain.php 1.7KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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 readExtendedMetadata($meta, array &$config)
  44. {
  45. foreach ($this->_drivers as $namespace => $driver) {
  46. if (strpos($meta->name, $namespace) === 0) {
  47. $driver->readExtendedMetadata($meta, $config);
  48. return;
  49. }
  50. }
  51. // commenting it for customized mapping support, debugging of such cases might get harder
  52. //throw new \Gedmo\Exception\UnexpectedValueException('Class ' . $meta->name . ' is not a valid entity or mapped super class.');
  53. }
  54. /**
  55. * Passes in the mapping read by original driver
  56. *
  57. * @param $driver
  58. * @return void
  59. */
  60. public function setOriginalDriver($driver)
  61. {
  62. //not needed here
  63. }
  64. }