From 03fb734de82b4c064cee4e75f1b509ebff760244 Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Tue, 17 Jan 2012 14:31:27 +0100 Subject: [PATCH] Removing API that should be moved to common --- .../ORM/Mapping/Driver/AbstractFileDriver.php | 34 +------------------ lib/Doctrine/ORM/Mapping/Driver/PHPDriver.php | 22 ++++++------ .../Mapping/Driver/SimplifiedXmlDriver.php | 10 +++--- .../Mapping/Driver/SimplifiedYamlDriver.php | 12 +++---- .../ORM/Mapping/YamlMappingDriverTest.php | 2 +- 5 files changed, 24 insertions(+), 56 deletions(-) diff --git a/lib/Doctrine/ORM/Mapping/Driver/AbstractFileDriver.php b/lib/Doctrine/ORM/Mapping/Driver/AbstractFileDriver.php index 0d8720708..31e7e068e 100644 --- a/lib/Doctrine/ORM/Mapping/Driver/AbstractFileDriver.php +++ b/lib/Doctrine/ORM/Mapping/Driver/AbstractFileDriver.php @@ -21,6 +21,7 @@ namespace Doctrine\ORM\Mapping\Driver; use Doctrine\ORM\Mapping\MappingException; use Doctrine\Common\Persistence\Mapping\Driver\FileDriver; +use Doctrine\Common\Persistence\Mapping\Driver\FileLocator; /** * Base driver for file-based metadata drivers. @@ -40,26 +41,6 @@ use Doctrine\Common\Persistence\Mapping\Driver\FileDriver; */ abstract class AbstractFileDriver extends FileDriver implements Driver { - /** - * Append lookup paths to metadata driver. - * - * @param array $paths - */ - public function addPaths(array $paths) - { - $this->locator->addPaths($paths); - } - - /** - * Retrieve the defined metadata lookup paths. - * - * @return array - */ - public function getPaths() - { - return $this->locator->getPaths(); - } - /** * Get the element of schema meta data for the class from the mapping file. * This will lazily load the mapping file if it is not loaded yet @@ -76,17 +57,4 @@ abstract class AbstractFileDriver extends FileDriver implements Driver } return $result; } - - /** - * Finds the mapping file for the class with the given name by searching - * through the configured paths. - * - * @param $className - * @return string The (absolute) file name. - * @throws MappingException - */ - protected function findMappingFile($className) - { - return $this->locator->findMappingFile($className); - } } \ No newline at end of file diff --git a/lib/Doctrine/ORM/Mapping/Driver/PHPDriver.php b/lib/Doctrine/ORM/Mapping/Driver/PHPDriver.php index 4a4dbd047..1071083cf 100644 --- a/lib/Doctrine/ORM/Mapping/Driver/PHPDriver.php +++ b/lib/Doctrine/ORM/Mapping/Driver/PHPDriver.php @@ -19,12 +19,7 @@ namespace Doctrine\ORM\Mapping\Driver; -use Doctrine\Common\Cache\ArrayCache, - Doctrine\Common\Annotations\AnnotationReader, - Doctrine\DBAL\Schema\AbstractSchemaManager, - Doctrine\Common\Persistence\Mapping\ClassMetadata, - Doctrine\ORM\Mapping\MappingException, - Doctrine\Common\Util\Inflector, +use Doctrine\Common\Persistence\Mapping\ClassMetadata, Doctrine\ORM\Mapping\Driver\AbstractFileDriver; /** @@ -46,11 +41,11 @@ class PHPDriver extends AbstractFileDriver const DEFAULT_FILE_EXTENSION = '.php'; /** - * {@inheritdoc} + * + * @var ClassMetadata */ - protected $_fileExtension = '.php'; protected $_metadata; - + /** * {@inheritdoc} */ @@ -65,7 +60,7 @@ class PHPDriver extends AbstractFileDriver public function loadMetadataForClass($className, ClassMetadata $metadata) { $this->_metadata = $metadata; - $this->loadMappingFile($this->findMappingFile($className)); + $this->getElement($className); } /** @@ -73,7 +68,12 @@ class PHPDriver extends AbstractFileDriver */ protected function loadMappingFile($file) { + $result = array(); $metadata = $this->_metadata; include $file; + // @todo cannot assume that the only loaded metadata is $metadata. Some + // decision about the preferred approach should be taken + $result[$metadata->getName()] = $metadata; + return $result; } -} +} \ No newline at end of file diff --git a/lib/Doctrine/ORM/Mapping/Driver/SimplifiedXmlDriver.php b/lib/Doctrine/ORM/Mapping/Driver/SimplifiedXmlDriver.php index 325495d3a..1f47ca609 100644 --- a/lib/Doctrine/ORM/Mapping/Driver/SimplifiedXmlDriver.php +++ b/lib/Doctrine/ORM/Mapping/Driver/SimplifiedXmlDriver.php @@ -59,7 +59,7 @@ class SimplifiedXmlDriver extends XmlDriver public function addNamespacePrefixes($prefixes) { $this->_prefixes = array_merge($this->_prefixes, $prefixes); - $this->addPaths(array_flip($prefixes)); + $this->locator->addPaths(array_flip($prefixes)); } public function getNamespacePrefixes() @@ -95,8 +95,8 @@ class SimplifiedXmlDriver extends XmlDriver $classes = array(); - if ($this->_paths) { - foreach ((array) $this->_paths as $path) { + if ($this->locator->getPaths()) { + foreach ($this->locator->getPaths() as $path) { if (!is_dir($path)) { throw MappingException::fileMappingDriversRequireConfiguredDirectoryPath($path); } @@ -143,7 +143,7 @@ class SimplifiedXmlDriver extends XmlDriver { $this->_classCache = array(); if (null !== $this->_globalBasename) { - foreach ($this->_paths as $path) { + foreach ($this->locator->getPaths() as $path) { if (is_file($file = $path.'/'.$this->_globalBasename.$this->_fileExtension)) { $this->_classCache = array_merge($this->_classCache, $this->loadMappingFile($file)); } @@ -154,7 +154,7 @@ class SimplifiedXmlDriver extends XmlDriver protected function findMappingFile($className) { $defaultFileName = str_replace('\\', '.', $className).$this->_fileExtension; - foreach ($this->_paths as $path) { + foreach ($this->locator->getPaths() as $path) { if (!isset($this->_prefixes[$path])) { if (is_file($path.DIRECTORY_SEPARATOR.$defaultFileName)) { return $path.DIRECTORY_SEPARATOR.$defaultFileName; diff --git a/lib/Doctrine/ORM/Mapping/Driver/SimplifiedYamlDriver.php b/lib/Doctrine/ORM/Mapping/Driver/SimplifiedYamlDriver.php index a6e55ae84..cdd826413 100644 --- a/lib/Doctrine/ORM/Mapping/Driver/SimplifiedYamlDriver.php +++ b/lib/Doctrine/ORM/Mapping/Driver/SimplifiedYamlDriver.php @@ -30,7 +30,7 @@ use Doctrine\ORM\Mapping\MappingException; */ class SimplifiedYamlDriver extends YamlDriver { - const DEFAULT_FILE_EXTENSION = '.orm.xml'; + const DEFAULT_FILE_EXTENSION = '.orm.yml'; protected $_prefixes = array(); protected $_globalBasename; @@ -59,7 +59,7 @@ class SimplifiedYamlDriver extends YamlDriver public function addNamespacePrefixes($prefixes) { $this->_prefixes = array_merge($this->_prefixes, $prefixes); - $this->addPaths(array_flip($prefixes)); + $this->locator->addPaths(array_flip($prefixes)); } public function addNamespacePrefix($prefix, $path) @@ -100,8 +100,8 @@ class SimplifiedYamlDriver extends YamlDriver $classes = array(); - if ($this->_paths) { - foreach ((array) $this->_paths as $path) { + if ($this->locator->getPaths()) { + foreach ($this->locator->getPaths() as $path) { if (!is_dir($path)) { throw MappingException::fileMappingDriversRequireConfiguredDirectoryPath($path); } @@ -148,7 +148,7 @@ class SimplifiedYamlDriver extends YamlDriver { $this->_classCache = array(); if (null !== $this->_globalBasename) { - foreach ($this->_paths as $path) { + foreach ($this->locator->getPaths() as $path) { if (is_file($file = $path.'/'.$this->_globalBasename.$this->_fileExtension)) { $this->_classCache = array_merge($this->_classCache, $this->loadMappingFile($file)); } @@ -159,7 +159,7 @@ class SimplifiedYamlDriver extends YamlDriver protected function findMappingFile($className) { $defaultFileName = str_replace('\\', '.', $className).$this->_fileExtension; - foreach ($this->_paths as $path) { + foreach ($this->locator->getPaths() as $path) { if (!isset($this->_prefixes[$path])) { if (is_file($path.DIRECTORY_SEPARATOR.$defaultFileName)) { return $path.DIRECTORY_SEPARATOR.$defaultFileName; diff --git a/tests/Doctrine/Tests/ORM/Mapping/YamlMappingDriverTest.php b/tests/Doctrine/Tests/ORM/Mapping/YamlMappingDriverTest.php index 2757259a4..08570a22c 100644 --- a/tests/Doctrine/Tests/ORM/Mapping/YamlMappingDriverTest.php +++ b/tests/Doctrine/Tests/ORM/Mapping/YamlMappingDriverTest.php @@ -27,7 +27,7 @@ class YamlMappingDriverTest extends AbstractMappingDriverTest public function testJoinTablesWithMappedSuperclassForYamlDriver() { $yamlDriver = $this->_loadDriver(); - $yamlDriver->addPaths(array(__DIR__ . DIRECTORY_SEPARATOR . 'yaml')); + $yamlDriver->getLocator()->addPaths(array(__DIR__ . DIRECTORY_SEPARATOR . 'yaml')); $em = $this->_getTestEntityManager(); $em->getConfiguration()->setMetadataDriverImpl($yamlDriver);