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>
Expanded class hierarchy of MappingDriverChain
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;
}
}
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
MappingDriverChain:: |
private | property | The default driver | |
MappingDriverChain:: |
private | property | ||
MappingDriverChain:: |
public | function | Add a nested driver. | |
MappingDriverChain:: |
public | function |
Gets the names of all mapped classes known to this driver. Overrides MappingDriver:: |
|
MappingDriverChain:: |
public | function | Get the default driver. | |
MappingDriverChain:: |
public | function | Get the array of nested drivers. | |
MappingDriverChain:: |
public | function |
Whether the class with the specified name should have its metadata loaded. Overrides MappingDriver:: |
|
MappingDriverChain:: |
public | function |
Loads the metadata for the specified class into the provided container. Overrides MappingDriver:: |
|
MappingDriverChain:: |
public | function | Set the default driver. |