From e6a2bae5d7be5edbb0c5f50b004d40e62a042081 Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Thu, 12 Jan 2012 02:09:26 +0100 Subject: [PATCH 01/22] Updating mapping driver interface to comply with Doctrine\Common\Persistence\Mapping\Driver\MappingDriver --- .../ORM/Mapping/Driver/AnnotationDriver.php | 6 ++-- .../ORM/Mapping/Driver/DatabaseDriver.php | 3 +- lib/Doctrine/ORM/Mapping/Driver/Driver.php | 30 ++----------------- .../ORM/Mapping/Driver/DriverChain.php | 6 ++-- lib/Doctrine/ORM/Mapping/Driver/PHPDriver.php | 6 ++-- .../ORM/Mapping/Driver/StaticPHPDriver.php | 4 +-- lib/Doctrine/ORM/Mapping/Driver/XmlDriver.php | 4 +-- .../ORM/Mapping/Driver/YamlDriver.php | 4 +-- .../Tests/Mocks/MetadataDriverMock.php | 2 +- 9 files changed, 21 insertions(+), 44 deletions(-) diff --git a/lib/Doctrine/ORM/Mapping/Driver/AnnotationDriver.php b/lib/Doctrine/ORM/Mapping/Driver/AnnotationDriver.php index 0dbc4199c..203dd42e0 100644 --- a/lib/Doctrine/ORM/Mapping/Driver/AnnotationDriver.php +++ b/lib/Doctrine/ORM/Mapping/Driver/AnnotationDriver.php @@ -22,10 +22,10 @@ namespace Doctrine\ORM\Mapping\Driver; use Doctrine\Common\Cache\ArrayCache, Doctrine\Common\Annotations\AnnotationReader, Doctrine\Common\Annotations\AnnotationRegistry, - Doctrine\ORM\Mapping\ClassMetadataInfo, Doctrine\ORM\Mapping\MappingException, Doctrine\ORM\Mapping\JoinColumn, - Doctrine\ORM\Mapping\Column; + Doctrine\ORM\Mapping\Column, + Doctrine\Common\Persistence\Mapping\ClassMetadata; /** * The AnnotationDriver reads the mapping metadata from docblock annotations. @@ -133,7 +133,7 @@ class AnnotationDriver implements Driver /** * {@inheritdoc} */ - public function loadMetadataForClass($className, ClassMetadataInfo $metadata) + public function loadMetadataForClass($className, ClassMetadata $metadata) { $class = $metadata->getReflectionClass(); if ( ! $class) { diff --git a/lib/Doctrine/ORM/Mapping/Driver/DatabaseDriver.php b/lib/Doctrine/ORM/Mapping/Driver/DatabaseDriver.php index 37e0dc93d..868835a35 100644 --- a/lib/Doctrine/ORM/Mapping/Driver/DatabaseDriver.php +++ b/lib/Doctrine/ORM/Mapping/Driver/DatabaseDriver.php @@ -23,6 +23,7 @@ use Doctrine\Common\Cache\ArrayCache, Doctrine\Common\Annotations\AnnotationReader, Doctrine\DBAL\Schema\AbstractSchemaManager, Doctrine\DBAL\Schema\SchemaException, + Doctrine\Common\Persistence\Mapping\ClassMetadata, Doctrine\ORM\Mapping\ClassMetadataInfo, Doctrine\ORM\Mapping\MappingException, Doctrine\Common\Util\Inflector; @@ -156,7 +157,7 @@ class DatabaseDriver implements Driver /** * {@inheritdoc} */ - public function loadMetadataForClass($className, ClassMetadataInfo $metadata) + public function loadMetadataForClass($className, ClassMetadata $metadata) { $this->reverseEngineerMappingFromDatabase(); diff --git a/lib/Doctrine/ORM/Mapping/Driver/Driver.php b/lib/Doctrine/ORM/Mapping/Driver/Driver.php index 409d357dc..2ec4866f7 100644 --- a/lib/Doctrine/ORM/Mapping/Driver/Driver.php +++ b/lib/Doctrine/ORM/Mapping/Driver/Driver.php @@ -19,7 +19,7 @@ namespace Doctrine\ORM\Mapping\Driver; -use Doctrine\ORM\Mapping\ClassMetadataInfo; +use Doctrine\Common\Persistence\Mapping\Driver\MappingDriver; /** * Contract for metadata drivers. @@ -28,30 +28,6 @@ use Doctrine\ORM\Mapping\ClassMetadataInfo; * @author Jonathan H. Wage * @todo Rename: MetadataDriver or MappingDriver */ -interface Driver +interface Driver extends MappingDriver { - /** - * Loads the metadata for the specified class into the provided container. - * - * @param string $className - * @param ClassMetadataInfo $metadata - */ - function loadMetadataForClass($className, ClassMetadataInfo $metadata); - - /** - * Gets the names of all mapped classes known to this driver. - * - * @return array The names of all mapped classes known to this driver. - */ - function getAllClassNames(); - - /** - * 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 - */ - function isTransient($className); -} +} \ No newline at end of file diff --git a/lib/Doctrine/ORM/Mapping/Driver/DriverChain.php b/lib/Doctrine/ORM/Mapping/Driver/DriverChain.php index 4c135a6c0..8536d7365 100644 --- a/lib/Doctrine/ORM/Mapping/Driver/DriverChain.php +++ b/lib/Doctrine/ORM/Mapping/Driver/DriverChain.php @@ -20,7 +20,7 @@ namespace Doctrine\ORM\Mapping\Driver; use Doctrine\ORM\Mapping\Driver\Driver, - Doctrine\ORM\Mapping\ClassMetadataInfo, + Doctrine\Common\Persistence\Mapping\ClassMetadata, Doctrine\ORM\Mapping\MappingException; /** @@ -93,9 +93,9 @@ class DriverChain implements Driver * Loads the metadata for the specified class into the provided container. * * @param string $className - * @param ClassMetadataInfo $metadata + * @param ClassMetadata $metadata */ - public function loadMetadataForClass($className, ClassMetadataInfo $metadata) + public function loadMetadataForClass($className, ClassMetadata $metadata) { foreach ($this->drivers as $namespace => $driver) { if (strpos($className, $namespace) === 0) { diff --git a/lib/Doctrine/ORM/Mapping/Driver/PHPDriver.php b/lib/Doctrine/ORM/Mapping/Driver/PHPDriver.php index b6f28c48c..1e3f7f686 100644 --- a/lib/Doctrine/ORM/Mapping/Driver/PHPDriver.php +++ b/lib/Doctrine/ORM/Mapping/Driver/PHPDriver.php @@ -22,13 +22,13 @@ namespace Doctrine\ORM\Mapping\Driver; use Doctrine\Common\Cache\ArrayCache, Doctrine\Common\Annotations\AnnotationReader, Doctrine\DBAL\Schema\AbstractSchemaManager, - Doctrine\ORM\Mapping\ClassMetadataInfo, + Doctrine\Common\Persistence\Mapping\ClassMetadata, Doctrine\ORM\Mapping\MappingException, Doctrine\Common\Util\Inflector, Doctrine\ORM\Mapping\Driver\AbstractFileDriver; /** - * The PHPDriver includes php files which just populate ClassMetadataInfo + * The PHPDriver includes php files which just populate ClassMetadata * instances with plain php code * * @license http://www.opensource.org/licenses/lgpl-license.php LGPL @@ -52,7 +52,7 @@ class PHPDriver extends AbstractFileDriver /** * {@inheritdoc} */ - public function loadMetadataForClass($className, ClassMetadataInfo $metadata) + public function loadMetadataForClass($className, ClassMetadata $metadata) { $this->_metadata = $metadata; $this->_loadMappingFile($this->_findMappingFile($className)); diff --git a/lib/Doctrine/ORM/Mapping/Driver/StaticPHPDriver.php b/lib/Doctrine/ORM/Mapping/Driver/StaticPHPDriver.php index eea4d094b..4430d4c7f 100644 --- a/lib/Doctrine/ORM/Mapping/Driver/StaticPHPDriver.php +++ b/lib/Doctrine/ORM/Mapping/Driver/StaticPHPDriver.php @@ -19,7 +19,7 @@ namespace Doctrine\ORM\Mapping\Driver; -use Doctrine\ORM\Mapping\ClassMetadataInfo, +use Doctrine\Common\Persistence\Mapping\ClassMetadata, Doctrine\ORM\Mapping\MappingException; /** @@ -70,7 +70,7 @@ class StaticPHPDriver implements Driver /** * {@inheritdoc} */ - public function loadMetadataForClass($className, ClassMetadataInfo $metadata) + public function loadMetadataForClass($className, ClassMetadata $metadata) { call_user_func_array(array($className, 'loadMetadata'), array($metadata)); } diff --git a/lib/Doctrine/ORM/Mapping/Driver/XmlDriver.php b/lib/Doctrine/ORM/Mapping/Driver/XmlDriver.php index 6bea5523b..46b46dc5f 100644 --- a/lib/Doctrine/ORM/Mapping/Driver/XmlDriver.php +++ b/lib/Doctrine/ORM/Mapping/Driver/XmlDriver.php @@ -20,7 +20,7 @@ namespace Doctrine\ORM\Mapping\Driver; use SimpleXMLElement, - Doctrine\ORM\Mapping\ClassMetadataInfo, + Doctrine\Common\Persistence\Mapping\ClassMetadata, Doctrine\ORM\Mapping\MappingException; /** @@ -44,7 +44,7 @@ class XmlDriver extends AbstractFileDriver /** * {@inheritdoc} */ - public function loadMetadataForClass($className, ClassMetadataInfo $metadata) + public function loadMetadataForClass($className, ClassMetadata $metadata) { $xmlRoot = $this->getElement($className); diff --git a/lib/Doctrine/ORM/Mapping/Driver/YamlDriver.php b/lib/Doctrine/ORM/Mapping/Driver/YamlDriver.php index 1ee8dd147..fb31c5416 100644 --- a/lib/Doctrine/ORM/Mapping/Driver/YamlDriver.php +++ b/lib/Doctrine/ORM/Mapping/Driver/YamlDriver.php @@ -19,7 +19,7 @@ namespace Doctrine\ORM\Mapping\Driver; -use Doctrine\ORM\Mapping\ClassMetadataInfo, +use Doctrine\Common\Persistence\Mapping\ClassMetadata, Doctrine\ORM\Mapping\MappingException; /** @@ -41,7 +41,7 @@ class YamlDriver extends AbstractFileDriver /** * {@inheritdoc} */ - public function loadMetadataForClass($className, ClassMetadataInfo $metadata) + public function loadMetadataForClass($className, ClassMetadata $metadata) { $element = $this->getElement($className); diff --git a/tests/Doctrine/Tests/Mocks/MetadataDriverMock.php b/tests/Doctrine/Tests/Mocks/MetadataDriverMock.php index fb533f465..87f560e64 100644 --- a/tests/Doctrine/Tests/Mocks/MetadataDriverMock.php +++ b/tests/Doctrine/Tests/Mocks/MetadataDriverMock.php @@ -4,7 +4,7 @@ namespace Doctrine\Tests\Mocks; class MetadataDriverMock implements \Doctrine\ORM\Mapping\Driver\Driver { - public function loadMetadataForClass($className, \Doctrine\ORM\Mapping\ClassMetadataInfo $metadata) + public function loadMetadataForClass($className, \Doctrine\Common\Persistence\Mapping\ClassMetadata $metadata) { return; } From 34bb0c4943fbcecf88c0b57a7ced0e39c069981e Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Tue, 17 Jan 2012 12:32:10 +0100 Subject: [PATCH 02/22] Reducing code duplication SimplifiedXmlDriver and SimplifiedYamlDriver are still not valid after this commit --- .../ORM/Mapping/Driver/AbstractFileDriver.php | 139 +----------------- lib/Doctrine/ORM/Mapping/Driver/PHPDriver.php | 18 ++- .../Mapping/Driver/SimplifiedXmlDriver.php | 14 +- .../Mapping/Driver/SimplifiedYamlDriver.php | 14 +- lib/Doctrine/ORM/Mapping/Driver/XmlDriver.php | 9 +- .../ORM/Mapping/Driver/YamlDriver.php | 14 +- .../Mapping/Symfony/AbstractDriverTest.php | 4 +- 7 files changed, 60 insertions(+), 152 deletions(-) diff --git a/lib/Doctrine/ORM/Mapping/Driver/AbstractFileDriver.php b/lib/Doctrine/ORM/Mapping/Driver/AbstractFileDriver.php index 86ef9ce2a..9a4ee054c 100644 --- a/lib/Doctrine/ORM/Mapping/Driver/AbstractFileDriver.php +++ b/lib/Doctrine/ORM/Mapping/Driver/AbstractFileDriver.php @@ -20,6 +20,7 @@ namespace Doctrine\ORM\Mapping\Driver; use Doctrine\ORM\Mapping\MappingException; +use Doctrine\Common\Persistence\Mapping\Driver\FileDriver; /** * Base driver for file-based metadata drivers. @@ -37,33 +38,8 @@ use Doctrine\ORM\Mapping\MappingException; * @author Jonathan H. Wage * @author Roman Borschel */ -abstract class AbstractFileDriver implements Driver +abstract class AbstractFileDriver extends FileDriver implements Driver { - /** - * The paths where to look for mapping files. - * - * @var array - */ - protected $_paths = array(); - - /** - * The file extension of mapping documents. - * - * @var string - */ - protected $_fileExtension; - - /** - * Initializes a new FileDriver that looks in the given path(s) for mapping - * documents and operates in the specified operating mode. - * - * @param string|array $paths One or multiple paths where mapping documents can be found. - */ - public function __construct($paths) - { - $this->addPaths((array) $paths); - } - /** * Append lookup paths to metadata driver. * @@ -71,7 +47,7 @@ abstract class AbstractFileDriver implements Driver */ public function addPaths(array $paths) { - $this->_paths = array_unique(array_merge($this->_paths, $paths)); + $this->locator->addPaths($paths); } /** @@ -81,100 +57,7 @@ abstract class AbstractFileDriver implements Driver */ public function getPaths() { - return $this->_paths; - } - - /** - * Get the file extension used to look for mapping files under - * - * @return void - */ - public function getFileExtension() - { - return $this->_fileExtension; - } - - /** - * Set the file extension used to look for mapping files under - * - * @param string $fileExtension The file extension to set - * @return void - */ - public function setFileExtension($fileExtension) - { - $this->_fileExtension = $fileExtension; - } - - /** - * 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 - * - * @return array $element The element of schema meta data - */ - public function getElement($className) - { - $result = $this->_loadMappingFile($this->_findMappingFile($className)); - - if(!isset($result[$className])){ - throw MappingException::invalidMappingFile($className, str_replace('\\', '.', $className) . $this->_fileExtension); - } - return $result[$className]; - } - - /** - * 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) - { - $fileName = str_replace('\\', '.', $className) . $this->_fileExtension; - - // Check whether file exists - foreach ((array) $this->_paths as $path) { - if (file_exists($path . DIRECTORY_SEPARATOR . $fileName)) { - return false; - } - } - - return true; - } - - /** - * 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() - { - $classes = array(); - - if ($this->_paths) { - foreach ((array) $this->_paths as $path) { - if ( ! is_dir($path)) { - throw MappingException::fileMappingDriversRequireConfiguredDirectoryPath($path); - } - - $iterator = new \RecursiveIteratorIterator( - new \RecursiveDirectoryIterator($path), - \RecursiveIteratorIterator::LEAVES_ONLY - ); - - foreach ($iterator as $file) { - if (($fileName = $file->getBasename($this->_fileExtension)) == $file->getBasename()) { - continue; - } - - // NOTE: All files found here means classes are not transient! - $classes[] = str_replace('.', '\\', $fileName); - } - } - } - - return $classes; + return $this->locator->getPaths(); } /** @@ -185,8 +68,9 @@ abstract class AbstractFileDriver implements Driver * @return string The (absolute) file name. * @throws MappingException */ - protected function _findMappingFile($className) + protected function findMappingFile($className) { + return $this->locator->findMappingFile($className); $fileName = str_replace('\\', '.', $className) . $this->_fileExtension; // Check whether file exists @@ -198,13 +82,4 @@ abstract class AbstractFileDriver implements Driver throw MappingException::mappingFileNotFound($className, $fileName); } - - /** - * Loads a mapping file with the given name and returns a map - * from class/entity names to their corresponding elements. - * - * @param string $file The mapping file to load. - * @return array - */ - abstract protected function _loadMappingFile($file); -} +} \ 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 1e3f7f686..4a4dbd047 100644 --- a/lib/Doctrine/ORM/Mapping/Driver/PHPDriver.php +++ b/lib/Doctrine/ORM/Mapping/Driver/PHPDriver.php @@ -43,6 +43,8 @@ use Doctrine\Common\Cache\ArrayCache, */ class PHPDriver extends AbstractFileDriver { + const DEFAULT_FILE_EXTENSION = '.php'; + /** * {@inheritdoc} */ @@ -52,16 +54,24 @@ class PHPDriver extends AbstractFileDriver /** * {@inheritdoc} */ - public function loadMetadataForClass($className, ClassMetadata $metadata) + public function __construct($locator, $fileExtension = self::DEFAULT_FILE_EXTENSION) { - $this->_metadata = $metadata; - $this->_loadMappingFile($this->_findMappingFile($className)); + parent::__construct($locator, $fileExtension); } /** * {@inheritdoc} */ - protected function _loadMappingFile($file) + public function loadMetadataForClass($className, ClassMetadata $metadata) + { + $this->_metadata = $metadata; + $this->loadMappingFile($this->findMappingFile($className)); + } + + /** + * {@inheritdoc} + */ + protected function loadMappingFile($file) { $metadata = $this->_metadata; include $file; diff --git a/lib/Doctrine/ORM/Mapping/Driver/SimplifiedXmlDriver.php b/lib/Doctrine/ORM/Mapping/Driver/SimplifiedXmlDriver.php index c87282d75..325495d3a 100644 --- a/lib/Doctrine/ORM/Mapping/Driver/SimplifiedXmlDriver.php +++ b/lib/Doctrine/ORM/Mapping/Driver/SimplifiedXmlDriver.php @@ -30,13 +30,19 @@ use Doctrine\ORM\Mapping\MappingException; */ class SimplifiedXmlDriver extends XmlDriver { + const DEFAULT_FILE_EXTENSION = '.orm.xml'; + protected $_prefixes = array(); protected $_globalBasename; protected $_classCache; protected $_fileExtension = '.orm.xml'; - public function __construct($prefixes) + /** + * {@inheritdoc} + */ + public function __construct($prefixes, $fileExtension = self::DEFAULT_FILE_EXTENSION) { + parent::__construct(array(), $fileExtension); $this->addNamespacePrefixes($prefixes); } @@ -73,7 +79,7 @@ class SimplifiedXmlDriver extends XmlDriver } try { - $this->_findMappingFile($className); + $this->findMappingFile($className); return false; } catch (MappingException $e) { @@ -139,13 +145,13 @@ class SimplifiedXmlDriver extends XmlDriver if (null !== $this->_globalBasename) { foreach ($this->_paths as $path) { if (is_file($file = $path.'/'.$this->_globalBasename.$this->_fileExtension)) { - $this->_classCache = array_merge($this->_classCache, $this->_loadMappingFile($file)); + $this->_classCache = array_merge($this->_classCache, $this->loadMappingFile($file)); } } } } - protected function _findMappingFile($className) + protected function findMappingFile($className) { $defaultFileName = str_replace('\\', '.', $className).$this->_fileExtension; foreach ($this->_paths as $path) { diff --git a/lib/Doctrine/ORM/Mapping/Driver/SimplifiedYamlDriver.php b/lib/Doctrine/ORM/Mapping/Driver/SimplifiedYamlDriver.php index 31c4eb85e..a6e55ae84 100644 --- a/lib/Doctrine/ORM/Mapping/Driver/SimplifiedYamlDriver.php +++ b/lib/Doctrine/ORM/Mapping/Driver/SimplifiedYamlDriver.php @@ -30,13 +30,19 @@ use Doctrine\ORM\Mapping\MappingException; */ class SimplifiedYamlDriver extends YamlDriver { + const DEFAULT_FILE_EXTENSION = '.orm.xml'; + protected $_prefixes = array(); protected $_globalBasename; protected $_classCache; protected $_fileExtension = '.orm.yml'; - public function __construct($prefixes) + /** + * {@inheritdoc} + */ + public function __construct($prefixes, $fileExtension = self::DEFAULT_FILE_EXTENSION) { + parent::__construct(array(), $fileExtension); $this->addNamespacePrefixes($prefixes); } @@ -78,7 +84,7 @@ class SimplifiedYamlDriver extends YamlDriver } try { - $this->_findMappingFile($className); + $this->findMappingFile($className); return false; } catch (MappingException $e) { @@ -144,13 +150,13 @@ class SimplifiedYamlDriver extends YamlDriver if (null !== $this->_globalBasename) { foreach ($this->_paths as $path) { if (is_file($file = $path.'/'.$this->_globalBasename.$this->_fileExtension)) { - $this->_classCache = array_merge($this->_classCache, $this->_loadMappingFile($file)); + $this->_classCache = array_merge($this->_classCache, $this->loadMappingFile($file)); } } } } - protected function _findMappingFile($className) + protected function findMappingFile($className) { $defaultFileName = str_replace('\\', '.', $className).$this->_fileExtension; foreach ($this->_paths as $path) { diff --git a/lib/Doctrine/ORM/Mapping/Driver/XmlDriver.php b/lib/Doctrine/ORM/Mapping/Driver/XmlDriver.php index 46b46dc5f..3ab7a08f2 100644 --- a/lib/Doctrine/ORM/Mapping/Driver/XmlDriver.php +++ b/lib/Doctrine/ORM/Mapping/Driver/XmlDriver.php @@ -36,10 +36,15 @@ use SimpleXMLElement, */ class XmlDriver extends AbstractFileDriver { + const DEFAULT_FILE_EXTENSION = '.dcm.xml'; + /** * {@inheritdoc} */ - protected $_fileExtension = '.dcm.xml'; + public function __construct($locator, $fileExtension = self::DEFAULT_FILE_EXTENSION) + { + parent::__construct($locator, $fileExtension); + } /** * {@inheritdoc} @@ -681,7 +686,7 @@ class XmlDriver extends AbstractFileDriver /** * {@inheritdoc} */ - protected function _loadMappingFile($file) + protected function loadMappingFile($file) { $result = array(); $xmlElement = simplexml_load_file($file); diff --git a/lib/Doctrine/ORM/Mapping/Driver/YamlDriver.php b/lib/Doctrine/ORM/Mapping/Driver/YamlDriver.php index fb31c5416..d74505150 100644 --- a/lib/Doctrine/ORM/Mapping/Driver/YamlDriver.php +++ b/lib/Doctrine/ORM/Mapping/Driver/YamlDriver.php @@ -20,7 +20,8 @@ namespace Doctrine\ORM\Mapping\Driver; use Doctrine\Common\Persistence\Mapping\ClassMetadata, - Doctrine\ORM\Mapping\MappingException; + Doctrine\ORM\Mapping\MappingException, + Symfony\Component\Yaml\Yaml; /** * The YamlDriver reads the mapping metadata from yaml schema files. @@ -33,10 +34,15 @@ use Doctrine\Common\Persistence\Mapping\ClassMetadata, */ class YamlDriver extends AbstractFileDriver { + const DEFAULT_FILE_EXTENSION = '.dcm.yml'; + /** * {@inheritdoc} */ - protected $_fileExtension = '.dcm.yml'; + public function __construct($locator, $fileExtension = self::DEFAULT_FILE_EXTENSION) + { + parent::__construct($locator, $fileExtension); + } /** * {@inheritdoc} @@ -666,8 +672,8 @@ class YamlDriver extends AbstractFileDriver /** * {@inheritdoc} */ - protected function _loadMappingFile($file) + protected function loadMappingFile($file) { - return \Symfony\Component\Yaml\Yaml::parse($file); + return Yaml::parse($file); } } diff --git a/tests/Doctrine/Tests/ORM/Mapping/Symfony/AbstractDriverTest.php b/tests/Doctrine/Tests/ORM/Mapping/Symfony/AbstractDriverTest.php index d16db4fbb..18e0d5534 100644 --- a/tests/Doctrine/Tests/ORM/Mapping/Symfony/AbstractDriverTest.php +++ b/tests/Doctrine/Tests/ORM/Mapping/Symfony/AbstractDriverTest.php @@ -32,7 +32,7 @@ abstract class AbstractDriverTest extends \PHPUnit_Framework_TestCase )); touch($filename = $this->dir.'/Foo'.$this->getFileExtension()); - $this->assertEquals($filename, $this->invoke($driver, '_findMappingFile', array('MyNamespace\MySubnamespace\Entity\Foo'))); + $this->assertEquals($filename, $this->invoke($driver, 'findMappingFile', array('MyNamespace\MySubnamespace\Entity\Foo'))); } public function testFindMappingFileInSubnamespace() @@ -42,7 +42,7 @@ abstract class AbstractDriverTest extends \PHPUnit_Framework_TestCase )); touch($filename = $this->dir.'/Foo.Bar'.$this->getFileExtension()); - $this->assertEquals($filename, $this->invoke($driver, '_findMappingFile', array('MyNamespace\MySubnamespace\Entity\Foo\Bar'))); + $this->assertEquals($filename, $this->invoke($driver, 'findMappingFile', array('MyNamespace\MySubnamespace\Entity\Foo\Bar'))); } public function testFindMappingFileNamespacedFoundFileNotFound() From e9f23d51e0108313da2d5c26ab9606862b944df8 Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Tue, 17 Jan 2012 13:14:39 +0100 Subject: [PATCH 03/22] Removing unused code --- lib/Doctrine/ORM/Mapping/Driver/AbstractFileDriver.php | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/lib/Doctrine/ORM/Mapping/Driver/AbstractFileDriver.php b/lib/Doctrine/ORM/Mapping/Driver/AbstractFileDriver.php index 9a4ee054c..7075ee646 100644 --- a/lib/Doctrine/ORM/Mapping/Driver/AbstractFileDriver.php +++ b/lib/Doctrine/ORM/Mapping/Driver/AbstractFileDriver.php @@ -71,15 +71,5 @@ abstract class AbstractFileDriver extends FileDriver implements Driver protected function findMappingFile($className) { return $this->locator->findMappingFile($className); - $fileName = str_replace('\\', '.', $className) . $this->_fileExtension; - - // Check whether file exists - foreach ((array) $this->_paths as $path) { - if (file_exists($path . DIRECTORY_SEPARATOR . $fileName)) { - return $path . DIRECTORY_SEPARATOR . $fileName; - } - } - - throw MappingException::mappingFileNotFound($className, $fileName); } } \ No newline at end of file From bb998d1738f6d0c722892b68b43cbefc23c6ec9d Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Tue, 17 Jan 2012 13:55:42 +0100 Subject: [PATCH 04/22] Emulating feature that has to be moved to Doctrine\Common --- .../ORM/Mapping/Driver/AbstractFileDriver.php | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/lib/Doctrine/ORM/Mapping/Driver/AbstractFileDriver.php b/lib/Doctrine/ORM/Mapping/Driver/AbstractFileDriver.php index 7075ee646..0d8720708 100644 --- a/lib/Doctrine/ORM/Mapping/Driver/AbstractFileDriver.php +++ b/lib/Doctrine/ORM/Mapping/Driver/AbstractFileDriver.php @@ -60,6 +60,23 @@ abstract class AbstractFileDriver extends FileDriver implements Driver 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 + * + * @return array $element The element of schema meta data + * @throws MappingException + * @todo move behavior to FileDriver + */ + public function getElement($className) + { + $result = parent::getElement($className); + if($result === null) { + throw MappingException::invalidMappingFile($className, str_replace('\\', '.', $className) . $this->locator->getFileExtension()); + } + return $result; + } + /** * Finds the mapping file for the class with the given name by searching * through the configured paths. From 82cfda3decf7efb6688af5a7915e418eec105776 Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Tue, 17 Jan 2012 13:57:34 +0100 Subject: [PATCH 05/22] Fixing reflection exceptions caused by changes in the AbstractFileDriver interface --- .../Doctrine/Tests/ORM/Mapping/Symfony/AbstractDriverTest.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/Doctrine/Tests/ORM/Mapping/Symfony/AbstractDriverTest.php b/tests/Doctrine/Tests/ORM/Mapping/Symfony/AbstractDriverTest.php index 18e0d5534..7315b57b2 100644 --- a/tests/Doctrine/Tests/ORM/Mapping/Symfony/AbstractDriverTest.php +++ b/tests/Doctrine/Tests/ORM/Mapping/Symfony/AbstractDriverTest.php @@ -56,7 +56,7 @@ abstract class AbstractDriverTest extends \PHPUnit_Framework_TestCase 'MyNamespace\MySubnamespace\Entity' => $this->dir, )); - $this->invoke($driver, '_findMappingFile', array('MyNamespace\MySubnamespace\Entity\Foo')); + $this->invoke($driver, 'findMappingFile', array('MyNamespace\MySubnamespace\Entity\Foo')); } public function testFindMappingNamespaceNotFound() @@ -70,7 +70,7 @@ abstract class AbstractDriverTest extends \PHPUnit_Framework_TestCase 'MyNamespace\MySubnamespace\Entity' => $this->dir, )); - $this->invoke($driver, '_findMappingFile', array('MyOtherNamespace\MySubnamespace\Entity\Foo')); + $this->invoke($driver, 'findMappingFile', array('MyOtherNamespace\MySubnamespace\Entity\Foo')); } protected function setUp() From 03fb734de82b4c064cee4e75f1b509ebff760244 Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Tue, 17 Jan 2012 14:31:27 +0100 Subject: [PATCH 06/22] 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); From ccace8cb8bbfe0ef49e336c1f4e81ba4272879ac Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Tue, 17 Jan 2012 15:39:52 +0100 Subject: [PATCH 07/22] Moving exception throwing for invalid file mappings to Doctrine\Common\Persistence\Mapping\Driver\FileDriver --- .../ORM/Mapping/Driver/AbstractFileDriver.php | 16 ---------------- lib/Doctrine/ORM/Mapping/MappingException.php | 7 +------ .../Tests/ORM/Mapping/XmlMappingDriverTest.php | 2 +- .../Tests/ORM/Mapping/YamlMappingDriverTest.php | 2 +- 4 files changed, 3 insertions(+), 24 deletions(-) diff --git a/lib/Doctrine/ORM/Mapping/Driver/AbstractFileDriver.php b/lib/Doctrine/ORM/Mapping/Driver/AbstractFileDriver.php index 31e7e068e..1bbed0cf2 100644 --- a/lib/Doctrine/ORM/Mapping/Driver/AbstractFileDriver.php +++ b/lib/Doctrine/ORM/Mapping/Driver/AbstractFileDriver.php @@ -41,20 +41,4 @@ use Doctrine\Common\Persistence\Mapping\Driver\FileLocator; */ abstract class AbstractFileDriver extends FileDriver implements Driver { - /** - * 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 - * - * @return array $element The element of schema meta data - * @throws MappingException - * @todo move behavior to FileDriver - */ - public function getElement($className) - { - $result = parent::getElement($className); - if($result === null) { - throw MappingException::invalidMappingFile($className, str_replace('\\', '.', $className) . $this->locator->getFileExtension()); - } - return $result; - } } \ No newline at end of file diff --git a/lib/Doctrine/ORM/Mapping/MappingException.php b/lib/Doctrine/ORM/Mapping/MappingException.php index 86dc5dd25..fd4e1a8ec 100644 --- a/lib/Doctrine/ORM/Mapping/MappingException.php +++ b/lib/Doctrine/ORM/Mapping/MappingException.php @@ -78,11 +78,6 @@ class MappingException extends \Doctrine\ORM\ORMException return new self("No mapping file found named '$fileName' for class '$entityName'."); } - public static function invalidMappingFile($entityName, $fileName) - { - return new self("Invalid mapping file '$fileName' for class '$entityName'."); - } - /** * Exception for invalid property name override. * @@ -144,7 +139,7 @@ class MappingException extends \Doctrine\ORM\ORMException { return new self('Result set mapping named "'.$resultName.'" in "'.$entity.' requires a field name.'); } - + public static function nameIsMandatoryForSqlResultSetMapping($className) { return new self("Result set mapping name on entity class '$className' is not defined."); diff --git a/tests/Doctrine/Tests/ORM/Mapping/XmlMappingDriverTest.php b/tests/Doctrine/Tests/ORM/Mapping/XmlMappingDriverTest.php index 3106bc1d3..83e524a65 100644 --- a/tests/Doctrine/Tests/ORM/Mapping/XmlMappingDriverTest.php +++ b/tests/Doctrine/Tests/ORM/Mapping/XmlMappingDriverTest.php @@ -55,7 +55,7 @@ class XmlMappingDriverTest extends AbstractMappingDriverTest /** * @group DDC-1468 * - * @expectedException Doctrine\ORM\Mapping\MappingException + * @expectedException Doctrine\Common\Persistence\Mapping\MappingException * @expectedExceptionMessage Invalid mapping file 'Doctrine.Tests.Models.Generic.SerializationModel.dcm.xml' for class 'Doctrine\Tests\Models\Generic\SerializationModel'. */ public function testInvalidMappingFileException() diff --git a/tests/Doctrine/Tests/ORM/Mapping/YamlMappingDriverTest.php b/tests/Doctrine/Tests/ORM/Mapping/YamlMappingDriverTest.php index 08570a22c..91dd7e3bd 100644 --- a/tests/Doctrine/Tests/ORM/Mapping/YamlMappingDriverTest.php +++ b/tests/Doctrine/Tests/ORM/Mapping/YamlMappingDriverTest.php @@ -46,7 +46,7 @@ class YamlMappingDriverTest extends AbstractMappingDriverTest /** * @group DDC-1468 * - * @expectedException Doctrine\ORM\Mapping\MappingException + * @expectedException Doctrine\Common\Persistence\Mapping\MappingException * @expectedExceptionMessage Invalid mapping file 'Doctrine.Tests.Models.Generic.SerializationModel.dcm.yml' for class 'Doctrine\Tests\Models\Generic\SerializationModel'. */ public function testInvalidMappingFileException() From abd3ddc1b1076da6c9e0c2d791504117e2e136bc Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Tue, 17 Jan 2012 16:05:20 +0100 Subject: [PATCH 08/22] Removing code duplication, reusing Doctrine\Common\Persistenc\Mapping\Driver\AnnotationDriver --- .gitignore | 2 +- .../ORM/Mapping/Driver/AnnotationDriver.php | 223 +++--------------- 2 files changed, 29 insertions(+), 196 deletions(-) diff --git a/.gitignore b/.gitignore index a91841777..b49fac4bf 100644 --- a/.gitignore +++ b/.gitignore @@ -8,4 +8,4 @@ lib/Doctrine/Common lib/Doctrine/DBAL /.settings/ .buildpath -.project +.project \ No newline at end of file diff --git a/lib/Doctrine/ORM/Mapping/Driver/AnnotationDriver.php b/lib/Doctrine/ORM/Mapping/Driver/AnnotationDriver.php index 203dd42e0..07f27c76e 100644 --- a/lib/Doctrine/ORM/Mapping/Driver/AnnotationDriver.php +++ b/lib/Doctrine/ORM/Mapping/Driver/AnnotationDriver.php @@ -25,7 +25,8 @@ use Doctrine\Common\Cache\ArrayCache, Doctrine\ORM\Mapping\MappingException, Doctrine\ORM\Mapping\JoinColumn, Doctrine\ORM\Mapping\Column, - Doctrine\Common\Persistence\Mapping\ClassMetadata; + Doctrine\Common\Persistence\Mapping\ClassMetadata, + Doctrine\Common\Persistence\Mapping\Driver\AnnotationDriver as AbstractAnnotationDriver; /** * The AnnotationDriver reads the mapping metadata from docblock annotations. @@ -36,99 +37,15 @@ use Doctrine\Common\Cache\ArrayCache, * @author Jonathan H. Wage * @author Roman Borschel */ -class AnnotationDriver implements Driver +class AnnotationDriver extends AbstractAnnotationDriver implements Driver { /** - * The AnnotationReader. - * - * @var AnnotationReader + * {@inheritdoc} */ - protected $_reader; - - /** - * The paths where to look for mapping files. - * - * @var array - */ - protected $_paths = array(); - - /** - * The file extension of mapping documents. - * - * @var string - */ - protected $_fileExtension = '.php'; - - /** - * @param array - */ - protected $_classNames; - - /** - * Initializes a new AnnotationDriver that uses the given AnnotationReader for reading - * docblock annotations. - * - * @param AnnotationReader $reader The AnnotationReader to use, duck-typed. - * @param string|array $paths One or multiple paths where mapping classes can be found. - */ - public function __construct($reader, $paths = null) - { - $this->_reader = $reader; - if ($paths) { - $this->addPaths((array) $paths); - } - } - - /** - * Append lookup paths to metadata driver. - * - * @param array $paths - */ - public function addPaths(array $paths) - { - $this->_paths = array_unique(array_merge($this->_paths, $paths)); - } - - /** - * Retrieve the defined metadata lookup paths. - * - * @return array - */ - public function getPaths() - { - return $this->_paths; - } - - /** - * Retrieve the current annotation reader - * - * @return AnnotationReader - */ - public function getReader() - { - return $this->_reader; - } - - /** - * Get the file extension used to look for mapping files under - * - * @return void - */ - public function getFileExtension() - { - return $this->_fileExtension; - } - - /** - * Set the file extension used to look for mapping files under - * - * @param string $fileExtension The file extension to set - * @return void - */ - public function setFileExtension($fileExtension) - { - $this->_fileExtension = $fileExtension; - } + protected $entityAnnotationClasses = array( + 'Doctrine\ORM\Mapping\Entity' => 1, + 'Doctrine\ORM\Mapping\MappedSuperclass' => 2, + ); /** * {@inheritdoc} @@ -142,7 +59,7 @@ class AnnotationDriver implements Driver $class = new \ReflectionClass($metadata->name); } - $classAnnotations = $this->_reader->getClassAnnotations($class); + $classAnnotations = $this->reader->getClassAnnotations($class); if ($classAnnotations && is_numeric(key($classAnnotations))) { foreach ($classAnnotations as $annot) { @@ -364,9 +281,9 @@ class AnnotationDriver implements Driver // Check for JoinColummn/JoinColumns annotations $joinColumns = array(); - if ($joinColumnAnnot = $this->_reader->getPropertyAnnotation($property, 'Doctrine\ORM\Mapping\JoinColumn')) { + if ($joinColumnAnnot = $this->reader->getPropertyAnnotation($property, 'Doctrine\ORM\Mapping\JoinColumn')) { $joinColumns[] = $this->joinColumnToArray($joinColumnAnnot); - } else if ($joinColumnsAnnot = $this->_reader->getPropertyAnnotation($property, 'Doctrine\ORM\Mapping\JoinColumns')) { + } else if ($joinColumnsAnnot = $this->reader->getPropertyAnnotation($property, 'Doctrine\ORM\Mapping\JoinColumns')) { foreach ($joinColumnsAnnot->value as $joinColumn) { $joinColumns[] = $this->joinColumnToArray($joinColumn); } @@ -374,43 +291,43 @@ class AnnotationDriver implements Driver // Field can only be annotated with one of: // @Column, @OneToOne, @OneToMany, @ManyToOne, @ManyToMany - if ($columnAnnot = $this->_reader->getPropertyAnnotation($property, 'Doctrine\ORM\Mapping\Column')) { + if ($columnAnnot = $this->reader->getPropertyAnnotation($property, 'Doctrine\ORM\Mapping\Column')) { if ($columnAnnot->type == null) { throw MappingException::propertyTypeIsRequired($className, $property->getName()); } $mapping = $this->columnToArray($property->getName(), $columnAnnot); - if ($idAnnot = $this->_reader->getPropertyAnnotation($property, 'Doctrine\ORM\Mapping\Id')) { + if ($idAnnot = $this->reader->getPropertyAnnotation($property, 'Doctrine\ORM\Mapping\Id')) { $mapping['id'] = true; } - if ($generatedValueAnnot = $this->_reader->getPropertyAnnotation($property, 'Doctrine\ORM\Mapping\GeneratedValue')) { + if ($generatedValueAnnot = $this->reader->getPropertyAnnotation($property, 'Doctrine\ORM\Mapping\GeneratedValue')) { $metadata->setIdGeneratorType(constant('Doctrine\ORM\Mapping\ClassMetadata::GENERATOR_TYPE_' . $generatedValueAnnot->strategy)); } - if ($this->_reader->getPropertyAnnotation($property, 'Doctrine\ORM\Mapping\Version')) { + if ($this->reader->getPropertyAnnotation($property, 'Doctrine\ORM\Mapping\Version')) { $metadata->setVersionMapping($mapping); } $metadata->mapField($mapping); // Check for SequenceGenerator/TableGenerator definition - if ($seqGeneratorAnnot = $this->_reader->getPropertyAnnotation($property, 'Doctrine\ORM\Mapping\SequenceGenerator')) { + if ($seqGeneratorAnnot = $this->reader->getPropertyAnnotation($property, 'Doctrine\ORM\Mapping\SequenceGenerator')) { $metadata->setSequenceGeneratorDefinition(array( 'sequenceName' => $seqGeneratorAnnot->sequenceName, 'allocationSize' => $seqGeneratorAnnot->allocationSize, 'initialValue' => $seqGeneratorAnnot->initialValue )); - } else if ($this->_reader->getPropertyAnnotation($property, 'Doctrine\ORM\Mapping\TableGenerator')) { + } else if ($this->reader->getPropertyAnnotation($property, 'Doctrine\ORM\Mapping\TableGenerator')) { throw MappingException::tableIdGeneratorNotImplemented($className); - } else if ($customGeneratorAnnot = $this->_reader->getPropertyAnnotation($property, 'Doctrine\ORM\Mapping\CustomIdGenerator')) { + } else if ($customGeneratorAnnot = $this->reader->getPropertyAnnotation($property, 'Doctrine\ORM\Mapping\CustomIdGenerator')) { $metadata->setCustomGeneratorDefinition(array( 'class' => $customGeneratorAnnot->class )); } - } else if ($oneToOneAnnot = $this->_reader->getPropertyAnnotation($property, 'Doctrine\ORM\Mapping\OneToOne')) { - if ($idAnnot = $this->_reader->getPropertyAnnotation($property, 'Doctrine\ORM\Mapping\Id')) { + } else if ($oneToOneAnnot = $this->reader->getPropertyAnnotation($property, 'Doctrine\ORM\Mapping\OneToOne')) { + if ($idAnnot = $this->reader->getPropertyAnnotation($property, 'Doctrine\ORM\Mapping\Id')) { $mapping['id'] = true; } @@ -422,7 +339,7 @@ class AnnotationDriver implements Driver $mapping['orphanRemoval'] = $oneToOneAnnot->orphanRemoval; $mapping['fetch'] = $this->getFetchMode($className, $oneToOneAnnot->fetch); $metadata->mapOneToOne($mapping); - } else if ($oneToManyAnnot = $this->_reader->getPropertyAnnotation($property, 'Doctrine\ORM\Mapping\OneToMany')) { + } else if ($oneToManyAnnot = $this->reader->getPropertyAnnotation($property, 'Doctrine\ORM\Mapping\OneToMany')) { $mapping['mappedBy'] = $oneToManyAnnot->mappedBy; $mapping['targetEntity'] = $oneToManyAnnot->targetEntity; $mapping['cascade'] = $oneToManyAnnot->cascade; @@ -430,13 +347,13 @@ class AnnotationDriver implements Driver $mapping['orphanRemoval'] = $oneToManyAnnot->orphanRemoval; $mapping['fetch'] = $this->getFetchMode($className, $oneToManyAnnot->fetch); - if ($orderByAnnot = $this->_reader->getPropertyAnnotation($property, 'Doctrine\ORM\Mapping\OrderBy')) { + if ($orderByAnnot = $this->reader->getPropertyAnnotation($property, 'Doctrine\ORM\Mapping\OrderBy')) { $mapping['orderBy'] = $orderByAnnot->value; } $metadata->mapOneToMany($mapping); - } else if ($manyToOneAnnot = $this->_reader->getPropertyAnnotation($property, 'Doctrine\ORM\Mapping\ManyToOne')) { - if ($idAnnot = $this->_reader->getPropertyAnnotation($property, 'Doctrine\ORM\Mapping\Id')) { + } else if ($manyToOneAnnot = $this->reader->getPropertyAnnotation($property, 'Doctrine\ORM\Mapping\ManyToOne')) { + if ($idAnnot = $this->reader->getPropertyAnnotation($property, 'Doctrine\ORM\Mapping\Id')) { $mapping['id'] = true; } @@ -446,10 +363,10 @@ class AnnotationDriver implements Driver $mapping['targetEntity'] = $manyToOneAnnot->targetEntity; $mapping['fetch'] = $this->getFetchMode($className, $manyToOneAnnot->fetch); $metadata->mapManyToOne($mapping); - } else if ($manyToManyAnnot = $this->_reader->getPropertyAnnotation($property, 'Doctrine\ORM\Mapping\ManyToMany')) { + } else if ($manyToManyAnnot = $this->reader->getPropertyAnnotation($property, 'Doctrine\ORM\Mapping\ManyToMany')) { $joinTable = array(); - if ($joinTableAnnot = $this->_reader->getPropertyAnnotation($property, 'Doctrine\ORM\Mapping\JoinTable')) { + if ($joinTableAnnot = $this->reader->getPropertyAnnotation($property, 'Doctrine\ORM\Mapping\JoinTable')) { $joinTable = array( 'name' => $joinTableAnnot->name, 'schema' => $joinTableAnnot->schema @@ -473,7 +390,7 @@ class AnnotationDriver implements Driver $mapping['orphanRemoval'] = $manyToManyAnnot->orphanRemoval; $mapping['fetch'] = $this->getFetchMode($className, $manyToManyAnnot->fetch); - if ($orderByAnnot = $this->_reader->getPropertyAnnotation($property, 'Doctrine\ORM\Mapping\OrderBy')) { + if ($orderByAnnot = $this->reader->getPropertyAnnotation($property, 'Doctrine\ORM\Mapping\OrderBy')) { $mapping['orderBy'] = $orderByAnnot->value; } @@ -537,7 +454,7 @@ class AnnotationDriver implements Driver foreach ($class->getMethods() as $method) { // filter for the declaring class only, callbacks from parents will already be registered. if ($method->isPublic() && $method->getDeclaringClass()->getName() == $class->name) { - $annotations = $this->_reader->getMethodAnnotations($method); + $annotations = $this->reader->getMethodAnnotations($method); if ($annotations && is_numeric(key($annotations))) { foreach ($annotations as $annot) { @@ -581,90 +498,6 @@ class AnnotationDriver implements Driver } } - /** - * Whether the class with the specified name is transient. Only non-transient - * classes, that is entities and mapped superclasses, should have their metadata loaded. - * A class is non-transient if it is annotated with either @Entity or - * @MappedSuperclass in the class doc block. - * - * @param string $className - * @return boolean - */ - public function isTransient($className) - { - $classAnnotations = $this->_reader->getClassAnnotations(new \ReflectionClass($className)); - - if ($classAnnotations && is_numeric(key($classAnnotations))) { - foreach ($classAnnotations as $annot) { - if ($annot instanceof \Doctrine\ORM\Mapping\Entity) { - return false; - } - if ($annot instanceof \Doctrine\ORM\Mapping\MappedSuperclass) { - return false; - } - } - - return true; - } - - return ! isset($classAnnotations['Doctrine\ORM\Mapping\Entity']) && - ! isset($classAnnotations['Doctrine\ORM\Mapping\MappedSuperclass']); - } - - /** - * {@inheritDoc} - */ - public function getAllClassNames() - { - if ($this->_classNames !== null) { - return $this->_classNames; - } - - if ( ! $this->_paths) { - throw MappingException::pathRequired(); - } - - $classes = array(); - $includedFiles = array(); - - foreach ($this->_paths as $path) { - if ( ! is_dir($path)) { - throw MappingException::fileMappingDriversRequireConfiguredDirectoryPath($path); - } - - $iterator = new \RegexIterator( - new \RecursiveIteratorIterator( - new \RecursiveDirectoryIterator($path, \FilesystemIterator::SKIP_DOTS), - \RecursiveIteratorIterator::LEAVES_ONLY - ), - '/^.+' . str_replace('.', '\.', $this->_fileExtension) . '$/i', - \RecursiveRegexIterator::GET_MATCH - ); - - foreach ($iterator as $file) { - $sourceFile = realpath($file[0]); - - require_once $sourceFile; - - $includedFiles[] = $sourceFile; - } - } - - $declared = get_declared_classes(); - - foreach ($declared as $className) { - $rc = new \ReflectionClass($className); - $sourceFile = $rc->getFileName(); - if (in_array($sourceFile, $includedFiles) && ! $this->isTransient($className)) { - $classes[] = $className; - } - } - - $this->_classNames = $classes; - - return $classes; - } - /** * Attempts to resolve the fetch mode. * From 5b973574023dad903c0e5592907c7a90f73406a4 Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Tue, 17 Jan 2012 17:44:19 +0100 Subject: [PATCH 09/22] Removing unused imports --- lib/Doctrine/ORM/Mapping/Driver/AbstractFileDriver.php | 1 - lib/Doctrine/ORM/Mapping/Driver/AnnotationDriver.php | 4 +--- lib/Doctrine/ORM/Mapping/Driver/DatabaseDriver.php | 9 ++------- 3 files changed, 3 insertions(+), 11 deletions(-) diff --git a/lib/Doctrine/ORM/Mapping/Driver/AbstractFileDriver.php b/lib/Doctrine/ORM/Mapping/Driver/AbstractFileDriver.php index 1bbed0cf2..35f9ce003 100644 --- a/lib/Doctrine/ORM/Mapping/Driver/AbstractFileDriver.php +++ b/lib/Doctrine/ORM/Mapping/Driver/AbstractFileDriver.php @@ -19,7 +19,6 @@ namespace Doctrine\ORM\Mapping\Driver; -use Doctrine\ORM\Mapping\MappingException; use Doctrine\Common\Persistence\Mapping\Driver\FileDriver; use Doctrine\Common\Persistence\Mapping\Driver\FileLocator; diff --git a/lib/Doctrine/ORM/Mapping/Driver/AnnotationDriver.php b/lib/Doctrine/ORM/Mapping/Driver/AnnotationDriver.php index 07f27c76e..8ffdb6abe 100644 --- a/lib/Doctrine/ORM/Mapping/Driver/AnnotationDriver.php +++ b/lib/Doctrine/ORM/Mapping/Driver/AnnotationDriver.php @@ -19,9 +19,7 @@ namespace Doctrine\ORM\Mapping\Driver; -use Doctrine\Common\Cache\ArrayCache, - Doctrine\Common\Annotations\AnnotationReader, - Doctrine\Common\Annotations\AnnotationRegistry, +use Doctrine\Common\Annotations\AnnotationReader, Doctrine\ORM\Mapping\MappingException, Doctrine\ORM\Mapping\JoinColumn, Doctrine\ORM\Mapping\Column, diff --git a/lib/Doctrine/ORM/Mapping/Driver/DatabaseDriver.php b/lib/Doctrine/ORM/Mapping/Driver/DatabaseDriver.php index 868835a35..5e6733be5 100644 --- a/lib/Doctrine/ORM/Mapping/Driver/DatabaseDriver.php +++ b/lib/Doctrine/ORM/Mapping/Driver/DatabaseDriver.php @@ -19,13 +19,10 @@ namespace Doctrine\ORM\Mapping\Driver; -use Doctrine\Common\Cache\ArrayCache, - Doctrine\Common\Annotations\AnnotationReader, - Doctrine\DBAL\Schema\AbstractSchemaManager, +use Doctrine\DBAL\Schema\AbstractSchemaManager, Doctrine\DBAL\Schema\SchemaException, Doctrine\Common\Persistence\Mapping\ClassMetadata, Doctrine\ORM\Mapping\ClassMetadataInfo, - Doctrine\ORM\Mapping\MappingException, Doctrine\Common\Util\Inflector; /** @@ -75,10 +72,8 @@ class DatabaseDriver implements Driver private $namespace; /** - * Initializes a new AnnotationDriver that uses the given AnnotationReader for reading - * docblock annotations. * - * @param AnnotationReader $reader The AnnotationReader to use. + * @param AbstractSchemaManager $schemaManager */ public function __construct(AbstractSchemaManager $schemaManager) { From 905acf9176618a50989f54f6efbaa379d5a02c9e Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Tue, 17 Jan 2012 17:58:56 +0100 Subject: [PATCH 10/22] Removing Doctrine\ORM\Mapping\Driver\Driver interface Interface has been moved to Doctrine\Common\Persistence\Mapping\Driver\MappingDriver --- lib/Doctrine/ORM/Configuration.php | 8 ++++---- lib/Doctrine/ORM/Mapping/ClassMetadataFactory.php | 2 +- lib/Doctrine/ORM/Mapping/Driver/DriverChain.php | 8 ++++---- tests/Doctrine/Tests/Mocks/MetadataDriverMock.php | 2 +- .../Tests/ORM/Mapping/ClassMetadataFactoryTest.php | 4 ++-- tests/Doctrine/Tests/ORM/Mapping/DriverChainTest.php | 9 ++++----- 6 files changed, 16 insertions(+), 17 deletions(-) diff --git a/lib/Doctrine/ORM/Configuration.php b/lib/Doctrine/ORM/Configuration.php index ff7ea63da..554f77f66 100644 --- a/lib/Doctrine/ORM/Configuration.php +++ b/lib/Doctrine/ORM/Configuration.php @@ -23,7 +23,7 @@ use Doctrine\Common\Cache\Cache, Doctrine\Common\Cache\ArrayCache, Doctrine\Common\Annotations\AnnotationRegistry, Doctrine\Common\Annotations\AnnotationReader, - Doctrine\ORM\Mapping\Driver\Driver, + Doctrine\Common\Persistence\Mapping\Driver\MappingDriver, Doctrine\ORM\Mapping\Driver\AnnotationDriver, Doctrine\ORM\Mapping\QuoteStrategy, Doctrine\ORM\Mapping\DefaultQuoteStrategy, @@ -114,11 +114,11 @@ class Configuration extends \Doctrine\DBAL\Configuration /** * Sets the cache driver implementation that is used for metadata caching. * - * @param Driver $driverImpl + * @param MappingDriver $driverImpl * @todo Force parameter to be a Closure to ensure lazy evaluation * (as soon as a metadata cache is in effect, the driver never needs to initialize). */ - public function setMetadataDriverImpl(Driver $driverImpl) + public function setMetadataDriverImpl(MappingDriver $driverImpl) { $this->_attributes['metadataDriverImpl'] = $driverImpl; } @@ -217,7 +217,7 @@ class Configuration extends \Doctrine\DBAL\Configuration * Gets the cache driver implementation that is used for the mapping metadata. * * @throws ORMException - * @return Mapping\Driver\Driver + * @return MappingDriver */ public function getMetadataDriverImpl() { diff --git a/lib/Doctrine/ORM/Mapping/ClassMetadataFactory.php b/lib/Doctrine/ORM/Mapping/ClassMetadataFactory.php index 378f1cc98..6f8ee80b2 100644 --- a/lib/Doctrine/ORM/Mapping/ClassMetadataFactory.php +++ b/lib/Doctrine/ORM/Mapping/ClassMetadataFactory.php @@ -53,7 +53,7 @@ class ClassMetadataFactory implements ClassMetadataFactoryInterface private $targetPlatform; /** - * @var \Doctrine\ORM\Mapping\Driver\Driver + * @var \Doctrine\Common\Persistence\Mapping\Driver\MappingDriver */ private $driver; diff --git a/lib/Doctrine/ORM/Mapping/Driver/DriverChain.php b/lib/Doctrine/ORM/Mapping/Driver/DriverChain.php index 8536d7365..267e9d534 100644 --- a/lib/Doctrine/ORM/Mapping/Driver/DriverChain.php +++ b/lib/Doctrine/ORM/Mapping/Driver/DriverChain.php @@ -19,7 +19,7 @@ namespace Doctrine\ORM\Mapping\Driver; -use Doctrine\ORM\Mapping\Driver\Driver, +use Doctrine\Common\Persistence\Mapping\Driver\MappingDriver, Doctrine\Common\Persistence\Mapping\ClassMetadata, Doctrine\ORM\Mapping\MappingException; @@ -34,7 +34,7 @@ use Doctrine\ORM\Mapping\Driver\Driver, * @author Roman Borschel * @todo Rename: MappingDriverChain or MetadataDriverChain */ -class DriverChain implements Driver +class DriverChain implements MappingDriver { /** * @var array @@ -71,10 +71,10 @@ class DriverChain implements Driver /** * Add a nested driver. * - * @param Driver $nestedDriver + * @param MappingDriver $nestedDriver * @param string $namespace */ - public function addDriver(Driver $nestedDriver, $namespace) + public function addDriver(MappingDriver $nestedDriver, $namespace) { $this->drivers[$namespace] = $nestedDriver; } diff --git a/tests/Doctrine/Tests/Mocks/MetadataDriverMock.php b/tests/Doctrine/Tests/Mocks/MetadataDriverMock.php index 87f560e64..3dfb5e3a9 100644 --- a/tests/Doctrine/Tests/Mocks/MetadataDriverMock.php +++ b/tests/Doctrine/Tests/Mocks/MetadataDriverMock.php @@ -2,7 +2,7 @@ namespace Doctrine\Tests\Mocks; -class MetadataDriverMock implements \Doctrine\ORM\Mapping\Driver\Driver +class MetadataDriverMock implements \Doctrine\Common\Persistence\Mapping\Driver\MappingDriver { public function loadMetadataForClass($className, \Doctrine\Common\Persistence\Mapping\ClassMetadata $metadata) { diff --git a/tests/Doctrine/Tests/ORM/Mapping/ClassMetadataFactoryTest.php b/tests/Doctrine/Tests/ORM/Mapping/ClassMetadataFactoryTest.php index f1654dcfd..100e4df85 100644 --- a/tests/Doctrine/Tests/ORM/Mapping/ClassMetadataFactoryTest.php +++ b/tests/Doctrine/Tests/ORM/Mapping/ClassMetadataFactoryTest.php @@ -114,7 +114,7 @@ class ClassMetadataFactoryTest extends \Doctrine\Tests\OrmTestCase public function testIsTransient() { $cmf = new ClassMetadataFactory(); - $driver = $this->getMock('Doctrine\ORM\Mapping\Driver\Driver'); + $driver = $this->getMock('Doctrine\Common\Persistence\Mapping\Driver\MappingDriver'); $driver->expects($this->at(0)) ->method('isTransient') ->with($this->equalTo('Doctrine\Tests\Models\CMS\CmsUser')) @@ -136,7 +136,7 @@ class ClassMetadataFactoryTest extends \Doctrine\Tests\OrmTestCase public function testIsTransientEntityNamespace() { $cmf = new ClassMetadataFactory(); - $driver = $this->getMock('Doctrine\ORM\Mapping\Driver\Driver'); + $driver = $this->getMock('Doctrine\Common\Persistence\Mapping\Driver\MappingDriver'); $driver->expects($this->at(0)) ->method('isTransient') ->with($this->equalTo('Doctrine\Tests\Models\CMS\CmsUser')) diff --git a/tests/Doctrine/Tests/ORM/Mapping/DriverChainTest.php b/tests/Doctrine/Tests/ORM/Mapping/DriverChainTest.php index 35560f35a..f5fd60a60 100644 --- a/tests/Doctrine/Tests/ORM/Mapping/DriverChainTest.php +++ b/tests/Doctrine/Tests/ORM/Mapping/DriverChainTest.php @@ -2,7 +2,6 @@ namespace Doctrine\Tests\ORM\Mapping; -use Doctrine\ORM\Mapping\Driver\Driver; use Doctrine\ORM\Mapping\Driver\DriverChain; require_once __DIR__ . '/../../TestInit.php'; @@ -16,13 +15,13 @@ class DriverChainTest extends \Doctrine\Tests\OrmTestCase $chain = new DriverChain(); - $driver1 = $this->getMock('Doctrine\ORM\Mapping\Driver\Driver'); + $driver1 = $this->getMock('Doctrine\Common\Persistence\Mapping\Driver\MappingDriver'); $driver1->expects($this->never()) ->method('loadMetadataForClass'); $driver1->expectS($this->never()) ->method('isTransient'); - $driver2 = $this->getMock('Doctrine\ORM\Mapping\Driver\Driver'); + $driver2 = $this->getMock('Doctrine\Common\Persistence\Mapping\Driver\MappingDriver'); $driver2->expects($this->at(0)) ->method('loadMetadataForClass') ->with($this->equalTo($className), $this->equalTo($classMetadata)); @@ -57,12 +56,12 @@ class DriverChainTest extends \Doctrine\Tests\OrmTestCase $chain = new DriverChain(); - $driver1 = $this->getMock('Doctrine\ORM\Mapping\Driver\Driver'); + $driver1 = $this->getMock('Doctrine\Common\Persistence\Mapping\Driver\MappingDriver'); $driver1->expects($this->once()) ->method('getAllClassNames') ->will($this->returnValue(array('Doctrine\Tests\Models\Company\Foo'))); - $driver2 = $this->getMock('Doctrine\ORM\Mapping\Driver\Driver'); + $driver2 = $this->getMock('Doctrine\Common\Persistence\Mapping\Driver\MappingDriver'); $driver2->expects($this->once()) ->method('getAllClassNames') ->will($this->returnValue(array('Doctrine\Tests\ORM\Mapping\Bar', 'Doctrine\Tests\ORM\Mapping\Baz', 'FooBarBaz'))); From e9e36dcf328218f07e88b5ffa9db9bd4ff593275 Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Tue, 17 Jan 2012 18:09:49 +0100 Subject: [PATCH 11/22] Removing Doctrine\ORM\Mapping\Driver\Driver interface Interface has been moved to Doctrine\Common\Persistence\Mapping\Driver\MappingDriver --- .../ORM/Mapping/Driver/AbstractFileDriver.php | 3 +- .../ORM/Mapping/Driver/AnnotationDriver.php | 2 +- .../ORM/Mapping/Driver/DatabaseDriver.php | 3 +- lib/Doctrine/ORM/Mapping/Driver/Driver.php | 33 ------------------- .../ORM/Mapping/Driver/StaticPHPDriver.php | 5 +-- 5 files changed, 7 insertions(+), 39 deletions(-) delete mode 100644 lib/Doctrine/ORM/Mapping/Driver/Driver.php diff --git a/lib/Doctrine/ORM/Mapping/Driver/AbstractFileDriver.php b/lib/Doctrine/ORM/Mapping/Driver/AbstractFileDriver.php index 35f9ce003..8f1e676e1 100644 --- a/lib/Doctrine/ORM/Mapping/Driver/AbstractFileDriver.php +++ b/lib/Doctrine/ORM/Mapping/Driver/AbstractFileDriver.php @@ -20,7 +20,6 @@ namespace Doctrine\ORM\Mapping\Driver; use Doctrine\Common\Persistence\Mapping\Driver\FileDriver; -use Doctrine\Common\Persistence\Mapping\Driver\FileLocator; /** * Base driver for file-based metadata drivers. @@ -38,6 +37,6 @@ use Doctrine\Common\Persistence\Mapping\Driver\FileLocator; * @author Jonathan H. Wage * @author Roman Borschel */ -abstract class AbstractFileDriver extends FileDriver implements Driver +abstract class AbstractFileDriver extends FileDriver { } \ No newline at end of file diff --git a/lib/Doctrine/ORM/Mapping/Driver/AnnotationDriver.php b/lib/Doctrine/ORM/Mapping/Driver/AnnotationDriver.php index 8ffdb6abe..f4501de8b 100644 --- a/lib/Doctrine/ORM/Mapping/Driver/AnnotationDriver.php +++ b/lib/Doctrine/ORM/Mapping/Driver/AnnotationDriver.php @@ -35,7 +35,7 @@ use Doctrine\Common\Annotations\AnnotationReader, * @author Jonathan H. Wage * @author Roman Borschel */ -class AnnotationDriver extends AbstractAnnotationDriver implements Driver +class AnnotationDriver extends AbstractAnnotationDriver { /** * {@inheritdoc} diff --git a/lib/Doctrine/ORM/Mapping/Driver/DatabaseDriver.php b/lib/Doctrine/ORM/Mapping/Driver/DatabaseDriver.php index 5e6733be5..a0705e6c2 100644 --- a/lib/Doctrine/ORM/Mapping/Driver/DatabaseDriver.php +++ b/lib/Doctrine/ORM/Mapping/Driver/DatabaseDriver.php @@ -21,6 +21,7 @@ namespace Doctrine\ORM\Mapping\Driver; use Doctrine\DBAL\Schema\AbstractSchemaManager, Doctrine\DBAL\Schema\SchemaException, + Doctrine\Common\Persistence\Mapping\Driver\MappingDriver, Doctrine\Common\Persistence\Mapping\ClassMetadata, Doctrine\ORM\Mapping\ClassMetadataInfo, Doctrine\Common\Util\Inflector; @@ -35,7 +36,7 @@ use Doctrine\DBAL\Schema\AbstractSchemaManager, * @author Jonathan Wage * @author Benjamin Eberlei */ -class DatabaseDriver implements Driver +class DatabaseDriver implements MappingDriver { /** * @var AbstractSchemaManager diff --git a/lib/Doctrine/ORM/Mapping/Driver/Driver.php b/lib/Doctrine/ORM/Mapping/Driver/Driver.php deleted file mode 100644 index 2ec4866f7..000000000 --- a/lib/Doctrine/ORM/Mapping/Driver/Driver.php +++ /dev/null @@ -1,33 +0,0 @@ -. - */ - -namespace Doctrine\ORM\Mapping\Driver; - -use Doctrine\Common\Persistence\Mapping\Driver\MappingDriver; - -/** - * Contract for metadata drivers. - * - * @since 2.0 - * @author Jonathan H. Wage - * @todo Rename: MetadataDriver or MappingDriver - */ -interface Driver extends MappingDriver -{ -} \ No newline at end of file diff --git a/lib/Doctrine/ORM/Mapping/Driver/StaticPHPDriver.php b/lib/Doctrine/ORM/Mapping/Driver/StaticPHPDriver.php index 4430d4c7f..64177bace 100644 --- a/lib/Doctrine/ORM/Mapping/Driver/StaticPHPDriver.php +++ b/lib/Doctrine/ORM/Mapping/Driver/StaticPHPDriver.php @@ -20,7 +20,8 @@ namespace Doctrine\ORM\Mapping\Driver; use Doctrine\Common\Persistence\Mapping\ClassMetadata, - Doctrine\ORM\Mapping\MappingException; + Doctrine\Common\Persistence\Mapping\Driver\MappingDriver, + Doctrine\ORM\Mapping\MappingException; /** * The StaticPHPDriver calls a static loadMetadata() method on your entity @@ -34,7 +35,7 @@ use Doctrine\Common\Persistence\Mapping\ClassMetadata, * @author Jonathan H. Wage * @author Roman Borschel */ -class StaticPHPDriver implements Driver +class StaticPHPDriver implements MappingDriver { /** * Paths of entity directories. From 245718c9ebf3173b41e3540a946b171ccaa06745 Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Tue, 17 Jan 2012 18:33:50 +0100 Subject: [PATCH 12/22] Removing AbstractFileDriver, using Doctrine\Common\Persistence\Mapping\Driver\FileDriver instead --- .../ORM/Mapping/Driver/AbstractFileDriver.php | 42 ------------------- lib/Doctrine/ORM/Mapping/Driver/PHPDriver.php | 4 +- lib/Doctrine/ORM/Mapping/Driver/XmlDriver.php | 3 +- .../ORM/Mapping/Driver/YamlDriver.php | 3 +- .../Command/SchemaTool/AbstractCommand.php | 8 +--- 5 files changed, 8 insertions(+), 52 deletions(-) delete mode 100644 lib/Doctrine/ORM/Mapping/Driver/AbstractFileDriver.php diff --git a/lib/Doctrine/ORM/Mapping/Driver/AbstractFileDriver.php b/lib/Doctrine/ORM/Mapping/Driver/AbstractFileDriver.php deleted file mode 100644 index 8f1e676e1..000000000 --- a/lib/Doctrine/ORM/Mapping/Driver/AbstractFileDriver.php +++ /dev/null @@ -1,42 +0,0 @@ -. - */ - -namespace Doctrine\ORM\Mapping\Driver; - -use Doctrine\Common\Persistence\Mapping\Driver\FileDriver; - -/** - * Base driver for file-based metadata drivers. - * - * A file driver operates in a mode where it loads the mapping files of individual - * classes on demand. This requires the user to adhere to the convention of 1 mapping - * file per class and the file names of the mapping files must correspond to the full - * class name, including namespace, with the namespace delimiters '\', replaced by dots '.'. - * - * @license http://www.opensource.org/licenses/lgpl-license.php LGPL - * @link www.doctrine-project.com - * @since 2.0 - * @author Benjamin Eberlei - * @author Guilherme Blanco - * @author Jonathan H. Wage - * @author Roman Borschel - */ -abstract class AbstractFileDriver extends FileDriver -{ -} \ 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 1071083cf..186ca8fef 100644 --- a/lib/Doctrine/ORM/Mapping/Driver/PHPDriver.php +++ b/lib/Doctrine/ORM/Mapping/Driver/PHPDriver.php @@ -20,7 +20,7 @@ namespace Doctrine\ORM\Mapping\Driver; use Doctrine\Common\Persistence\Mapping\ClassMetadata, - Doctrine\ORM\Mapping\Driver\AbstractFileDriver; + Doctrine\Common\Persistence\Mapping\Driver\FileDriver; /** * The PHPDriver includes php files which just populate ClassMetadata @@ -36,7 +36,7 @@ use Doctrine\Common\Persistence\Mapping\ClassMetadata, * @author Roman Borschel * @todo Rename: PHPDriver */ -class PHPDriver extends AbstractFileDriver +class PHPDriver extends FileDriver { const DEFAULT_FILE_EXTENSION = '.php'; diff --git a/lib/Doctrine/ORM/Mapping/Driver/XmlDriver.php b/lib/Doctrine/ORM/Mapping/Driver/XmlDriver.php index 3ab7a08f2..1969692fe 100644 --- a/lib/Doctrine/ORM/Mapping/Driver/XmlDriver.php +++ b/lib/Doctrine/ORM/Mapping/Driver/XmlDriver.php @@ -20,6 +20,7 @@ namespace Doctrine\ORM\Mapping\Driver; use SimpleXMLElement, + Doctrine\Common\Persistence\Mapping\Driver\FileDriver, Doctrine\Common\Persistence\Mapping\ClassMetadata, Doctrine\ORM\Mapping\MappingException; @@ -34,7 +35,7 @@ use SimpleXMLElement, * @author Jonathan H. Wage * @author Roman Borschel */ -class XmlDriver extends AbstractFileDriver +class XmlDriver extends FileDriver { const DEFAULT_FILE_EXTENSION = '.dcm.xml'; diff --git a/lib/Doctrine/ORM/Mapping/Driver/YamlDriver.php b/lib/Doctrine/ORM/Mapping/Driver/YamlDriver.php index d74505150..051ea5612 100644 --- a/lib/Doctrine/ORM/Mapping/Driver/YamlDriver.php +++ b/lib/Doctrine/ORM/Mapping/Driver/YamlDriver.php @@ -20,6 +20,7 @@ namespace Doctrine\ORM\Mapping\Driver; use Doctrine\Common\Persistence\Mapping\ClassMetadata, + Doctrine\Common\Persistence\Mapping\Driver\FileDriver, Doctrine\ORM\Mapping\MappingException, Symfony\Component\Yaml\Yaml; @@ -32,7 +33,7 @@ use Doctrine\Common\Persistence\Mapping\ClassMetadata, * @author Jonathan H. Wage * @author Roman Borschel */ -class YamlDriver extends AbstractFileDriver +class YamlDriver extends FileDriver { const DEFAULT_FILE_EXTENSION = '.dcm.yml'; diff --git a/lib/Doctrine/ORM/Tools/Console/Command/SchemaTool/AbstractCommand.php b/lib/Doctrine/ORM/Tools/Console/Command/SchemaTool/AbstractCommand.php index 2add41a2a..a87eb2004 100644 --- a/lib/Doctrine/ORM/Tools/Console/Command/SchemaTool/AbstractCommand.php +++ b/lib/Doctrine/ORM/Tools/Console/Command/SchemaTool/AbstractCommand.php @@ -19,14 +19,10 @@ namespace Doctrine\ORM\Tools\Console\Command\SchemaTool; -use Symfony\Component\Console\Input\InputArgument, - Symfony\Component\Console\Input\InputOption, - Symfony\Component\Console\Input\InputInterface, +use Symfony\Component\Console\Input\InputInterface, Symfony\Component\Console\Output\OutputInterface, Symfony\Component\Console\Command\Command, - Doctrine\ORM\Tools\Console\Helper\EntityManagerHelper, - Doctrine\ORM\Tools\SchemaTool, - Doctrine\ORM\Mapping\Driver\AbstractFileDriver; + Doctrine\ORM\Tools\SchemaTool; abstract class AbstractCommand extends Command { From 5c05a4356a9418d0ec9bb45bccd2a9844ba6d84e Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Tue, 17 Jan 2012 18:49:42 +0100 Subject: [PATCH 13/22] Adding notes about upgrading to 2.3 (metadata drivers changes) --- UPGRADE_TO_2_3 | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/UPGRADE_TO_2_3 b/UPGRADE_TO_2_3 index 39b0d1f9d..10e8a41f4 100644 --- a/UPGRADE_TO_2_3 +++ b/UPGRADE_TO_2_3 @@ -30,3 +30,11 @@ Also, related functions were affected: Internal changes were made to DQL and SQL generation. If you have implemented your own TreeWalker, you probably need to update it. The method walkJoinVariableDeclaration is now named walkJoin. + +# Metadata Drivers + +Metadata drivers have been rewritten to reuse code from Doctrine\Common. +Anyone who is using the `Doctrine\ORM\Mapping\Driver\Driver` interface +explicitly should instead refer to `Doctrine\Common\Persistence\Mapping\Driver\MappingDriver`. +Same applies to `Doctrine\ORM\Mapping\Driver\AbstractFileDriver`: you should now refer to +`Doctrine\Common\Persistence\Mapping\Driver\FileDriver`. \ No newline at end of file From 01b1b0b5fbe2ada58feba958e4ca58de83e206c1 Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Wed, 18 Jan 2012 00:04:25 +0100 Subject: [PATCH 14/22] Removing code from the simplified drivers, use SymfonyFileLocator instead --- .../Mapping/Driver/SimplifiedXmlDriver.php | 145 +---------------- .../Mapping/Driver/SimplifiedYamlDriver.php | 150 +----------------- .../Mapping/Symfony/AbstractDriverTest.php | 12 +- 3 files changed, 12 insertions(+), 295 deletions(-) diff --git a/lib/Doctrine/ORM/Mapping/Driver/SimplifiedXmlDriver.php b/lib/Doctrine/ORM/Mapping/Driver/SimplifiedXmlDriver.php index 1f47ca609..ab28d9fce 100644 --- a/lib/Doctrine/ORM/Mapping/Driver/SimplifiedXmlDriver.php +++ b/lib/Doctrine/ORM/Mapping/Driver/SimplifiedXmlDriver.php @@ -19,7 +19,7 @@ namespace Doctrine\ORM\Mapping\Driver; -use Doctrine\ORM\Mapping\MappingException; +use Doctrine\Common\Persistence\Mapping\Driver\SymfonyFileLocator; /** * XmlDriver that additionally looks for mapping information in a global file. @@ -32,151 +32,12 @@ class SimplifiedXmlDriver extends XmlDriver { const DEFAULT_FILE_EXTENSION = '.orm.xml'; - protected $_prefixes = array(); - protected $_globalBasename; - protected $_classCache; - protected $_fileExtension = '.orm.xml'; - /** * {@inheritdoc} */ public function __construct($prefixes, $fileExtension = self::DEFAULT_FILE_EXTENSION) { - parent::__construct(array(), $fileExtension); - $this->addNamespacePrefixes($prefixes); - } - - public function setGlobalBasename($file) - { - $this->_globalBasename = $file; - } - - public function getGlobalBasename() - { - return $this->_globalBasename; - } - - public function addNamespacePrefixes($prefixes) - { - $this->_prefixes = array_merge($this->_prefixes, $prefixes); - $this->locator->addPaths(array_flip($prefixes)); - } - - public function getNamespacePrefixes() - { - return $this->_prefixes; - } - - public function isTransient($className) - { - if (null === $this->_classCache) { - $this->initialize(); - } - - // The mapping is defined in the global mapping file - if (isset($this->_classCache[$className])) { - return false; - } - - try { - $this->findMappingFile($className); - - return false; - } catch (MappingException $e) { - return true; - } - } - - public function getAllClassNames() - { - if (null === $this->_classCache) { - $this->initialize(); - } - - $classes = array(); - - if ($this->locator->getPaths()) { - foreach ($this->locator->getPaths() as $path) { - if (!is_dir($path)) { - throw MappingException::fileMappingDriversRequireConfiguredDirectoryPath($path); - } - - $iterator = new \RecursiveIteratorIterator( - new \RecursiveDirectoryIterator($path), - \RecursiveIteratorIterator::LEAVES_ONLY - ); - - foreach ($iterator as $file) { - $fileName = $file->getBasename($this->_fileExtension); - - if ($fileName == $file->getBasename() || $fileName == $this->_globalBasename) { - continue; - } - - // NOTE: All files found here means classes are not transient! - if (isset($this->_prefixes[$path])) { - $classes[] = $this->_prefixes[$path].'\\'.str_replace('.', '\\', $fileName); - } else { - $classes[] = str_replace('.', '\\', $fileName); - } - } - } - } - - return array_merge($classes, array_keys($this->_classCache)); - } - - public function getElement($className) - { - if (null === $this->_classCache) { - $this->initialize(); - } - - if (!isset($this->_classCache[$className])) { - $this->_classCache[$className] = parent::getElement($className); - } - - return $this->_classCache[$className]; - } - - protected function initialize() - { - $this->_classCache = array(); - if (null !== $this->_globalBasename) { - foreach ($this->locator->getPaths() as $path) { - if (is_file($file = $path.'/'.$this->_globalBasename.$this->_fileExtension)) { - $this->_classCache = array_merge($this->_classCache, $this->loadMappingFile($file)); - } - } - } - } - - protected function findMappingFile($className) - { - $defaultFileName = str_replace('\\', '.', $className).$this->_fileExtension; - foreach ($this->locator->getPaths() as $path) { - if (!isset($this->_prefixes[$path])) { - if (is_file($path.DIRECTORY_SEPARATOR.$defaultFileName)) { - return $path.DIRECTORY_SEPARATOR.$defaultFileName; - } - - continue; - } - - $prefix = $this->_prefixes[$path]; - - if (0 !== strpos($className, $prefix.'\\')) { - continue; - } - - $filename = $path.'/'.strtr(substr($className, strlen($prefix)+1), '\\', '.').$this->_fileExtension; - if (is_file($filename)) { - return $filename; - } - - throw MappingException::mappingFileNotFound($className, $filename); - } - - throw MappingException::mappingFileNotFound($className, substr($className, strrpos($className, '\\') + 1).$this->_fileExtension); + $locator = new SymfonyFileLocator((array) $prefixes, $fileExtension); + parent::__construct($locator, $fileExtension); } } diff --git a/lib/Doctrine/ORM/Mapping/Driver/SimplifiedYamlDriver.php b/lib/Doctrine/ORM/Mapping/Driver/SimplifiedYamlDriver.php index cdd826413..7fc840de6 100644 --- a/lib/Doctrine/ORM/Mapping/Driver/SimplifiedYamlDriver.php +++ b/lib/Doctrine/ORM/Mapping/Driver/SimplifiedYamlDriver.php @@ -19,7 +19,7 @@ namespace Doctrine\ORM\Mapping\Driver; -use Doctrine\ORM\Mapping\MappingException; +use Doctrine\Common\Persistence\Mapping\Driver\SymfonyFileLocator; /** * YamlDriver that additionally looks for mapping information in a global file. @@ -32,156 +32,12 @@ class SimplifiedYamlDriver extends YamlDriver { const DEFAULT_FILE_EXTENSION = '.orm.yml'; - protected $_prefixes = array(); - protected $_globalBasename; - protected $_classCache; - protected $_fileExtension = '.orm.yml'; - /** * {@inheritdoc} */ public function __construct($prefixes, $fileExtension = self::DEFAULT_FILE_EXTENSION) { - parent::__construct(array(), $fileExtension); - $this->addNamespacePrefixes($prefixes); - } - - public function setGlobalBasename($file) - { - $this->_globalBasename = $file; - } - - public function getGlobalBasename() - { - return $this->_globalBasename; - } - - public function addNamespacePrefixes($prefixes) - { - $this->_prefixes = array_merge($this->_prefixes, $prefixes); - $this->locator->addPaths(array_flip($prefixes)); - } - - public function addNamespacePrefix($prefix, $path) - { - $this->_prefixes[$path] = $prefix; - } - - public function getNamespacePrefixes() - { - return $this->_prefixes; - } - - public function isTransient($className) - { - if (null === $this->_classCache) { - $this->initialize(); - } - - // The mapping is defined in the global mapping file - if (isset($this->_classCache[$className])) { - return false; - } - - try { - $this->findMappingFile($className); - - return false; - } catch (MappingException $e) { - return true; - } - } - - public function getAllClassNames() - { - if (null === $this->_classCache) { - $this->initialize(); - } - - $classes = array(); - - if ($this->locator->getPaths()) { - foreach ($this->locator->getPaths() as $path) { - if (!is_dir($path)) { - throw MappingException::fileMappingDriversRequireConfiguredDirectoryPath($path); - } - - $iterator = new \RecursiveIteratorIterator( - new \RecursiveDirectoryIterator($path), - \RecursiveIteratorIterator::LEAVES_ONLY - ); - - foreach ($iterator as $file) { - $fileName = $file->getBasename($this->_fileExtension); - - if ($fileName == $file->getBasename() || $fileName == $this->_globalBasename) { - continue; - } - - // NOTE: All files found here means classes are not transient! - if (isset($this->_prefixes[$path])) { - $classes[] = $this->_prefixes[$path].'\\'.str_replace('.', '\\', $fileName); - } else { - $classes[] = str_replace('.', '\\', $fileName); - } - } - } - } - - return array_merge($classes, array_keys($this->_classCache)); - } - - public function getElement($className) - { - if (null === $this->_classCache) { - $this->initialize(); - } - - if (!isset($this->_classCache[$className])) { - $this->_classCache[$className] = parent::getElement($className); - } - - return $this->_classCache[$className]; - } - - protected function initialize() - { - $this->_classCache = array(); - if (null !== $this->_globalBasename) { - foreach ($this->locator->getPaths() as $path) { - if (is_file($file = $path.'/'.$this->_globalBasename.$this->_fileExtension)) { - $this->_classCache = array_merge($this->_classCache, $this->loadMappingFile($file)); - } - } - } - } - - protected function findMappingFile($className) - { - $defaultFileName = str_replace('\\', '.', $className).$this->_fileExtension; - foreach ($this->locator->getPaths() as $path) { - if (!isset($this->_prefixes[$path])) { - if (is_file($path.DIRECTORY_SEPARATOR.$defaultFileName)) { - return $path.DIRECTORY_SEPARATOR.$defaultFileName; - } - - continue; - } - - $prefix = $this->_prefixes[$path]; - - if (0 !== strpos($className, $prefix.'\\')) { - continue; - } - - $filename = $path.'/'.strtr(substr($className, strlen($prefix)+1), '\\', '.').$this->_fileExtension; - if (is_file($filename)) { - return $filename; - } - - throw MappingException::mappingFileNotFound($className, $filename); - } - - throw MappingException::mappingFileNotFound($className, substr($className, strrpos($className, '\\') + 1).$this->_fileExtension); + $locator = new SymfonyFileLocator((array) $prefixes, $fileExtension); + parent::__construct($locator, $fileExtension); } } diff --git a/tests/Doctrine/Tests/ORM/Mapping/Symfony/AbstractDriverTest.php b/tests/Doctrine/Tests/ORM/Mapping/Symfony/AbstractDriverTest.php index 7315b57b2..405260185 100644 --- a/tests/Doctrine/Tests/ORM/Mapping/Symfony/AbstractDriverTest.php +++ b/tests/Doctrine/Tests/ORM/Mapping/Symfony/AbstractDriverTest.php @@ -32,7 +32,7 @@ abstract class AbstractDriverTest extends \PHPUnit_Framework_TestCase )); touch($filename = $this->dir.'/Foo'.$this->getFileExtension()); - $this->assertEquals($filename, $this->invoke($driver, 'findMappingFile', array('MyNamespace\MySubnamespace\Entity\Foo'))); + $this->assertEquals($filename, $driver->getLocator()->findMappingFile('MyNamespace\MySubnamespace\Entity\Foo')); } public function testFindMappingFileInSubnamespace() @@ -42,13 +42,13 @@ abstract class AbstractDriverTest extends \PHPUnit_Framework_TestCase )); touch($filename = $this->dir.'/Foo.Bar'.$this->getFileExtension()); - $this->assertEquals($filename, $this->invoke($driver, 'findMappingFile', array('MyNamespace\MySubnamespace\Entity\Foo\Bar'))); + $this->assertEquals($filename, $driver->getLocator()->findMappingFile('MyNamespace\MySubnamespace\Entity\Foo\Bar')); } public function testFindMappingFileNamespacedFoundFileNotFound() { $this->setExpectedException( - 'Doctrine\ORM\Mapping\MappingException', + 'Doctrine\Common\Persistence\Mapping\MappingException', "No mapping file found named '".$this->dir."/Foo".$this->getFileExtension()."' for class 'MyNamespace\MySubnamespace\Entity\Foo'." ); @@ -56,13 +56,13 @@ abstract class AbstractDriverTest extends \PHPUnit_Framework_TestCase 'MyNamespace\MySubnamespace\Entity' => $this->dir, )); - $this->invoke($driver, 'findMappingFile', array('MyNamespace\MySubnamespace\Entity\Foo')); + $driver->getLocator()->findMappingFile('MyNamespace\MySubnamespace\Entity\Foo'); } public function testFindMappingNamespaceNotFound() { $this->setExpectedException( - 'Doctrine\ORM\Mapping\MappingException', + 'Doctrine\Common\Persistence\Mapping\MappingException', "No mapping file found named 'Foo".$this->getFileExtension()."' for class 'MyOtherNamespace\MySubnamespace\Entity\Foo'." ); @@ -70,7 +70,7 @@ abstract class AbstractDriverTest extends \PHPUnit_Framework_TestCase 'MyNamespace\MySubnamespace\Entity' => $this->dir, )); - $this->invoke($driver, 'findMappingFile', array('MyOtherNamespace\MySubnamespace\Entity\Foo')); + $driver->getLocator()->findMappingFile('MyOtherNamespace\MySubnamespace\Entity\Foo'); } protected function setUp() From 737b74e5d534eb9ee9e5d0993644ba3dce728ede Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Wed, 18 Jan 2012 00:04:25 +0100 Subject: [PATCH 15/22] Rebasing on master --- UPGRADE_TO_2_3 | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/UPGRADE_TO_2_3 b/UPGRADE_TO_2_3 index 10e8a41f4..fa6379393 100644 --- a/UPGRADE_TO_2_3 +++ b/UPGRADE_TO_2_3 @@ -33,8 +33,8 @@ you probably need to update it. The method walkJoinVariableDeclaration is now na # Metadata Drivers -Metadata drivers have been rewritten to reuse code from Doctrine\Common. -Anyone who is using the `Doctrine\ORM\Mapping\Driver\Driver` interface -explicitly should instead refer to `Doctrine\Common\Persistence\Mapping\Driver\MappingDriver`. -Same applies to `Doctrine\ORM\Mapping\Driver\AbstractFileDriver`: you should now refer to +Metadata drivers have been rewritten to reuse code from Doctrine\Common. Anyone who is using the +`Doctrine\ORM\Mapping\Driver\Driver` interface should instead refer to +`Doctrine\Common\Persistence\Mapping\Driver\MappingDriver`. Same applies to +`Doctrine\ORM\Mapping\Driver\AbstractFileDriver`: you should now refer to `Doctrine\Common\Persistence\Mapping\Driver\FileDriver`. \ No newline at end of file From 63fbf7c2e5e9f6ba026b2ecfbaba999e5674da35 Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Fri, 30 Mar 2012 19:56:05 +0200 Subject: [PATCH 16/22] Fixing broken tests because of wrong method signature and reference to the old Driver interface --- lib/Doctrine/ORM/Mapping/Driver/DriverChain.php | 4 ++-- tests/Doctrine/Tests/ORM/Mapping/DriverChainTest.php | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/Doctrine/ORM/Mapping/Driver/DriverChain.php b/lib/Doctrine/ORM/Mapping/Driver/DriverChain.php index 267e9d534..bdeb97b9d 100644 --- a/lib/Doctrine/ORM/Mapping/Driver/DriverChain.php +++ b/lib/Doctrine/ORM/Mapping/Driver/DriverChain.php @@ -61,9 +61,9 @@ class DriverChain implements MappingDriver /** * Set the default driver. * - * @param Driver $driver + * @param MappingDriver $driver */ - public function setDefaultDriver(Driver $driver) + public function setDefaultDriver(MappingDriver $driver) { $this->defaultDriver = $driver; } diff --git a/tests/Doctrine/Tests/ORM/Mapping/DriverChainTest.php b/tests/Doctrine/Tests/ORM/Mapping/DriverChainTest.php index f5fd60a60..76ca9d29f 100644 --- a/tests/Doctrine/Tests/ORM/Mapping/DriverChainTest.php +++ b/tests/Doctrine/Tests/ORM/Mapping/DriverChainTest.php @@ -93,8 +93,8 @@ class DriverChainTest extends \Doctrine\Tests\OrmTestCase */ public function testDefaultDriver() { - $companyDriver = $this->getMock('Doctrine\ORM\Mapping\Driver\Driver'); - $dafaultDriver = $this->getMock('Doctrine\ORM\Mapping\Driver\Driver'); + $companyDriver = $this->getMock('Doctrine\Common\Persistence\Mapping\Driver\MappingDriver'); + $dafaultDriver = $this->getMock('Doctrine\Common\Persistence\Mapping\Driver\MappingDriver'); $entityClassName = 'Doctrine\Tests\ORM\Mapping\DriverChainEntity'; $managerClassName = 'Doctrine\Tests\Models\Company\CompanyManager'; $chain = new DriverChain(); From 943cff673a90d72f9c7b0567ed24638d9c874571 Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Sat, 7 Apr 2012 19:34:04 +0200 Subject: [PATCH 17/22] Fixing test expecting a ORM\Mapping exception Those exceptions are now in the Common\Persistence\Mapping namespace --- tests/Doctrine/Tests/ORM/Mapping/XmlMappingDriverTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/Doctrine/Tests/ORM/Mapping/XmlMappingDriverTest.php b/tests/Doctrine/Tests/ORM/Mapping/XmlMappingDriverTest.php index 83e524a65..e69f23a35 100644 --- a/tests/Doctrine/Tests/ORM/Mapping/XmlMappingDriverTest.php +++ b/tests/Doctrine/Tests/ORM/Mapping/XmlMappingDriverTest.php @@ -87,7 +87,7 @@ class XmlMappingDriverTest extends AbstractMappingDriverTest /** * @group DDC-889 - * @expectedException Doctrine\ORM\Mapping\MappingException + * @expectedException Doctrine\Common\Persistence\Mapping\MappingException * @expectedExceptionMessage Invalid mapping file 'Doctrine.Tests.Models.DDC889.DDC889Class.dcm.xml' for class 'Doctrine\Tests\Models\DDC889\DDC889Class'. */ public function testinvalidEntityOrMappedSuperClassShouldMentionParentClasses() From e522391ee95d282457495ad7c6cfdfa11338de2b Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Sat, 7 Apr 2012 21:20:17 +0200 Subject: [PATCH 18/22] Reusing Doctrine\Common's AbstractClassMetadataFactory --- .../ORM/Mapping/ClassMetadataFactory.php | 293 +++--------------- 1 file changed, 44 insertions(+), 249 deletions(-) diff --git a/lib/Doctrine/ORM/Mapping/ClassMetadataFactory.php b/lib/Doctrine/ORM/Mapping/ClassMetadataFactory.php index 6f8ee80b2..713024e9c 100644 --- a/lib/Doctrine/ORM/Mapping/ClassMetadataFactory.php +++ b/lib/Doctrine/ORM/Mapping/ClassMetadataFactory.php @@ -24,10 +24,9 @@ use ReflectionException, Doctrine\ORM\EntityManager, Doctrine\DBAL\Platforms, Doctrine\ORM\Events, - Doctrine\Common\Util\ClassUtils, - Doctrine\Common\Persistence\Mapping\RuntimeReflectionService, Doctrine\Common\Persistence\Mapping\ReflectionService, - Doctrine\Common\Persistence\Mapping\ClassMetadataFactory as ClassMetadataFactoryInterface; + Doctrine\Common\Persistence\Mapping\ClassMetadata as ClassMetadataInterface, + Doctrine\Common\Persistence\Mapping\AbstractClassMetadataFactory; /** * The ClassMetadataFactory is used to create ClassMetadata objects that contain all the @@ -40,7 +39,7 @@ use ReflectionException, * @author Jonathan Wage * @author Roman Borschel */ -class ClassMetadataFactory implements ClassMetadataFactoryInterface +class ClassMetadataFactory extends AbstractClassMetadataFactory { /** * @var EntityManager @@ -62,26 +61,6 @@ class ClassMetadataFactory implements ClassMetadataFactoryInterface */ private $evm; - /** - * @var \Doctrine\Common\Cache\Cache - */ - private $cacheDriver; - - /** - * @var array - */ - private $loadedMetadata = array(); - - /** - * @var bool - */ - private $initialized = false; - - /** - * @var ReflectionService - */ - private $reflectionService; - /** * @param EntityManager $$em */ @@ -91,55 +70,9 @@ class ClassMetadataFactory implements ClassMetadataFactoryInterface } /** - * Sets the cache driver used by the factory to cache ClassMetadata instances. - * - * @param \Doctrine\Common\Cache\Cache $cacheDriver + * {@inheritDoc}. */ - public function setCacheDriver($cacheDriver) - { - $this->cacheDriver = $cacheDriver; - } - - /** - * Gets the cache driver used by the factory to cache ClassMetadata instances. - * - * @return \Doctrine\Common\Cache\Cache - */ - public function getCacheDriver() - { - return $this->cacheDriver; - } - - public function getLoadedMetadata() - { - return $this->loadedMetadata; - } - - /** - * Forces the factory to load the metadata of all classes known to the underlying - * mapping driver. - * - * @return array The ClassMetadata instances of all mapped classes. - */ - public function getAllMetadata() - { - if ( ! $this->initialized) { - $this->initialize(); - } - - $metadata = array(); - foreach ($this->driver->getAllClassNames() as $className) { - $metadata[] = $this->getMetadataFor($className); - } - - return $metadata; - } - - /** - * Lazy initialization of this stuff, especially the metadata driver, - * since these are not needed at all when a metadata cache is active. - */ - private function initialize() + protected function initialize() { $this->driver = $this->em->getConfiguration()->getMetadataDriverImpl(); $this->targetPlatform = $this->em->getConnection()->getDatabasePlatform(); @@ -148,104 +81,8 @@ class ClassMetadataFactory implements ClassMetadataFactoryInterface } /** - * Gets the class metadata descriptor for a class. - * - * @param string $className The name of the class. - * @return \Doctrine\ORM\Mapping\ClassMetadata - */ - public function getMetadataFor($className) - { - if (isset($this->loadedMetadata[$className])) { - return $this->loadedMetadata[$className]; - } + * {@inheritDoc} - $realClassName = $className; - - // Check for namespace alias - if (strpos($className, ':') !== false) { - list($namespaceAlias, $simpleClassName) = explode(':', $className); - $realClassName = $this->em->getConfiguration()->getEntityNamespace($namespaceAlias) . '\\' . $simpleClassName; - } else { - $realClassName = ClassUtils::getRealClass($realClassName); - } - - if (isset($this->loadedMetadata[$realClassName])) { - // We do not have the alias name in the map, include it - $this->loadedMetadata[$className] = $this->loadedMetadata[$realClassName]; - return $this->loadedMetadata[$realClassName]; - } - - if ($this->cacheDriver) { - if (($cached = $this->cacheDriver->fetch("$realClassName\$CLASSMETADATA")) !== false) { - $this->wakeupReflection($cached, $this->getReflectionService()); - $this->loadedMetadata[$realClassName] = $cached; - } else { - foreach ($this->loadMetadata($realClassName) as $loadedClassName) { - $this->cacheDriver->save( - "$loadedClassName\$CLASSMETADATA", $this->loadedMetadata[$loadedClassName], null - ); - } - } - } else { - $this->loadMetadata($realClassName); - } - - if ($className != $realClassName) { - // We do not have the alias name in the map, include it - $this->loadedMetadata[$className] = $this->loadedMetadata[$realClassName]; - } - - return $this->loadedMetadata[$className]; - } - - /** - * Checks whether the factory has the metadata for a class loaded already. - * - * @param string $className - * @return boolean TRUE if the metadata of the class in question is already loaded, FALSE otherwise. - */ - public function hasMetadataFor($className) - { - return isset($this->loadedMetadata[$className]); - } - - /** - * Sets the metadata descriptor for a specific class. - * - * NOTE: This is only useful in very special cases, like when generating proxy classes. - * - * @param string $className - * @param ClassMetadata $class - */ - public function setMetadataFor($className, $class) - { - $this->loadedMetadata[$className] = $class; - } - - /** - * Get array of parent classes for the given entity class - * - * @param string $name - * @return array $parentClasses - */ - protected function getParentClasses($name) - { - // Collect parent classes, ignoring transient (not-mapped) classes. - $parentClasses = array(); - foreach (array_reverse($this->getReflectionService()->getParentClasses($name)) as $parentClass) { - if ( ! $this->driver->isTransient($parentClass)) { - $parentClasses[] = $parentClass; - } - } - return $parentClasses; - } - - /** - * Loads the metadata of the class in question and all it's ancestors whose metadata - * is still not loaded. - * - * @param string $name The name of the class for which the metadata should get loaded. - * @param array $tables The metadata collection to which the loaded metadata is added. */ protected function loadMetadata($name) { @@ -263,8 +100,8 @@ class ClassMetadataFactory implements ClassMetadataFactoryInterface $rootEntityFound = false; $visited = array(); foreach ($parentClasses as $className) { - if (isset($this->loadedMetadata[$className])) { - $parent = $this->loadedMetadata[$className]; + if ($this->hasMetadataFor($className)) { + $parent = $this->getMetadataFor($className); if ( ! $parent->isMappedSuperclass) { $rootEntityFound = true; array_unshift($visited, $className); @@ -352,7 +189,7 @@ class ClassMetadataFactory implements ClassMetadataFactoryInterface $this->validateRuntimeMetadata($class, $parent); - $this->loadedMetadata[$className] = $class; + $this->setMetadataFor($className, $class); $parent = $class; @@ -404,10 +241,7 @@ class ClassMetadataFactory implements ClassMetadataFactoryInterface } /** - * Creates a new ClassMetadata instance for the given class name. - * - * @param string $className - * @return \Doctrine\ORM\Mapping\ClassMetadata + * {@inheritDoc} */ protected function newClassMetadataInstance($className) { @@ -469,40 +303,6 @@ class ClassMetadataFactory implements ClassMetadataFactoryInterface return strtolower(end($parts)); } - /** - * Cache the metadata - * - * @param $className - * @param \Doctrine\ORM\Mapping\ClassMetadata $metadata - */ - private function cacheMetadata($className, ClassMetadata $metadata) - { - $this->cacheDriver->save( - "$className\$CLASSMETADATA", $metadata, null - ); - } - - /** - * Verify if metadata is cached - * - * @param $className - * @return bool - */ - private function cacheContainsMetadata($className) - { - return $this->cacheDriver->contains("$className\$CLASSMETADATA"); - } - - /** - * Fetch metadata from cache - * - * @param $className - */ - private function fetchMetadataFromCache($className) - { - return $this->cacheDriver->fetch("$className\$CLASSMETADATA"); - } - /** * Adds inherited fields to the subclass mapping. * @@ -725,10 +525,9 @@ class ClassMetadataFactory implements ClassMetadataFactoryInterface } /** - * Check if this class is mapped by this EntityManager + ClassMetadata configuration + * {@inheritDoc} * - * @param $class - * @return bool + * @todo remove after doctrine/common#138 is merged */ public function isTransient($class) { @@ -739,56 +538,52 @@ class ClassMetadataFactory implements ClassMetadataFactoryInterface // Check for namespace alias if (strpos($class, ':') !== false) { list($namespaceAlias, $simpleClassName) = explode(':', $class); - $class = $this->em->getConfiguration()->getEntityNamespace($namespaceAlias) . '\\' . $simpleClassName; + $class = $this->getFqcnFromAlias($namespaceAlias, $simpleClassName); } return $this->driver->isTransient($class); } /** - * Get reflectionService. - * - * @return \Doctrine\Common\Persistence\Mapping\ReflectionService + * {@inheritDoc} */ - public function getReflectionService() - { - if ($this->reflectionService === null) { - $this->reflectionService = new RuntimeReflectionService(); - } - return $this->reflectionService; - } - - /** - * Set reflectionService. - * - * @param reflectionService the value to set. - */ - public function setReflectionService(ReflectionService $reflectionService) - { - $this->reflectionService = $reflectionService; - } - - /** - * Wakeup reflection after ClassMetadata gets unserialized from cache. - * - * @param ClassMetadataInfo $class - * @param ReflectionService $reflService - * @return void - */ - protected function wakeupReflection(ClassMetadataInfo $class, ReflectionService $reflService) + protected function wakeupReflection(ClassMetadataInterface $class, ReflectionService $reflService) { $class->wakeupReflection($reflService); } /** - * Initialize Reflection after ClassMetadata was constructed. - * - * @param ClassMetadataInfo $class - * @param ReflectionService $reflService - * @return void + * {@inheritDoc} */ - protected function initializeReflection(ClassMetadataInfo $class, ReflectionService $reflService) + protected function initializeReflection(ClassMetadataInterface $class, ReflectionService $reflService) { $class->initializeReflection($reflService); } + + /** + * {@inheritDoc} + */ + protected function getFqcnFromAlias($namespaceAlias, $simpleClassName) + { + return $this->em->getConfiguration()->getEntityNamespace($namespaceAlias) . '\\' . $simpleClassName; + } + + /** + * {@inheritDoc} + */ + protected function getDriver() + { + return $this->driver; + } + + /** + * {@inheritDoc} + */ + protected function doLoadMetadata($class, $parent, $rootEntityFound) + { + throw new \LogicException( + 'Not implemented because Doctrine\Common\Persistence\Mapping\AbstractClassMetadataFactory ' + . 'behavior differs in how Doctrine\ORM\Mapping\MetadataFactory works' + ); + } } From 94714db132a0384fff278db82876c806feec5c8e Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Sat, 9 Jun 2012 15:17:45 +0200 Subject: [PATCH 19/22] Fixing code sniff issues before continuing refactoring of --- lib/Doctrine/ORM/Mapping/ClassMetadata.php | 2 - .../ORM/Mapping/ClassMetadataFactory.php | 41 ++++--- .../ORM/Mapping/ClassMetadataInfo.php | 115 ++++++++++++------ .../ORM/Mapping/Driver/DatabaseDriver.php | 13 +- .../ORM/Mapping/Driver/DriverChain.php | 6 +- lib/Doctrine/ORM/Mapping/Driver/XmlDriver.php | 30 ++--- .../ORM/Mapping/Driver/YamlDriver.php | 8 +- 7 files changed, 135 insertions(+), 80 deletions(-) diff --git a/lib/Doctrine/ORM/Mapping/ClassMetadata.php b/lib/Doctrine/ORM/Mapping/ClassMetadata.php index 67a91fada..55e975cc5 100644 --- a/lib/Doctrine/ORM/Mapping/ClassMetadata.php +++ b/lib/Doctrine/ORM/Mapping/ClassMetadata.php @@ -19,8 +19,6 @@ namespace Doctrine\ORM\Mapping; -use ReflectionClass, ReflectionProperty; - /** * A ClassMetadata instance holds all the object-relational mapping metadata * of an entity and it's associations. diff --git a/lib/Doctrine/ORM/Mapping/ClassMetadataFactory.php b/lib/Doctrine/ORM/Mapping/ClassMetadataFactory.php index 713024e9c..0baccfe92 100644 --- a/lib/Doctrine/ORM/Mapping/ClassMetadataFactory.php +++ b/lib/Doctrine/ORM/Mapping/ClassMetadataFactory.php @@ -26,11 +26,12 @@ use ReflectionException, Doctrine\ORM\Events, Doctrine\Common\Persistence\Mapping\ReflectionService, Doctrine\Common\Persistence\Mapping\ClassMetadata as ClassMetadataInterface, - Doctrine\Common\Persistence\Mapping\AbstractClassMetadataFactory; + Doctrine\Common\Persistence\Mapping\AbstractClassMetadataFactory, + Doctrine\ORM\Id\IdentityGenerator; /** * The ClassMetadataFactory is used to create ClassMetadata objects that contain all the - * metadata mapping informations of a class which describes how a class should be mapped + * metadata mapping information of a class which describes how a class should be mapped * to a relational database. * * @since 2.0 @@ -47,7 +48,7 @@ class ClassMetadataFactory extends AbstractClassMetadataFactory private $em; /** - * @var AbstractPlatform + * @var \Doctrine\DBAL\Platforms\AbstractPlatform */ private $targetPlatform; @@ -62,7 +63,8 @@ class ClassMetadataFactory extends AbstractClassMetadataFactory private $evm; /** - * @param EntityManager $$em + * @param EntityManager $em + * @return void */ public function setEntityManager(EntityManager $em) { @@ -137,13 +139,13 @@ class ClassMetadataFactory extends AbstractClassMetadataFactory } // If this class has a parent the id generator strategy is inherited. - // However this is only true if the hierachy of parents contains the root entity, - // if it consinsts of mapped superclasses these don't necessarily include the id field. + // However this is only true if the hierarchy of parents contains the root entity, + // if it consists of mapped superclasses these don't necessarily include the id field. if ($parent && $rootEntityFound) { if ($parent->isIdGeneratorSequence()) { $class->setSequenceGeneratorDefinition($parent->sequenceGeneratorDefinition); } else if ($parent->isIdGeneratorTable()) { - $class->getTableGeneratorDefinition($parent->tableGeneratorDefinition); + $class->tableGeneratorDefinition = $parent->tableGeneratorDefinition; } if ($parent->generatorType) { $class->setIdGeneratorType($parent->generatorType); @@ -208,7 +210,9 @@ class ClassMetadataFactory extends AbstractClassMetadataFactory * Validate runtime metadata is correctly defined. * * @param ClassMetadata $class - * @param ClassMetadata $parent + * @param $parent + * @throws MappingException + * @return void */ protected function validateRuntimeMetadata($class, $parent) { @@ -231,11 +235,11 @@ class ClassMetadataFactory extends AbstractClassMetadataFactory throw MappingException::missingDiscriminatorColumn($class->name); } } else if ($parent && !$class->reflClass->isAbstract() && !in_array($class->name, array_values($class->discriminatorMap))) { - // enforce discriminator map for all entities of an inheritance hierachy, otherwise problems will occur. + // enforce discriminator map for all entities of an inheritance hierarchy, otherwise problems will occur. throw MappingException::mappedClassNotPartOfDiscriminatorMap($class->name, $class->rootEntityName); } } else if ($class->isMappedSuperclass && $class->name == $class->rootEntityName && (count($class->discriminatorMap) || $class->discriminatorColumn)) { - // second condition is necessary for mapped superclasses in the middle of an inheritance hierachy + // second condition is necessary for mapped superclasses in the middle of an inheritance hierarchy throw MappingException::noInheritanceOnMappedSuperClass($class->name); } } @@ -252,18 +256,19 @@ class ClassMetadataFactory extends AbstractClassMetadataFactory * Adds a default discriminator map if no one is given * * If an entity is of any inheritance type and does not contain a - * discrimiator map, then the map is generated automatically. This process + * discriminator map, then the map is generated automatically. This process * is expensive computation wise. * - * The automatically generated discriminator map contains the lowercase shortname of + * The automatically generated discriminator map contains the lowercase short name of * each class as key. * * @param \Doctrine\ORM\Mapping\ClassMetadata $class + * @throws MappingException + * @return void */ private function addDefaultDiscriminatorMap(ClassMetadata $class) { $allClasses = $this->driver->getAllClassNames(); - $subClassesMetadata = array(); $fqcn = $class->getName(); $map = array($this->getShortName($class->name) => $fqcn); @@ -288,7 +293,7 @@ class ClassMetadataFactory extends AbstractClassMetadataFactory } /** - * Get the lower-case shortname of a class. + * Get the lower-case short name of a class. * * @param string $className * @return string @@ -330,6 +335,8 @@ class ClassMetadataFactory extends AbstractClassMetadataFactory * * @param \Doctrine\ORM\Mapping\ClassMetadata $subClass * @param \Doctrine\ORM\Mapping\ClassMetadata $parentClass + * @throws MappingException + * @return void */ private function addInheritedRelations(ClassMetadata $subClass, ClassMetadata $parentClass) { @@ -427,7 +434,9 @@ class ClassMetadataFactory extends AbstractClassMetadataFactory * Completes the ID generator mapping. If "auto" is specified we choose the generator * most appropriate for the targeted database platform. * - * @param \Doctrine\ORM\Mapping\ClassMetadata $class + * @param ClassMetadataInfo $class + * @throws ORMException + * @return void */ private function completeIdGeneratorMapping(ClassMetadataInfo $class) { @@ -549,6 +558,7 @@ class ClassMetadataFactory extends AbstractClassMetadataFactory */ protected function wakeupReflection(ClassMetadataInterface $class, ReflectionService $reflService) { + /* @var $class ClassMetadata */ $class->wakeupReflection($reflService); } @@ -557,6 +567,7 @@ class ClassMetadataFactory extends AbstractClassMetadataFactory */ protected function initializeReflection(ClassMetadataInterface $class, ReflectionService $reflService) { + /* @var $class ClassMetadata */ $class->initializeReflection($reflService); } diff --git a/lib/Doctrine/ORM/Mapping/ClassMetadataInfo.php b/lib/Doctrine/ORM/Mapping/ClassMetadataInfo.php index 246a2c9f2..caee668d6 100644 --- a/lib/Doctrine/ORM/Mapping/ClassMetadataInfo.php +++ b/lib/Doctrine/ORM/Mapping/ClassMetadataInfo.php @@ -19,9 +19,13 @@ namespace Doctrine\ORM\Mapping; +use BadMethodCallException; +use InvalidArgumentException; +use RuntimeException; use Doctrine\DBAL\Types\Type; use ReflectionClass; use Doctrine\Common\Persistence\Mapping\ClassMetadata; +use Doctrine\Common\ClassLoader; /** * A ClassMetadata instance holds all the object-relational mapping metadata @@ -617,7 +621,7 @@ class ClassMetadataInfo implements ClassMetadata * Gets a ReflectionProperty for a specific field of the mapped class. * * @param string $name - * @return ReflectionProperty + * @return \ReflectionProperty */ public function getReflectionProperty($name) { @@ -627,13 +631,13 @@ class ClassMetadataInfo implements ClassMetadata /** * Gets the ReflectionProperty for the single identifier field. * - * @return ReflectionProperty + * @return \ReflectionProperty * @throws BadMethodCallException If the class has a composite identifier. */ public function getSingleIdReflectionProperty() { if ($this->isIdentifierComposite) { - throw new \BadMethodCallException("Class " . $this->name . " has a composite identifier."); + throw new BadMethodCallException("Class " . $this->name . " has a composite identifier."); } return $this->reflFields[$this->identifier[0]]; } @@ -831,7 +835,7 @@ class ClassMetadataInfo implements ClassMetadata /** * Restores some state that can not be serialized/unserialized. * - * @param ReflectionService $reflService + * @param \Doctrine\Common\Persistence\Mapping\ReflectionService $reflService * @return void */ public function wakeupReflection($reflService) @@ -856,7 +860,7 @@ class ClassMetadataInfo implements ClassMetadata * Initializes a new ClassMetadata instance that will hold the object-relational mapping * metadata of the class with the given name. * - * @param ReflectionService $reflService The reflection service. + * @param \Doctrine\Common\Persistence\Mapping\ReflectionService $reflService The reflection service. */ public function initializeReflection($reflService) { @@ -873,6 +877,7 @@ class ClassMetadataInfo implements ClassMetadata /** * Validate Identifier * + * @throws MappingException * @return void */ public function validateIdentifier() @@ -890,12 +895,13 @@ class ClassMetadataInfo implements ClassMetadata /** * Validate association targets actually exist. * + * @throws MappingException * @return void */ public function validateAssocations() { foreach ($this->associationMappings as $mapping) { - if ( ! \Doctrine\Common\ClassLoader::classExists($mapping['targetEntity']) ) { + if ( ! ClassLoader::classExists($mapping['targetEntity']) ) { throw MappingException::invalidTargetEntityClass($mapping['targetEntity'], $this->name, $mapping['fieldName']); } } @@ -904,12 +910,13 @@ class ClassMetadataInfo implements ClassMetadata /** * Validate lifecycle callbacks * - * @param ReflectionService $reflService + * @param \Doctrine\Common\Persistence\Mapping\ReflectionService $reflService + * @throws MappingException * @return void */ public function validateLifecycleCallbacks($reflService) { - foreach ($this->lifecycleCallbacks as $event => $callbacks) { + foreach ($this->lifecycleCallbacks as $callbacks) { foreach ($callbacks as $callbackFuncName) { if ( ! $reflService->hasPublicMethod($this->name, $callbackFuncName)) { throw MappingException::lifecycleCallbackMethodNotFound($this->name, $callbackFuncName); @@ -1032,7 +1039,8 @@ class ClassMetadataInfo implements ClassMetadata * reference to another object. * * @param string $fieldName The field name. - * @return array The field mapping. + * @throws MappingException + * @return array The field mapping. */ public function getFieldMapping($fieldName) { @@ -1048,6 +1056,7 @@ class ClassMetadataInfo implements ClassMetadata * @see ClassMetadataInfo::$associationMappings * @param string $fieldName The field name that represents the association in * the object model. + * @throws MappingException * @return array The mapping. */ public function getAssociationMapping($fieldName) @@ -1165,7 +1174,8 @@ class ClassMetadataInfo implements ClassMetadata * Validates & completes the given field mapping. * * @param array $mapping The field mapping to validated & complete. - * @return array The validated and completed field mapping. + * @throws MappingException + * @return array The validated and completed field mapping. */ protected function _validateAndCompleteFieldMapping(array &$mapping) { @@ -1342,8 +1352,9 @@ class ClassMetadataInfo implements ClassMetadata * Validates & completes a one-to-one association mapping. * * @param array $mapping The mapping to validate & complete. - * @return array The validated & completed mapping. - * @override + * @throws RuntimeException + * @throws MappingException + * @return array The validated & completed mapping.@override */ protected function _validateAndCompleteOneToOneMapping(array $mapping) { @@ -1363,7 +1374,7 @@ class ClassMetadataInfo implements ClassMetadata } $uniqueContraintColumns = array(); - foreach ($mapping['joinColumns'] as $key => &$joinColumn) { + foreach ($mapping['joinColumns'] as &$joinColumn) { if ($mapping['type'] === self::ONE_TO_ONE && ! $this->isInheritanceTypeSingleTable()) { if (count($mapping['joinColumns']) == 1) { if ( ! isset($mapping['id']) || ! $mapping['id']) { @@ -1399,7 +1410,7 @@ class ClassMetadataInfo implements ClassMetadata if ($uniqueContraintColumns) { if ( ! $this->table) { - throw new \RuntimeException("ClassMetadataInfo::setTable() has to be called before defining a one to one relationship."); + throw new RuntimeException("ClassMetadataInfo::setTable() has to be called before defining a one to one relationship."); } $this->table['uniqueConstraints'][$mapping['fieldName']."_uniq"] = array( 'columns' => $uniqueContraintColumns @@ -1423,8 +1434,9 @@ class ClassMetadataInfo implements ClassMetadata * Validates and completes the mapping. * * @param array $mapping The mapping to validate and complete. - * @return array The validated and completed mapping. - * @override + * @throws MappingException + * @throws InvalidArgumentException + * @return array The validated and completed mapping.@override */ protected function _validateAndCompleteOneToManyMapping(array $mapping) { @@ -1440,7 +1452,7 @@ class ClassMetadataInfo implements ClassMetadata if (isset($mapping['orderBy'])) { if ( ! is_array($mapping['orderBy'])) { - throw new \InvalidArgumentException("'orderBy' is expected to be an array, not ".gettype($mapping['orderBy'])); + throw new InvalidArgumentException("'orderBy' is expected to be an array, not ".gettype($mapping['orderBy'])); } } @@ -1527,7 +1539,7 @@ class ClassMetadataInfo implements ClassMetadata if (isset($mapping['orderBy'])) { if ( ! is_array($mapping['orderBy'])) { - throw new \InvalidArgumentException("'orderBy' is expected to be an array, not ".gettype($mapping['orderBy'])); + throw new InvalidArgumentException("'orderBy' is expected to be an array, not ".gettype($mapping['orderBy'])); } } @@ -1587,7 +1599,7 @@ class ClassMetadataInfo implements ClassMetadata /** * Gets the mapped identifier field of this class. * - * @return string $identifier + * @return array|string $identifier */ public function getIdentifier() { @@ -1597,7 +1609,8 @@ class ClassMetadataInfo implements ClassMetadata /** * Checks whether the class has a (mapped) field with a certain name. * - * @return boolean + * @param string $fieldName + * @return bool */ public function hasField($fieldName) { @@ -1607,6 +1620,7 @@ class ClassMetadataInfo implements ClassMetadata /** * Gets an array containing all the column names. * + * @param array $fieldNames * @return array */ public function getColumnNames(array $fieldNames = null) @@ -1734,7 +1748,7 @@ class ClassMetadataInfo implements ClassMetadata */ public function isIdGeneratorTable() { - $this->generatorType == self::GENERATOR_TYPE_TABLE; + return $this->generatorType == self::GENERATOR_TYPE_TABLE; } /** @@ -1762,7 +1776,7 @@ class ClassMetadataInfo implements ClassMetadata * Gets the type of a field. * * @param string $fieldName - * @return \Doctrine\DBAL\Types\Type + * @return \Doctrine\DBAL\Types\Type|string */ public function getTypeOfField($fieldName) { @@ -1773,6 +1787,7 @@ class ClassMetadataInfo implements ClassMetadata /** * Gets the type of a column. * + * @param string $columnName * @return \Doctrine\DBAL\Types\Type */ public function getTypeOfColumn($columnName) @@ -1834,6 +1849,8 @@ class ClassMetadataInfo implements ClassMetadata * Sets the inheritance type used by the class and it's subclasses. * * @param integer $type + * @throws MappingException + * @return void */ public function setInheritanceType($type) { @@ -1848,6 +1865,8 @@ class ClassMetadataInfo implements ClassMetadata * * @param string $fieldName * @param array $overrideMapping + * @throws MappingException + * @return void */ public function setAssociationOverride($fieldName, array $overrideMapping) { @@ -1870,7 +1889,7 @@ class ClassMetadataInfo implements ClassMetadata $mapping['sourceToTargetKeyColumns'] = null; $mapping['relationToSourceKeyColumns'] = null; $mapping['relationToTargetKeyColumns'] = null; - + switch ($mapping['type']) { case self::ONE_TO_ONE: $mapping = $this->_validateAndCompleteOneToOneMapping($mapping); @@ -1889,11 +1908,14 @@ class ClassMetadataInfo implements ClassMetadata $this->associationMappings[$fieldName] = $mapping; } - /** + /** * Sets the override for a mapped field. * * @param string $fieldName - * @param array $mapping + * @param array $overrideMapping + * @throws MappingException + * @param array $overrideMapping + * @return void */ public function setAttributeOverride($fieldName, array $overrideMapping) { @@ -1930,7 +1952,8 @@ class ClassMetadataInfo implements ClassMetadata /** * Checks whether a mapped field is inherited from an entity superclass. * - * @return boolean TRUE if the field is inherited, FALSE otherwise. + * @param string $fieldName + * @return bool TRUE if the field is inherited, FALSE otherwise. */ public function isInheritedField($fieldName) { @@ -2023,6 +2046,8 @@ class ClassMetadataInfo implements ClassMetadata * Adds a mapped field to the class. * * @param array $mapping The field mapping. + * @throws MappingException + * @return void */ public function mapField(array $mapping) { @@ -2039,6 +2064,8 @@ class ClassMetadataInfo implements ClassMetadata * This is mainly used to add inherited association mappings to derived classes. * * @param array $mapping + * @throws MappingException + * @return void */ public function addInheritedAssociationMapping(array $mapping/*, $owningClassName = null*/) { @@ -2053,7 +2080,8 @@ class ClassMetadataInfo implements ClassMetadata * Adds a field mapping without completing/validating it. * This is mainly used to add inherited field mappings to derived classes. * - * @param array $mapping + * @internal param array $fieldMapping + * @return void */ public function addInheritedFieldMapping(array $fieldMapping) { @@ -2247,6 +2275,8 @@ class ClassMetadataInfo implements ClassMetadata * Stores the association mapping. * * @param array $assocMapping + * @throws MappingException + * @return void */ protected function _storeAssociationMapping(array $assocMapping) { @@ -2277,8 +2307,8 @@ class ClassMetadataInfo implements ClassMetadata * Dispatches the lifecycle event of the given entity to the registered * lifecycle callbacks and lifecycle listeners. * - * @param string $event The lifecycle event. - * @param Entity $entity The Entity on which the event occured. + * @param string $lifecycleEvent The lifecycle event. + * @param \Object $entity The Entity on which the event occured. */ public function invokeLifecycleCallbacks($lifecycleEvent, $entity) { @@ -2335,6 +2365,10 @@ class ClassMetadataInfo implements ClassMetadata * Sets the discriminator column definition. * * @param array $columnDef + * + * @param $columnDef + * @throws MappingException + * @return void * @see getDiscriminatorColumn() */ public function setDiscriminatorColumn($columnDef) @@ -2382,6 +2416,8 @@ class ClassMetadataInfo implements ClassMetadata * * @param string $name * @param string $className + * @throws MappingException + * @return void */ public function addDiscriminatorMapClass($name, $className) { @@ -2493,6 +2529,7 @@ class ClassMetadataInfo implements ClassMetadata * Return the single association join column (if any). * * @param string $fieldName + * @throws MappingException * @return string */ public function getSingleAssociationJoinColumnName($fieldName) @@ -2507,6 +2544,7 @@ class ClassMetadataInfo implements ClassMetadata * Return the single association referenced join column name (if any). * * @param string $fieldName + * @throws MappingException * @return string */ public function getSingleAssociationReferencedJoinColumnName($fieldName) @@ -2523,6 +2561,7 @@ class ClassMetadataInfo implements ClassMetadata * This method is used in foreign-key as primary-key contexts. * * @param string $columnName + * @throws MappingException * @return string */ public function getFieldForColumn($columnName) @@ -2545,7 +2584,7 @@ class ClassMetadataInfo implements ClassMetadata /** * Sets the ID generator used to generate IDs for instances of this class. * - * @param AbstractIdGenerator $generator + * @param \Doctrine\ORM\Id\AbstractIdGenerator $generator */ public function setIdGenerator($generator) { @@ -2591,6 +2630,8 @@ class ClassMetadataInfo implements ClassMetadata * value to use depending on the column type. * * @param array $mapping The version field mapping array + * @throws MappingException + * @return void */ public function setVersionMapping(array &$mapping) { @@ -2667,12 +2708,13 @@ class ClassMetadataInfo implements ClassMetadata * Returns the target class name of the given association. * * @param string $assocName + * @throws InvalidArgumentException * @return string */ public function getAssociationTargetClass($assocName) { if ( ! isset($this->associationMappings[$assocName])) { - throw new \InvalidArgumentException("Association name expected, '" . $assocName ."' is not an association."); + throw new InvalidArgumentException("Association name expected, '" . $assocName ."' is not an association."); } return $this->associationMappings[$assocName]['targetEntity']; @@ -2693,7 +2735,7 @@ class ClassMetadataInfo implements ClassMetadata * * @deprecated Deprecated since version 2.3 in favor of \Doctrine\ORM\Mapping\QuoteStrategy * - * @param AbstractPlatform $platform + * @param \Doctrine\DBAL\Platforms\AbstractPlatform $platform * @return array */ public function getQuotedIdentifierColumnNames($platform) @@ -2728,11 +2770,11 @@ class ClassMetadataInfo implements ClassMetadata /** * Gets the (possibly quoted) column name of a mapped field for safe use in an SQL statement. - * + * * @deprecated Deprecated since version 2.3 in favor of \Doctrine\ORM\Mapping\QuoteStrategy * * @param string $field - * @param AbstractPlatform $platform + * @param \Doctrine\DBAL\Platforms\AbstractPlatform $platform * @return string */ public function getQuotedColumnName($field, $platform) @@ -2747,7 +2789,7 @@ class ClassMetadataInfo implements ClassMetadata * * @deprecated Deprecated since version 2.3 in favor of \Doctrine\ORM\Mapping\QuoteStrategy * - * @param AbstractPlatform $platform + * @param \Doctrine\DBAL\Platforms\AbstractPlatform $platform * @return string */ public function getQuotedTableName($platform) @@ -2760,7 +2802,8 @@ class ClassMetadataInfo implements ClassMetadata * * @deprecated Deprecated since version 2.3 in favor of \Doctrine\ORM\Mapping\QuoteStrategy * - * @param AbstractPlatform $platform + * @param array $assoc + * @param \Doctrine\DBAL\Platforms\AbstractPlatform $platform * @return string */ public function getQuotedJoinTableName(array $assoc, $platform) diff --git a/lib/Doctrine/ORM/Mapping/Driver/DatabaseDriver.php b/lib/Doctrine/ORM/Mapping/Driver/DatabaseDriver.php index a0705e6c2..a47cef88b 100644 --- a/lib/Doctrine/ORM/Mapping/Driver/DatabaseDriver.php +++ b/lib/Doctrine/ORM/Mapping/Driver/DatabaseDriver.php @@ -24,12 +24,13 @@ use Doctrine\DBAL\Schema\AbstractSchemaManager, Doctrine\Common\Persistence\Mapping\Driver\MappingDriver, Doctrine\Common\Persistence\Mapping\ClassMetadata, Doctrine\ORM\Mapping\ClassMetadataInfo, - Doctrine\Common\Util\Inflector; + Doctrine\Common\Util\Inflector, + Doctrine\ORM\Mapping\MappingException; /** * The DatabaseDriver reverse engineers the mapping metadata from a database. * - * + * * @link www.doctrine-project.org * @since 2.0 * @author Guilherme Blanco @@ -115,7 +116,7 @@ class DatabaseDriver implements MappingDriver $this->tables = $this->manyToManyTables = $this->classToTableNames = array(); foreach ($tables as $tableName => $table) { - /* @var $table Table */ + /* @var $table \Doctrine\DBAL\Schema\Table */ if ($this->_sm->getDatabasePlatform()->supportsForeignKeyConstraints()) { $foreignKeys = $table->getForeignKeys(); } else { @@ -189,13 +190,13 @@ class DatabaseDriver implements MappingDriver $fieldMappings = array(); foreach ($columns as $column) { $fieldMapping = array(); - + if (in_array($column->getName(), $allForeignKeyColumns)) { continue; } else if ($primaryKeyColumns && in_array($column->getName(), $primaryKeyColumns)) { $fieldMapping['id'] = true; } - + $fieldMapping['fieldName'] = $this->getFieldNameForColumn($tableName, $column->getName(), false); $fieldMapping['columnName'] = $column->getName(); $fieldMapping['type'] = strtolower((string) $column->getType()); @@ -306,7 +307,7 @@ class DatabaseDriver implements MappingDriver 'referencedColumnName' => $fkCols[$i], ); } - + //Here we need to check if $cols are the same as $primaryKeyColums if (!array_diff($cols,$primaryKeyColumns)) { $metadata->mapOneToOne($associationMapping); diff --git a/lib/Doctrine/ORM/Mapping/Driver/DriverChain.php b/lib/Doctrine/ORM/Mapping/Driver/DriverChain.php index bdeb97b9d..7a636cdb4 100644 --- a/lib/Doctrine/ORM/Mapping/Driver/DriverChain.php +++ b/lib/Doctrine/ORM/Mapping/Driver/DriverChain.php @@ -44,14 +44,14 @@ class DriverChain implements MappingDriver /** * The default driver * - * @var Driver + * @var MappingDriver */ private $defaultDriver; /** * Get the default driver. * - * @return Driver + * @return MappingDriver */ public function getDefaultDriver() { @@ -94,6 +94,8 @@ class DriverChain implements MappingDriver * * @param string $className * @param ClassMetadata $metadata + * @throws MappingException + * @return */ public function loadMetadataForClass($className, ClassMetadata $metadata) { diff --git a/lib/Doctrine/ORM/Mapping/Driver/XmlDriver.php b/lib/Doctrine/ORM/Mapping/Driver/XmlDriver.php index 1969692fe..84efde9ec 100644 --- a/lib/Doctrine/ORM/Mapping/Driver/XmlDriver.php +++ b/lib/Doctrine/ORM/Mapping/Driver/XmlDriver.php @@ -53,7 +53,7 @@ class XmlDriver extends FileDriver public function loadMetadataForClass($className, ClassMetadata $metadata) { $xmlRoot = $this->getElement($className); - + if ($xmlRoot->getName() == 'entity') { if (isset($xmlRoot['repository-class'])) { $metadata->setCustomRepositoryClass((string)$xmlRoot['repository-class']); @@ -235,7 +235,7 @@ class XmlDriver extends FileDriver foreach ($mappings as $mapping) { $metadata->mapField($mapping); } - + // Evaluate mappings $associationIds = array(); foreach ($xmlRoot->id as $idElement) { @@ -550,7 +550,7 @@ class XmlDriver extends FileDriver /** * Parses (nested) option elements. * - * @param $options The XML element. + * @param SimpleXMLElement $options the XML element. * @return array The options array. */ private function _parseOptions(SimpleXMLElement $options) @@ -580,7 +580,7 @@ class XmlDriver extends FileDriver * Constructs a joinColumn mapping array based on the information * found in the given SimpleXMLElement. * - * @param $joinColumnElement The XML element. + * @param SimpleXMLElement $joinColumnElement the XML element. * @return array The mapping array. */ private function joinColumnToArray(SimpleXMLElement $joinColumnElement) @@ -618,43 +618,43 @@ class XmlDriver extends FileDriver private function columnToArray(SimpleXMLElement $fieldMapping) { $mapping = array( - 'fieldName' => (string)$fieldMapping['name'], + 'fieldName' => (string) $fieldMapping['name'], ); if (isset($fieldMapping['type'])) { - $mapping['type'] = (string)$fieldMapping['type']; + $mapping['type'] = (string) $fieldMapping['type']; } if (isset($fieldMapping['column'])) { - $mapping['columnName'] = (string)$fieldMapping['column']; + $mapping['columnName'] = (string) $fieldMapping['column']; } if (isset($fieldMapping['length'])) { - $mapping['length'] = (int)$fieldMapping['length']; + $mapping['length'] = (int) $fieldMapping['length']; } if (isset($fieldMapping['precision'])) { - $mapping['precision'] = (int)$fieldMapping['precision']; + $mapping['precision'] = (int) $fieldMapping['precision']; } if (isset($fieldMapping['scale'])) { - $mapping['scale'] = (int)$fieldMapping['scale']; + $mapping['scale'] = (int) $fieldMapping['scale']; } if (isset($fieldMapping['unique'])) { - $mapping['unique'] = ((string)$fieldMapping['unique'] == "false") ? false : true; + $mapping['unique'] = ((string) $fieldMapping['unique'] == "false") ? false : true; } if (isset($fieldMapping['nullable'])) { - $mapping['nullable'] = ((string)$fieldMapping['nullable'] == "false") ? false : true; + $mapping['nullable'] = ((string) $fieldMapping['nullable'] == "false") ? false : true; } if (isset($fieldMapping['version']) && $fieldMapping['version']) { - $metadata->setVersionMapping($mapping); + $mapping['version'] = $fieldMapping['version']; } if (isset($fieldMapping['column-definition'])) { - $mapping['columnDefinition'] = (string)$fieldMapping['column-definition']; + $mapping['columnDefinition'] = (string) $fieldMapping['column-definition']; } if (isset($fieldMapping->options)) { @@ -667,7 +667,7 @@ class XmlDriver extends FileDriver /** * Gathers a list of cascade options found in the given cascade element. * - * @param $cascadeElement The cascade element. + * @param SimpleXMLElement $cascadeElement the cascade element. * @return array The list of cascade options. */ private function _getCascadeMappings($cascadeElement) diff --git a/lib/Doctrine/ORM/Mapping/Driver/YamlDriver.php b/lib/Doctrine/ORM/Mapping/Driver/YamlDriver.php index 051ea5612..9b65efb64 100644 --- a/lib/Doctrine/ORM/Mapping/Driver/YamlDriver.php +++ b/lib/Doctrine/ORM/Mapping/Driver/YamlDriver.php @@ -134,7 +134,7 @@ class YamlDriver extends FileDriver $entities[] = $entityResult; } } - + if (isset($resultSetMapping['columnResult'])) { foreach ($resultSetMapping['columnResult'] as $columnResultAnnot) { @@ -571,7 +571,7 @@ class YamlDriver extends FileDriver * Constructs a joinColumn mapping array based on the information * found in the given join column element. * - * @param $joinColumnElement The array join column element + * @param array $joinColumnElement The array join column element * @return array The mapping array. */ private function joinColumnToArray($joinColumnElement) @@ -580,7 +580,7 @@ class YamlDriver extends FileDriver if (isset($joinColumnElement['referencedColumnName'])) { $joinColumn['referencedColumnName'] = (string) $joinColumnElement['referencedColumnName']; } - + if (isset($joinColumnElement['name'])) { $joinColumn['name'] = (string) $joinColumnElement['name']; } @@ -660,7 +660,7 @@ class YamlDriver extends FileDriver } if (isset($column['version']) && $column['version']) { - $metadata->setVersionMapping($mapping); + $mapping['version'] = $column['version']; } if (isset($column['columnDefinition'])) { From f6381d7b762d2f61a0a82a6dcff0441aee471b6c Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Sat, 9 Jun 2012 16:04:47 +0200 Subject: [PATCH 20/22] Updating ClassMetadataFactory to comply with new abstract CMF interface as of doctrine/common#150 --- .../ORM/Mapping/ClassMetadataFactory.php | 192 +++++++----------- 1 file changed, 73 insertions(+), 119 deletions(-) diff --git a/lib/Doctrine/ORM/Mapping/ClassMetadataFactory.php b/lib/Doctrine/ORM/Mapping/ClassMetadataFactory.php index 0baccfe92..aafde2eee 100644 --- a/lib/Doctrine/ORM/Mapping/ClassMetadataFactory.php +++ b/lib/Doctrine/ORM/Mapping/ClassMetadataFactory.php @@ -27,7 +27,8 @@ use ReflectionException, Doctrine\Common\Persistence\Mapping\ReflectionService, Doctrine\Common\Persistence\Mapping\ClassMetadata as ClassMetadataInterface, Doctrine\Common\Persistence\Mapping\AbstractClassMetadataFactory, - Doctrine\ORM\Id\IdentityGenerator; + Doctrine\ORM\Id\IdentityGenerator, + Doctrine\ORM\Event\LoadClassMetadataEventArgs; /** * The ClassMetadataFactory is used to create ClassMetadata objects that contain all the @@ -84,126 +85,90 @@ class ClassMetadataFactory extends AbstractClassMetadataFactory /** * {@inheritDoc} - */ - protected function loadMetadata($name) + protected function doLoadMetadata($class, $parent, $rootEntityFound, array $nonSuperclassParents) { - if ( ! $this->initialized) { - $this->initialize(); + /* @var $class ClassMetadata */ + /* @var $parent ClassMetadata */ + if ($parent) { + $class->setInheritanceType($parent->inheritanceType); + $class->setDiscriminatorColumn($parent->discriminatorColumn); + $class->setIdGeneratorType($parent->generatorType); + $this->addInheritedFields($class, $parent); + $this->addInheritedRelations($class, $parent); + $class->setIdentifier($parent->identifier); + $class->setVersioned($parent->isVersioned); + $class->setVersionField($parent->versionField); + $class->setDiscriminatorMap($parent->discriminatorMap); + $class->setLifecycleCallbacks($parent->lifecycleCallbacks); + $class->setChangeTrackingPolicy($parent->changeTrackingPolicy); + + if ($parent->isMappedSuperclass) { + $class->setCustomRepositoryClass($parent->customRepositoryClassName); + } } - $loaded = array(); + // Invoke driver + try { + $this->driver->loadMetadataForClass($class->getName(), $class); + } catch (ReflectionException $e) { + throw MappingException::reflectionFailure($class->getName(), $e); + } - $parentClasses = $this->getParentClasses($name); - $parentClasses[] = $name; - - // Move down the hierarchy of parent classes, starting from the topmost class - $parent = null; - $rootEntityFound = false; - $visited = array(); - foreach ($parentClasses as $className) { - if ($this->hasMetadataFor($className)) { - $parent = $this->getMetadataFor($className); - if ( ! $parent->isMappedSuperclass) { - $rootEntityFound = true; - array_unshift($visited, $className); - } - continue; + // If this class has a parent the id generator strategy is inherited. + // However this is only true if the hierarchy of parents contains the root entity, + // if it consists of mapped superclasses these don't necessarily include the id field. + if ($parent && $rootEntityFound) { + if ($parent->isIdGeneratorSequence()) { + $class->setSequenceGeneratorDefinition($parent->sequenceGeneratorDefinition); + } else if ($parent->isIdGeneratorTable()) { + $class->tableGeneratorDefinition = $parent->tableGeneratorDefinition; } - $class = $this->newClassMetadataInstance($className); - $this->initializeReflection($class, $this->getReflectionService()); - - if ($parent) { - $class->setInheritanceType($parent->inheritanceType); - $class->setDiscriminatorColumn($parent->discriminatorColumn); + if ($parent->generatorType) { $class->setIdGeneratorType($parent->generatorType); - $this->addInheritedFields($class, $parent); - $this->addInheritedRelations($class, $parent); - $class->setIdentifier($parent->identifier); - $class->setVersioned($parent->isVersioned); - $class->setVersionField($parent->versionField); - $class->setDiscriminatorMap($parent->discriminatorMap); - $class->setLifecycleCallbacks($parent->lifecycleCallbacks); - $class->setChangeTrackingPolicy($parent->changeTrackingPolicy); - if ($parent->isMappedSuperclass) { - $class->setCustomRepositoryClass($parent->customRepositoryClassName); - } } - // Invoke driver - try { - $this->driver->loadMetadataForClass($className, $class); - } catch (ReflectionException $e) { - throw MappingException::reflectionFailure($className, $e); + if ($parent->idGenerator) { + $class->setIdGenerator($parent->idGenerator); } - - // If this class has a parent the id generator strategy is inherited. - // However this is only true if the hierarchy of parents contains the root entity, - // if it consists of mapped superclasses these don't necessarily include the id field. - if ($parent && $rootEntityFound) { - if ($parent->isIdGeneratorSequence()) { - $class->setSequenceGeneratorDefinition($parent->sequenceGeneratorDefinition); - } else if ($parent->isIdGeneratorTable()) { - $class->tableGeneratorDefinition = $parent->tableGeneratorDefinition; - } - if ($parent->generatorType) { - $class->setIdGeneratorType($parent->generatorType); - } - if ($parent->idGenerator) { - $class->setIdGenerator($parent->idGenerator); - } - } else { - $this->completeIdGeneratorMapping($class); - } - - if ($parent && $parent->isInheritanceTypeSingleTable()) { - $class->setPrimaryTable($parent->table); - } - - if ($parent && $parent->containsForeignIdentifier) { - $class->containsForeignIdentifier = true; - } - - if ($parent && !empty ($parent->namedQueries)) { - $this->addInheritedNamedQueries($class, $parent); - } - - if ($parent && !empty ($parent->namedNativeQueries)) { - $this->addInheritedNamedNativeQueries($class, $parent); - } - - if ($parent && !empty ($parent->sqlResultSetMappings)) { - $this->addInheritedSqlResultSetMappings($class, $parent); - } - - $class->setParentClasses($visited); - - if ( $class->isRootEntity() && ! $class->isInheritanceTypeNone() && ! $class->discriminatorMap) { - $this->addDefaultDiscriminatorMap($class); - } - - if ($this->evm->hasListeners(Events::loadClassMetadata)) { - $eventArgs = new \Doctrine\ORM\Event\LoadClassMetadataEventArgs($class, $this->em); - $this->evm->dispatchEvent(Events::loadClassMetadata, $eventArgs); - } - $this->wakeupReflection($class, $this->getReflectionService()); - - $this->validateRuntimeMetadata($class, $parent); - - $this->setMetadataFor($className, $class); - - $parent = $class; - - if ( ! $class->isMappedSuperclass) { - $rootEntityFound = true; - array_unshift($visited, $className); - } - - $loaded[] = $className; + } else { + $this->completeIdGeneratorMapping($class); } - return $loaded; + if ($parent && $parent->isInheritanceTypeSingleTable()) { + $class->setPrimaryTable($parent->table); + } + + if ($parent && $parent->containsForeignIdentifier) { + $class->containsForeignIdentifier = true; + } + + if ($parent && !empty ($parent->namedQueries)) { + $this->addInheritedNamedQueries($class, $parent); + } + + if ($parent && !empty ($parent->namedNativeQueries)) { + $this->addInheritedNamedNativeQueries($class, $parent); + } + + if ($parent && !empty ($parent->sqlResultSetMappings)) { + $this->addInheritedSqlResultSetMappings($class, $parent); + } + + $class->setParentClasses($nonSuperclassParents); + + if ( $class->isRootEntity() && ! $class->isInheritanceTypeNone() && ! $class->discriminatorMap) { + $this->addDefaultDiscriminatorMap($class); + } + + if ($this->evm->hasListeners(Events::loadClassMetadata)) { + $eventArgs = new LoadClassMetadataEventArgs($class, $this->em); + $this->evm->dispatchEvent(Events::loadClassMetadata, $eventArgs); + } + + $this->wakeupReflection($class, $this->getReflectionService()); + $this->validateRuntimeMetadata($class, $parent); } /** @@ -586,15 +551,4 @@ class ClassMetadataFactory extends AbstractClassMetadataFactory { return $this->driver; } - - /** - * {@inheritDoc} - */ - protected function doLoadMetadata($class, $parent, $rootEntityFound) - { - throw new \LogicException( - 'Not implemented because Doctrine\Common\Persistence\Mapping\AbstractClassMetadataFactory ' - . 'behavior differs in how Doctrine\ORM\Mapping\MetadataFactory works' - ); - } } From 97d7cae012ed616b6e508e17087fcb4fcbd6d6f5 Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Sun, 10 Jun 2012 23:52:48 +0200 Subject: [PATCH 21/22] Stoffing and including changes of doctrine/common#138 --- .../ORM/Mapping/ClassMetadataFactory.php | 31 ++----------------- 1 file changed, 3 insertions(+), 28 deletions(-) diff --git a/lib/Doctrine/ORM/Mapping/ClassMetadataFactory.php b/lib/Doctrine/ORM/Mapping/ClassMetadataFactory.php index aafde2eee..9e081d43e 100644 --- a/lib/Doctrine/ORM/Mapping/ClassMetadataFactory.php +++ b/lib/Doctrine/ORM/Mapping/ClassMetadataFactory.php @@ -65,7 +65,6 @@ class ClassMetadataFactory extends AbstractClassMetadataFactory /** * @param EntityManager $em - * @return void */ public function setEntityManager(EntityManager $em) { @@ -144,15 +143,15 @@ class ClassMetadataFactory extends AbstractClassMetadataFactory $class->containsForeignIdentifier = true; } - if ($parent && !empty ($parent->namedQueries)) { + if ($parent && !empty($parent->namedQueries)) { $this->addInheritedNamedQueries($class, $parent); } - if ($parent && !empty ($parent->namedNativeQueries)) { + if ($parent && !empty($parent->namedNativeQueries)) { $this->addInheritedNamedNativeQueries($class, $parent); } - if ($parent && !empty ($parent->sqlResultSetMappings)) { + if ($parent && !empty($parent->sqlResultSetMappings)) { $this->addInheritedSqlResultSetMappings($class, $parent); } @@ -177,7 +176,6 @@ class ClassMetadataFactory extends AbstractClassMetadataFactory * @param ClassMetadata $class * @param $parent * @throws MappingException - * @return void */ protected function validateRuntimeMetadata($class, $parent) { @@ -229,7 +227,6 @@ class ClassMetadataFactory extends AbstractClassMetadataFactory * * @param \Doctrine\ORM\Mapping\ClassMetadata $class * @throws MappingException - * @return void */ private function addDefaultDiscriminatorMap(ClassMetadata $class) { @@ -301,7 +298,6 @@ class ClassMetadataFactory extends AbstractClassMetadataFactory * @param \Doctrine\ORM\Mapping\ClassMetadata $subClass * @param \Doctrine\ORM\Mapping\ClassMetadata $parentClass * @throws MappingException - * @return void */ private function addInheritedRelations(ClassMetadata $subClass, ClassMetadata $parentClass) { @@ -401,7 +397,6 @@ class ClassMetadataFactory extends AbstractClassMetadataFactory * * @param ClassMetadataInfo $class * @throws ORMException - * @return void */ private function completeIdGeneratorMapping(ClassMetadataInfo $class) { @@ -498,26 +493,6 @@ class ClassMetadataFactory extends AbstractClassMetadataFactory } } - /** - * {@inheritDoc} - * - * @todo remove after doctrine/common#138 is merged - */ - public function isTransient($class) - { - if ( ! $this->initialized) { - $this->initialize(); - } - - // Check for namespace alias - if (strpos($class, ':') !== false) { - list($namespaceAlias, $simpleClassName) = explode(':', $class); - $class = $this->getFqcnFromAlias($namespaceAlias, $simpleClassName); - } - - return $this->driver->isTransient($class); - } - /** * {@inheritDoc} */ From 379e69865e9d848726d94214b75ad30daa401f26 Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Thu, 21 Jun 2012 15:31:36 +0200 Subject: [PATCH 22/22] Reusing chained driver now available in common, fixing cs/code smells and removing duplicate docs. --- lib/Doctrine/ORM/Mapping/ClassMetadata.php | 17 +--- .../ORM/Mapping/ClassMetadataInfo.php | 62 ++++----------- .../ORM/Mapping/Driver/AnnotationDriver.php | 10 ++- .../ORM/Mapping/Driver/DatabaseDriver.php | 10 +-- .../ORM/Mapping/Driver/DriverChain.php | 79 +++---------------- lib/Doctrine/ORM/Mapping/Driver/PHPDriver.php | 7 +- .../Mapping/Driver/SimplifiedXmlDriver.php | 2 +- .../Mapping/Driver/SimplifiedYamlDriver.php | 2 +- .../ORM/Mapping/Driver/StaticPHPDriver.php | 19 +++-- lib/Doctrine/ORM/Mapping/Driver/XmlDriver.php | 10 ++- .../ORM/Mapping/Driver/YamlDriver.php | 23 +++--- 11 files changed, 73 insertions(+), 168 deletions(-) diff --git a/lib/Doctrine/ORM/Mapping/ClassMetadata.php b/lib/Doctrine/ORM/Mapping/ClassMetadata.php index 55e975cc5..a57f1e15a 100644 --- a/lib/Doctrine/ORM/Mapping/ClassMetadata.php +++ b/lib/Doctrine/ORM/Mapping/ClassMetadata.php @@ -20,22 +20,9 @@ namespace Doctrine\ORM\Mapping; /** - * A ClassMetadata instance holds all the object-relational mapping metadata - * of an entity and it's associations. + * {@inheritDoc} * - * Once populated, ClassMetadata instances are usually cached in a serialized form. - * - * IMPORTANT NOTE: - * - * The fields of this class are only public for 2 reasons: - * 1) To allow fast READ access. - * 2) To drastically reduce the size of a serialized instance (private/protected members - * get the whole class name, namespace inclusive, prepended to every property in - * the serialized representation). - * - * @author Roman Borschel - * @author Jonathan H. Wage - * @since 2.0 + * @todo remove or rename ClassMetadataInfo to ClassMetadata */ class ClassMetadata extends ClassMetadataInfo { diff --git a/lib/Doctrine/ORM/Mapping/ClassMetadataInfo.php b/lib/Doctrine/ORM/Mapping/ClassMetadataInfo.php index caee668d6..85f928971 100644 --- a/lib/Doctrine/ORM/Mapping/ClassMetadataInfo.php +++ b/lib/Doctrine/ORM/Mapping/ClassMetadataInfo.php @@ -926,9 +926,7 @@ class ClassMetadataInfo implements ClassMetadata } /** - * Gets the ReflectionClass instance of the mapped class. - * - * @return ReflectionClass + * {@inheritDoc} */ public function getReflectionClass() { @@ -1547,9 +1545,7 @@ class ClassMetadataInfo implements ClassMetadata } /** - * Gets the identifier (primary key) field names of the class. - * - * @return mixed + * {@inheritDoc} */ public function getIdentifierFieldNames() { @@ -1607,10 +1603,7 @@ class ClassMetadataInfo implements ClassMetadata } /** - * Checks whether the class has a (mapped) field with a certain name. - * - * @param string $fieldName - * @return bool + * {@inheritDoc} */ public function hasField($fieldName) { @@ -2080,7 +2073,7 @@ class ClassMetadataInfo implements ClassMetadata * Adds a field mapping without completing/validating it. * This is mainly used to add inherited field mappings to derived classes. * - * @internal param array $fieldMapping + * @param array $fieldMapping * @return void */ public function addInheritedFieldMapping(array $fieldMapping) @@ -2292,7 +2285,8 @@ class ClassMetadataInfo implements ClassMetadata /** * Registers a custom repository class for the entity class. * - * @param string $mapperClassName The class name of the custom mapper. + * @param string $repositoryClassName The class name of the custom mapper. + * @return void */ public function setCustomRepositoryClass($repositoryClassName) { @@ -2474,10 +2468,7 @@ class ClassMetadataInfo implements ClassMetadata } /** - * Checks whether the class has a mapped association with the given field name. - * - * @param string $fieldName - * @return boolean + * {@inheritDoc} */ public function hasAssociation($fieldName) { @@ -2485,11 +2476,7 @@ class ClassMetadataInfo implements ClassMetadata } /** - * Checks whether the class has a mapped association for the specified field - * and if yes, checks whether it is a single-valued association (to-one). - * - * @param string $fieldName - * @return boolean TRUE if the association exists and is single-valued, FALSE otherwise. + * {@inheritDoc} */ public function isSingleValuedAssociation($fieldName) { @@ -2498,11 +2485,7 @@ class ClassMetadataInfo implements ClassMetadata } /** - * Checks whether the class has a mapped association for the specified field - * and if yes, checks whether it is a collection-valued association (to-many). - * - * @param string $fieldName - * @return boolean TRUE if the association exists and is collection-valued, FALSE otherwise. + * {@inheritDoc} */ public function isCollectionValuedAssociation($fieldName) { @@ -2681,11 +2664,7 @@ class ClassMetadataInfo implements ClassMetadata } /** - * A numerically indexed list of field names of this persistent class. - * - * This array includes identifier fields if present on this class. - * - * @return array + * {@inheritDoc} */ public function getFieldNames() { @@ -2693,11 +2672,7 @@ class ClassMetadataInfo implements ClassMetadata } /** - * A numerically indexed list of association names of this persistent class. - * - * This array includes identifier associations if present on this class. - * - * @return array + * {@inheritDoc} */ public function getAssociationNames() { @@ -2705,11 +2680,8 @@ class ClassMetadataInfo implements ClassMetadata } /** - * Returns the target class name of the given association. - * - * @param string $assocName + * {@inheritDoc} * @throws InvalidArgumentException - * @return string */ public function getAssociationTargetClass($assocName) { @@ -2721,9 +2693,7 @@ class ClassMetadataInfo implements ClassMetadata } /** - * Get fully-qualified class name of this persistent class. - * - * @return string + * {@inheritDoc} */ public function getName() { @@ -2812,8 +2782,7 @@ class ClassMetadataInfo implements ClassMetadata } /** - * @param string $fieldName - * @return bool + * {@inheritDoc} */ public function isAssociationInverseSide($fieldName) { @@ -2821,8 +2790,7 @@ class ClassMetadataInfo implements ClassMetadata } /** - * @param string $fieldName - * @return string + * {@inheritDoc} */ public function getAssociationMappedByTargetField($fieldName) { diff --git a/lib/Doctrine/ORM/Mapping/Driver/AnnotationDriver.php b/lib/Doctrine/ORM/Mapping/Driver/AnnotationDriver.php index f4501de8b..b7562ad52 100644 --- a/lib/Doctrine/ORM/Mapping/Driver/AnnotationDriver.php +++ b/lib/Doctrine/ORM/Mapping/Driver/AnnotationDriver.php @@ -38,7 +38,7 @@ use Doctrine\Common\Annotations\AnnotationReader, class AnnotationDriver extends AbstractAnnotationDriver { /** - * {@inheritdoc} + * {@inheritDoc} */ protected $entityAnnotationClasses = array( 'Doctrine\ORM\Mapping\Entity' => 1, @@ -46,10 +46,11 @@ class AnnotationDriver extends AbstractAnnotationDriver ); /** - * {@inheritdoc} + * {@inheritDoc} */ public function loadMetadataForClass($className, ClassMetadata $metadata) { + /* @var $metadata \Doctrine\ORM\Mapping\ClassMetadataInfo */ $class = $metadata->getReflectionClass(); if ( ! $class) { // this happens when running annotation driver in combination with @@ -264,6 +265,7 @@ class AnnotationDriver extends AbstractAnnotationDriver } // Evaluate annotations on properties/fields + /* @var $property \ReflectionProperty */ foreach ($class->getProperties() as $property) { if ($metadata->isMappedSuperclass && ! $property->isPrivate() || @@ -437,7 +439,6 @@ class AnnotationDriver extends AbstractAnnotationDriver } } - $attributeOverrides = array(); // Evaluate AttributeOverrides annotation if (isset($classAnnotations['Doctrine\ORM\Mapping\AttributeOverrides'])) { $attributeOverridesAnnot = $classAnnotations['Doctrine\ORM\Mapping\AttributeOverrides']; @@ -449,6 +450,7 @@ class AnnotationDriver extends AbstractAnnotationDriver // Evaluate @HasLifecycleCallbacks annotation if (isset($classAnnotations['Doctrine\ORM\Mapping\HasLifecycleCallbacks'])) { + /* @var $method \ReflectionMethod */ foreach ($class->getMethods() as $method) { // filter for the declaring class only, callbacks from parents will already be registered. if ($method->isPublic() && $method->getDeclaringClass()->getName() == $class->name) { @@ -576,8 +578,8 @@ class AnnotationDriver extends AbstractAnnotationDriver { if ($reader == null) { $reader = new AnnotationReader(); - $reader->setDefaultAnnotationNamespace('Doctrine\ORM\Mapping\\'); } + return new self($reader, $paths); } } diff --git a/lib/Doctrine/ORM/Mapping/Driver/DatabaseDriver.php b/lib/Doctrine/ORM/Mapping/Driver/DatabaseDriver.php index a47cef88b..0882c50bc 100644 --- a/lib/Doctrine/ORM/Mapping/Driver/DatabaseDriver.php +++ b/lib/Doctrine/ORM/Mapping/Driver/DatabaseDriver.php @@ -152,7 +152,7 @@ class DatabaseDriver implements MappingDriver } /** - * {@inheritdoc} + * {@inheritDoc} */ public function loadMetadataForClass($className, ClassMetadata $metadata) { @@ -318,7 +318,7 @@ class DatabaseDriver implements MappingDriver } /** - * {@inheritdoc} + * {@inheritDoc} */ public function isTransient($className) { @@ -326,11 +326,7 @@ class DatabaseDriver implements MappingDriver } /** - * Return all the class names supported by this driver. - * - * IMPORTANT: This method must return an array of class not tables names. - * - * @return array + * {@inheritDoc} */ public function getAllClassNames() { diff --git a/lib/Doctrine/ORM/Mapping/Driver/DriverChain.php b/lib/Doctrine/ORM/Mapping/Driver/DriverChain.php index 7a636cdb4..70f681e3c 100644 --- a/lib/Doctrine/ORM/Mapping/Driver/DriverChain.php +++ b/lib/Doctrine/ORM/Mapping/Driver/DriverChain.php @@ -20,6 +20,7 @@ namespace Doctrine\ORM\Mapping\Driver; use Doctrine\Common\Persistence\Mapping\Driver\MappingDriver, + Doctrine\Common\Persistence\Mapping\Driver\MappingDriverChain, Doctrine\Common\Persistence\Mapping\ClassMetadata, Doctrine\ORM\Mapping\MappingException; @@ -32,15 +33,9 @@ use Doctrine\Common\Persistence\Mapping\Driver\MappingDriver, * @author Guilherme Blanco * @author Jonathan H. Wage * @author Roman Borschel - * @todo Rename: MappingDriverChain or MetadataDriverChain */ -class DriverChain implements MappingDriver +class DriverChain extends MappingDriverChain { - /** - * @var array - */ - private $drivers = array(); - /** * The default driver * @@ -51,7 +46,7 @@ class DriverChain implements MappingDriver /** * Get the default driver. * - * @return MappingDriver + * @return MappingDriver|null */ public function getDefaultDriver() { @@ -69,37 +64,13 @@ class DriverChain implements MappingDriver } /** - * 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 + * {@inheritDoc} * @throws MappingException - * @return */ public function loadMetadataForClass($className, ClassMetadata $metadata) { - foreach ($this->drivers as $namespace => $driver) { + /* @var $driver MappingDriver */ + foreach ($this->getDrivers() as $namespace => $driver) { if (strpos($className, $namespace) === 0) { $driver->loadMetadataForClass($className, $metadata); return; @@ -115,50 +86,18 @@ class DriverChain implements MappingDriver } /** - * 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(); - 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 + * {@inheritDoc} */ public function isTransient($className) { - foreach ($this->drivers as $namespace => $driver) { - if (strpos($className, $namespace) === 0) { - return $driver->isTransient($className); - } + if (!parent::isTransient($className)) { + return false; } if ($this->defaultDriver !== null) { return $this->defaultDriver->isTransient($className); } - // class isTransient, i.e. not an entity or mapped superclass return true; } } diff --git a/lib/Doctrine/ORM/Mapping/Driver/PHPDriver.php b/lib/Doctrine/ORM/Mapping/Driver/PHPDriver.php index 186ca8fef..4266999a4 100644 --- a/lib/Doctrine/ORM/Mapping/Driver/PHPDriver.php +++ b/lib/Doctrine/ORM/Mapping/Driver/PHPDriver.php @@ -34,7 +34,6 @@ use Doctrine\Common\Persistence\Mapping\ClassMetadata, * @author Guilherme Blanco * @author Jonathan H. Wage * @author Roman Borschel - * @todo Rename: PHPDriver */ class PHPDriver extends FileDriver { @@ -47,7 +46,7 @@ class PHPDriver extends FileDriver protected $_metadata; /** - * {@inheritdoc} + * {@inheritDoc} */ public function __construct($locator, $fileExtension = self::DEFAULT_FILE_EXTENSION) { @@ -55,7 +54,7 @@ class PHPDriver extends FileDriver } /** - * {@inheritdoc} + * {@inheritDoc} */ public function loadMetadataForClass($className, ClassMetadata $metadata) { @@ -64,7 +63,7 @@ class PHPDriver extends FileDriver } /** - * {@inheritdoc} + * {@inheritDoc} */ protected function loadMappingFile($file) { diff --git a/lib/Doctrine/ORM/Mapping/Driver/SimplifiedXmlDriver.php b/lib/Doctrine/ORM/Mapping/Driver/SimplifiedXmlDriver.php index ab28d9fce..85221f3a2 100644 --- a/lib/Doctrine/ORM/Mapping/Driver/SimplifiedXmlDriver.php +++ b/lib/Doctrine/ORM/Mapping/Driver/SimplifiedXmlDriver.php @@ -33,7 +33,7 @@ class SimplifiedXmlDriver extends XmlDriver const DEFAULT_FILE_EXTENSION = '.orm.xml'; /** - * {@inheritdoc} + * {@inheritDoc} */ public function __construct($prefixes, $fileExtension = self::DEFAULT_FILE_EXTENSION) { diff --git a/lib/Doctrine/ORM/Mapping/Driver/SimplifiedYamlDriver.php b/lib/Doctrine/ORM/Mapping/Driver/SimplifiedYamlDriver.php index 7fc840de6..d2b8c0fcf 100644 --- a/lib/Doctrine/ORM/Mapping/Driver/SimplifiedYamlDriver.php +++ b/lib/Doctrine/ORM/Mapping/Driver/SimplifiedYamlDriver.php @@ -33,7 +33,7 @@ class SimplifiedYamlDriver extends YamlDriver const DEFAULT_FILE_EXTENSION = '.orm.yml'; /** - * {@inheritdoc} + * {@inheritDoc} */ public function __construct($prefixes, $fileExtension = self::DEFAULT_FILE_EXTENSION) { diff --git a/lib/Doctrine/ORM/Mapping/Driver/StaticPHPDriver.php b/lib/Doctrine/ORM/Mapping/Driver/StaticPHPDriver.php index 64177bace..78dd237dd 100644 --- a/lib/Doctrine/ORM/Mapping/Driver/StaticPHPDriver.php +++ b/lib/Doctrine/ORM/Mapping/Driver/StaticPHPDriver.php @@ -58,18 +58,28 @@ class StaticPHPDriver implements MappingDriver */ private $_fileExtension = '.php'; + /** + * Constructor + * + * @param array $paths Paths where to look for mappings + */ public function __construct($paths) { $this->addPaths((array) $paths); } + /** + * Add paths where to look for mappings + * + * @param array $paths + */ public function addPaths(array $paths) { $this->_paths = array_unique(array_merge($this->_paths, $paths)); } /** - * {@inheritdoc} + * {@inheritDoc} */ public function loadMetadataForClass($className, ClassMetadata $metadata) { @@ -78,7 +88,6 @@ class StaticPHPDriver implements MappingDriver /** * {@inheritDoc} - * @todo Same code exists in AnnotationDriver, should we re-use it somehow or not worry about it? */ public function getAllClassNames() { @@ -99,8 +108,8 @@ class StaticPHPDriver implements MappingDriver } $iterator = new \RecursiveIteratorIterator( - new \RecursiveDirectoryIterator($path), - \RecursiveIteratorIterator::LEAVES_ONLY + new \RecursiveDirectoryIterator($path), + \RecursiveIteratorIterator::LEAVES_ONLY ); foreach ($iterator as $file) { @@ -130,7 +139,7 @@ class StaticPHPDriver implements MappingDriver } /** - * {@inheritdoc} + * {@inheritDoc} */ public function isTransient($className) { diff --git a/lib/Doctrine/ORM/Mapping/Driver/XmlDriver.php b/lib/Doctrine/ORM/Mapping/Driver/XmlDriver.php index 84efde9ec..251b71909 100644 --- a/lib/Doctrine/ORM/Mapping/Driver/XmlDriver.php +++ b/lib/Doctrine/ORM/Mapping/Driver/XmlDriver.php @@ -40,7 +40,7 @@ class XmlDriver extends FileDriver const DEFAULT_FILE_EXTENSION = '.dcm.xml'; /** - * {@inheritdoc} + * {@inheritDoc} */ public function __construct($locator, $fileExtension = self::DEFAULT_FILE_EXTENSION) { @@ -48,10 +48,12 @@ class XmlDriver extends FileDriver } /** - * {@inheritdoc} + * {@inheritDoc} */ public function loadMetadataForClass($className, ClassMetadata $metadata) { + /* @var $metadata \Doctrine\ORM\Mapping\ClassMetadataInfo */ + /* @var $xmlRoot SimpleXMLElement */ $xmlRoot = $this->getElement($className); if ($xmlRoot->getName() == 'entity') { @@ -557,6 +559,7 @@ class XmlDriver extends FileDriver { $array = array(); + /* @var $option SimpleXMLElement */ foreach ($options as $option) { if ($option->count()) { $value = $this->_parseOptions($option->children()); @@ -673,6 +676,7 @@ class XmlDriver extends FileDriver private function _getCascadeMappings($cascadeElement) { $cascades = array(); + /* @var $action SimpleXmlElement */ foreach ($cascadeElement->children() as $action) { // According to the JPA specifications, XML uses "cascade-persist" // instead of "persist". Here, both variations @@ -685,7 +689,7 @@ class XmlDriver extends FileDriver } /** - * {@inheritdoc} + * {@inheritDoc} */ protected function loadMappingFile($file) { diff --git a/lib/Doctrine/ORM/Mapping/Driver/YamlDriver.php b/lib/Doctrine/ORM/Mapping/Driver/YamlDriver.php index 9b65efb64..4ade73960 100644 --- a/lib/Doctrine/ORM/Mapping/Driver/YamlDriver.php +++ b/lib/Doctrine/ORM/Mapping/Driver/YamlDriver.php @@ -38,7 +38,7 @@ class YamlDriver extends FileDriver const DEFAULT_FILE_EXTENSION = '.dcm.yml'; /** - * {@inheritdoc} + * {@inheritDoc} */ public function __construct($locator, $fileExtension = self::DEFAULT_FILE_EXTENSION) { @@ -46,10 +46,11 @@ class YamlDriver extends FileDriver } /** - * {@inheritdoc} + * {@inheritDoc} */ public function loadMetadataForClass($className, ClassMetadata $metadata) { + /* @var $metadata \Doctrine\ORM\Mapping\ClassMetadataInfo */ $element = $this->getElement($className); if ($element['type'] == 'entity') { @@ -326,9 +327,9 @@ class YamlDriver extends FileDriver if (isset($oneToOneElement['joinColumn'])) { $joinColumns[] = $this->joinColumnToArray($oneToOneElement['joinColumn']); } else if (isset($oneToOneElement['joinColumns'])) { - foreach ($oneToOneElement['joinColumns'] as $name => $joinColumnElement) { + foreach ($oneToOneElement['joinColumns'] as $joinColumnName => $joinColumnElement) { if ( ! isset($joinColumnElement['name'])) { - $joinColumnElement['name'] = $name; + $joinColumnElement['name'] = $joinColumnName; } $joinColumns[] = $this->joinColumnToArray($joinColumnElement); @@ -408,9 +409,9 @@ class YamlDriver extends FileDriver if (isset($manyToOneElement['joinColumn'])) { $joinColumns[] = $this->joinColumnToArray($manyToOneElement['joinColumn']); } else if (isset($manyToOneElement['joinColumns'])) { - foreach ($manyToOneElement['joinColumns'] as $name => $joinColumnElement) { + foreach ($manyToOneElement['joinColumns'] as $joinColumnName => $joinColumnElement) { if ( ! isset($joinColumnElement['name'])) { - $joinColumnElement['name'] = $name; + $joinColumnElement['name'] = $joinColumnName; } $joinColumns[] = $this->joinColumnToArray($joinColumnElement); @@ -452,17 +453,17 @@ class YamlDriver extends FileDriver $joinTable['schema'] = $joinTableElement['schema']; } - foreach ($joinTableElement['joinColumns'] as $name => $joinColumnElement) { + foreach ($joinTableElement['joinColumns'] as $joinColumnName => $joinColumnElement) { if ( ! isset($joinColumnElement['name'])) { - $joinColumnElement['name'] = $name; + $joinColumnElement['name'] = $joinColumnName; } $joinTable['joinColumns'][] = $this->joinColumnToArray($joinColumnElement); } - foreach ($joinTableElement['inverseJoinColumns'] as $name => $joinColumnElement) { + foreach ($joinTableElement['inverseJoinColumns'] as $joinColumnName => $joinColumnElement) { if ( ! isset($joinColumnElement['name'])) { - $joinColumnElement['name'] = $name; + $joinColumnElement['name'] = $joinColumnName; } $joinTable['inverseJoinColumns'][] = $this->joinColumnToArray($joinColumnElement); @@ -671,7 +672,7 @@ class YamlDriver extends FileDriver } /** - * {@inheritdoc} + * {@inheritDoc} */ protected function loadMappingFile($file) {