vendor/gedmo/doctrine-extensions/src/Mapping/Driver/Chain.php line 78

Open in your IDE?
  1. <?php
  2. /*
  3.  * This file is part of the Doctrine Behavioral Extensions package.
  4.  * (c) Gediminas Morkevicius <gediminas.morkevicius@gmail.com> http://www.gediminasm.org
  5.  * For the full copyright and license information, please view the LICENSE
  6.  * file that was distributed with this source code.
  7.  */
  8. namespace Gedmo\Mapping\Driver;
  9. use Gedmo\Mapping\Driver;
  10. /**
  11.  * The chain mapping driver enables chained
  12.  * extension mapping driver support
  13.  *
  14.  * @author Gediminas Morkevicius <gediminas.morkevicius@gmail.com>
  15.  *
  16.  * @final since gedmo/doctrine-extensions 3.11
  17.  */
  18. class Chain implements Driver
  19. {
  20.     /**
  21.      * The default driver
  22.      */
  23.     private ?Driver $defaultDriver null;
  24.     /**
  25.      * List of drivers nested
  26.      *
  27.      * @var array<string, Driver>
  28.      */
  29.     private array $_drivers = [];
  30.     /**
  31.      * Add a nested driver.
  32.      *
  33.      * @param string $namespace
  34.      *
  35.      * @return void
  36.      */
  37.     public function addDriver(Driver $nestedDriver$namespace)
  38.     {
  39.         $this->_drivers[$namespace] = $nestedDriver;
  40.     }
  41.     /**
  42.      * Get the array of nested drivers.
  43.      *
  44.      * @return array<string, Driver>
  45.      */
  46.     public function getDrivers()
  47.     {
  48.         return $this->_drivers;
  49.     }
  50.     /**
  51.      * Get the default driver.
  52.      *
  53.      * @return Driver|null
  54.      */
  55.     public function getDefaultDriver()
  56.     {
  57.         return $this->defaultDriver;
  58.     }
  59.     /**
  60.      * Set the default driver.
  61.      *
  62.      * @return void
  63.      */
  64.     public function setDefaultDriver(Driver $driver)
  65.     {
  66.         $this->defaultDriver $driver;
  67.     }
  68.     public function readExtendedMetadata($meta, array &$config)
  69.     {
  70.         foreach ($this->_drivers as $namespace => $driver) {
  71.             if (=== strpos($meta->getName(), $namespace)) {
  72.                 $extendedMetadata $driver->readExtendedMetadata($meta$config);
  73.                 if (\is_array($extendedMetadata)) {
  74.                     $config $extendedMetadata;
  75.                 }
  76.                 // @todo: In the next major release remove the assignment to `$extendedMetadata`, the previous conditional
  77.                 // block, uncomment the following line and replace the following return statement.
  78.                 // return $driver->readExtendedMetadata($meta, $config);
  79.                 return $config;
  80.             }
  81.         }
  82.         if (null !== $this->defaultDriver) {
  83.             $extendedMetadata $this->defaultDriver->readExtendedMetadata($meta$config);
  84.             if (\is_array($extendedMetadata)) {
  85.                 $config $extendedMetadata;
  86.             }
  87.             // @todo: In the next major release remove the assignment to `$extendedMetadata`, the previous conditional
  88.             // block, uncomment the following line and replace the following return statement.
  89.             // return $this->defaultDriver->readExtendedMetadata($meta, $config);
  90.             return $config;
  91.         }
  92.         // commenting it for customized mapping support, debugging of such cases might get harder
  93.         // throw new \Gedmo\Exception\UnexpectedValueException('Class ' . $meta->getName() . ' is not a valid entity or mapped super class.');
  94.     }
  95.     /**
  96.      * Passes in the mapping read by original driver
  97.      */
  98.     public function setOriginalDriver($driver)
  99.     {
  100.         // not needed here
  101.     }
  102. }