From fcd623e8ef0070c2da4319f777328bee996a89aa Mon Sep 17 00:00:00 2001 From: jwage Date: Thu, 25 Feb 2010 19:33:21 +0000 Subject: [PATCH] [2.0] Adding DriverChain mapping driver type to allow you to configure drivers to use for certain entity namespaces --- .../ORM/Mapping/Driver/DriverChain.php | 97 +++++++++++++++++++ 1 file changed, 97 insertions(+) create mode 100644 lib/Doctrine/ORM/Mapping/Driver/DriverChain.php diff --git a/lib/Doctrine/ORM/Mapping/Driver/DriverChain.php b/lib/Doctrine/ORM/Mapping/Driver/DriverChain.php new file mode 100644 index 000000000..b12a53421 --- /dev/null +++ b/lib/Doctrine/ORM/Mapping/Driver/DriverChain.php @@ -0,0 +1,97 @@ +. + */ + +namespace Doctrine\ORM\Mapping\Driver; + +use Doctrine\ORM\Mapping\Driver\Driver, + Doctrine\ORM\Mapping\ClassMetadataInfo; + +/** + * The DriverChain allows you to add multiple other mapping drivers for + * certain namespaces + * + * @license http://www.opensource.org/licenses/lgpl-license.php LGPL + * @link www.doctrine-project.org + * @since 2.0 + * @version $Revision$ + * @author Benjamin Eberlei + * @author Guilherme Blanco + * @author Jonathan H. Wage + * @author Roman Borschel + */ +class DriverChain implements Driver +{ + /** + * @var array + */ + private $_drivers = array(); + + public function addDriver(Driver $nestedDriver, $namespace) + { + $this->_drivers[$namespace] = $nestedDriver; + } + + /** + * Loads the metadata for the specified class into the provided container. + * + * @param string $className + * @param ClassMetadataInfo $metadata + */ + public function loadMetadataForClass($className, ClassMetadataInfo $metadata) + { + foreach ($this->_drivers AS $namespace => $driver) { + if (strpos($className, $namespace) === 0) { + $driver->loadMetadataForClass($className, $metadata); + } + } + } + + /** + * 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(); + foreach ($this->_drivers AS $driver) { + $classNames = array_merge($classNames, $driver->getAllClassNames()); + } + return $classNames; + } + + /** + * Whether the class with the specified name should have its metadata loaded. + * This is only the case if it is either mapped as an Entity or a + * MappedSuperclass. + * + * @param string $className + * @return boolean + */ + public function isTransient($className) + { + foreach ($this->_drivers AS $namespace => $driver) { + if (strpos($className, $namespace) === 0) { + return $driver->isTransient($className); + } + } + } +} \ No newline at end of file