class MappingDriverChain

The DriverChain allows you to add multiple other mapping drivers for certain namespaces

@since 2.2 @author Benjamin Eberlei <kontakt@beberlei.de> @author Guilherme Blanco <guilhermeblanco@hotmail.com> @author Jonathan H. Wage <jonwage@gmail.com> @author Roman Borschel <roman@code-factory.org>

Hierarchy

Expanded class hierarchy of MappingDriverChain

1 file declares its use of MappingDriverChain
ChainDriverTest.php in drupal/core/vendor/doctrine/common/tests/Doctrine/Tests/Common/Persistence/Mapping/ChainDriverTest.php

File

drupal/core/vendor/doctrine/common/lib/Doctrine/Common/Persistence/Mapping/Driver/MappingDriverChain.php, line 36

Namespace

Doctrine\Common\Persistence\Mapping\Driver
View source
class MappingDriverChain implements MappingDriver {

  /**
   * The default driver
   *
   * @var MappingDriver
   */
  private $defaultDriver;

  /**
   * @var array
   */
  private $drivers = array();

  /**
   * Get the default driver.
   *
   * @return MappingDriver|null
   */
  public function getDefaultDriver() {
    return $this->defaultDriver;
  }

  /**
   * Set the default driver.
   *
   * @param MappingDriver $driver
   */
  public function setDefaultDriver(MappingDriver $driver) {
    $this->defaultDriver = $driver;
  }

  /**
   * Add a nested driver.
   *
   * @param MappingDriver $nestedDriver
   * @param string $namespace
   */
  public function addDriver(MappingDriver $nestedDriver, $namespace) {
    $this->drivers[$namespace] = $nestedDriver;
  }

  /**
   * Get the array of nested drivers.
   *
   * @return array $drivers
   */
  public function getDrivers() {
    return $this->drivers;
  }

  /**
   * Loads the metadata for the specified class into the provided container.
   *
   * @param string $className
   * @param ClassMetadata $metadata
   *
   * @throws MappingException
   */
  public function loadMetadataForClass($className, ClassMetadata $metadata) {

    /* @var $driver MappingDriver */
    foreach ($this->drivers as $namespace => $driver) {
      if (strpos($className, $namespace) === 0) {
        $driver
          ->loadMetadataForClass($className, $metadata);
        return;
      }
    }
    if (null !== $this->defaultDriver) {
      $this->defaultDriver
        ->loadMetadataForClass($className, $metadata);
      return;
    }
    throw MappingException::classNotFoundInNamespaces($className, array_keys($this->drivers));
  }

  /**
   * Gets the names of all mapped classes known to this driver.
   *
   * @return array The names of all mapped classes known to this driver.
   */
  public function getAllClassNames() {
    $classNames = array();
    $driverClasses = array();

    /* @var $driver MappingDriver */
    foreach ($this->drivers as $namespace => $driver) {
      $oid = spl_object_hash($driver);
      if (!isset($driverClasses[$oid])) {
        $driverClasses[$oid] = $driver
          ->getAllClassNames();
      }
      foreach ($driverClasses[$oid] as $className) {
        if (strpos($className, $namespace) === 0) {
          $classNames[$className] = true;
        }
      }
    }
    return array_keys($classNames);
  }

  /**
   * Whether the class with the specified name should have its metadata loaded.
   *
   * This is only the case for non-transient classes either mapped as an Entity or MappedSuperclass.
   *
   * @param string $className
   * @return boolean
   */
  public function isTransient($className) {

    /* @var $driver MappingDriver */
    foreach ($this->drivers as $namespace => $driver) {
      if (strpos($className, $namespace) === 0) {
        return $driver
          ->isTransient($className);
      }
    }
    if ($this->defaultDriver !== null) {
      return $this->defaultDriver
        ->isTransient($className);
    }
    return true;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
MappingDriverChain::$defaultDriver private property The default driver
MappingDriverChain::$drivers private property
MappingDriverChain::addDriver public function Add a nested driver.
MappingDriverChain::getAllClassNames public function Gets the names of all mapped classes known to this driver. Overrides MappingDriver::getAllClassNames
MappingDriverChain::getDefaultDriver public function Get the default driver.
MappingDriverChain::getDrivers public function Get the array of nested drivers.
MappingDriverChain::isTransient public function Whether the class with the specified name should have its metadata loaded. Overrides MappingDriver::isTransient
MappingDriverChain::loadMetadataForClass public function Loads the metadata for the specified class into the provided container. Overrides MappingDriver::loadMetadataForClass
MappingDriverChain::setDefaultDriver public function Set the default driver.