Chain.php 1.7 KB

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