Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Cleanup/removing deprecated metadata drivers #397

Merged
merged 6 commits into from

4 participants

@Ocramius
Owner

Removing deprecated drivers that are already available in Doctrine\Common.
This PR depends on doctrine/common#164/ For now it fails since the referenced git submodule for Doctrine\Common points to a commit that isn't yet in the common repository.

Build Status

@travisbot

This pull request fails (merged 915da58 into 113c6f5).

@travisbot

This pull request fails (merged a2e00a9 into 113c6f5).

lib/Doctrine/ORM/Mapping/Driver/DriverChain.php
((22 lines not shown))
-use Doctrine\Common\Persistence\Mapping\Driver\MappingDriver,
- Doctrine\Common\Persistence\Mapping\Driver\MappingDriverChain,
- Doctrine\Common\Persistence\Mapping\ClassMetadata,
- Doctrine\ORM\Mapping\MappingException;
-
-/**
- * The DriverChain allows you to add multiple other mapping drivers for
- * certain namespaces
- *
- * @since 2.0
- * @author Benjamin Eberlei <kontakt@beberlei.de>
- * @author Guilherme Blanco <guilhermeblanco@hotmail.com>
- * @author Jonathan H. Wage <jonwage@gmail.com>
- * @author Roman Borschel <roman@code-factory.org>
- */
-class DriverChain extends MappingDriverChain
@stof
stof added a note

removing it is a BC break. You should keep it (empty) and mark it as deprecated instead

@beberlei Owner

yes make it empty and extend the Common Persistence ones and mark as deprecated.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
lib/Doctrine/ORM/Mapping/Driver/PHPDriver.php
((23 lines not shown))
- Doctrine\Common\Persistence\Mapping\Driver\FileDriver;
-
-/**
- * The PHPDriver includes php files which just populate ClassMetadata
- * instances with plain php code
- *
- * @license http://www.opensource.org/licenses/lgpl-license.php LGPL
- * @link www.doctrine-project.org
- * @since 2.0
- * @version $Revision$
- * @author Benjamin Eberlei <kontakt@beberlei.de>
- * @author Guilherme Blanco <guilhermeblanco@hotmail.com>
- * @author Jonathan H. Wage <jonwage@gmail.com>
- * @author Roman Borschel <roman@code-factory.org>
- */
-class PHPDriver extends FileDriver
@stof
stof added a note

why removing this driver ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
lib/Doctrine/ORM/Mapping/Driver/StaticPHPDriver.php
((23 lines not shown))
- Doctrine\Common\Persistence\Mapping\Driver\MappingDriver,
- Doctrine\ORM\Mapping\MappingException;
-
-/**
- * The StaticPHPDriver calls a static loadMetadata() method on your entity
- * classes where you can manually populate the ClassMetadata instance.
- *
- * @license http://www.opensource.org/licenses/lgpl-license.php LGPL
- * @link www.doctrine-project.org
- * @since 2.0
- * @author Benjamin Eberlei <kontakt@beberlei.de>
- * @author Guilherme Blanco <guilhermeblanco@hotmail.com>
- * @author Jonathan H. Wage <jonwage@gmail.com>
- * @author Roman Borschel <roman@code-factory.org>
- */
-class StaticPHPDriver implements MappingDriver
@stof
stof added a note

same here. This is a BC break

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@Ocramius
Owner

@stof I know this is BC break, but these drivers exist in Doctrine\Common since quite some time, and keeping them here simply makes things more difficult when it comes to compatibilize libraries :) Also, for now this just requires a rename of an import, as you can see from Ocramius@e2c1d7c#L3R6 and Ocramius@e2c1d7c#L4R6

@Ocramius
Owner

Ah, that way... I went for a direct removal. Adding them later today

@Ocramius
Owner

This should be ok now

@beberlei beberlei merged commit e0455b5 into doctrine:master
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
View
6 UPGRADE.md
@@ -41,6 +41,12 @@ Metadata drivers have been rewritten to reuse code from Doctrine\Common. Anyone
`Doctrine\ORM\Mapping\Driver\AbstractFileDriver`: you should now refer to
`Doctrine\Common\Persistence\Mapping\Driver\FileDriver`.
+Also, following mapping drivers have been deprecated, please use their replacements in Doctrine\Common as listed:
+
+ * `Doctrine\ORM\Mapping\Driver\DriverChain` => `Doctrine\Common\Persistence\Mapping\Driver\MappingDriverChain`
+ * `Doctrine\ORM\Mapping\Driver\PHPDriver` => `Doctrine\Common\Persistence\Mapping\Driver\PHPDriver`
+ * `Doctrine\ORM\Mapping\Driver\StaticPHPDriver` => `Doctrine\Common\Persistence\Mapping\Driver\StaticPHPDriver`
+
# Upgrade to 2.2
## ResultCache implementation rewritten
View
80 lib/Doctrine/ORM/Mapping/Driver/DriverChain.php
@@ -19,85 +19,13 @@
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;
+use Doctrine\Common\Persistence\Mapping\Driver\MappingDriverChain;
/**
- * The DriverChain allows you to add multiple other mapping drivers for
- * certain namespaces
+ * {@inheritDoc}
*
- * @since 2.0
- * @author Benjamin Eberlei <kontakt@beberlei.de>
- * @author Guilherme Blanco <guilhermeblanco@hotmail.com>
- * @author Jonathan H. Wage <jonwage@gmail.com>
- * @author Roman Borschel <roman@code-factory.org>
+ * @deprecated this driver will be removed. Use Doctrine\Common\Persistence\Mapping\Driver\MappingDriverChain instead
*/
class DriverChain extends MappingDriverChain
{
- /**
- * The default driver
- *
- * @var MappingDriver
- */
- private $defaultDriver;
-
- /**
- * Get the default driver.
- *
- * @return MappingDriver|null
- */
- public function getDefaultDriver()
- {
- return $this->defaultDriver;
- }
-
- /**
- * Set the default driver.
- *
- * @param MappingDriver $driver
- */
- public function setDefaultDriver(MappingDriver $driver)
- {
- $this->defaultDriver = $driver;
- }
-
- /**
- * {@inheritDoc}
- * @throws MappingException
- */
- public function loadMetadataForClass($className, ClassMetadata $metadata)
- {
- /* @var $driver MappingDriver */
- foreach ($this->getDrivers() as $namespace => $driver) {
- if (strpos($className, $namespace) === 0) {
- $driver->loadMetadataForClass($className, $metadata);
- return;
- }
- }
-
- if ($this->defaultDriver !== null) {
- $this->defaultDriver->loadMetadataForClass($className, $metadata);
- return;
- }
-
- throw MappingException::classIsNotAValidEntityOrMappedSuperClass($className);
- }
-
- /**
- * {@inheritDoc}
- */
- public function isTransient($className)
- {
- if (!parent::isTransient($className)) {
- return false;
- }
-
- if ($this->defaultDriver !== null) {
- return $this->defaultDriver->isTransient($className);
- }
-
- return true;
- }
-}
+}
View
55 lib/Doctrine/ORM/Mapping/Driver/PHPDriver.php
@@ -19,60 +19,13 @@
namespace Doctrine\ORM\Mapping\Driver;
-use Doctrine\Common\Persistence\Mapping\ClassMetadata,
- Doctrine\Common\Persistence\Mapping\Driver\FileDriver;
+use Doctrine\Common\Persistence\Mapping\Driver\PHPDriver as CommonPHPDriver;
/**
- * The PHPDriver includes php files which just populate ClassMetadata
- * instances with plain php code
+ * {@inheritDoc}
*
- * @license http://www.opensource.org/licenses/lgpl-license.php LGPL
- * @link www.doctrine-project.org
- * @since 2.0
- * @version $Revision$
- * @author Benjamin Eberlei <kontakt@beberlei.de>
- * @author Guilherme Blanco <guilhermeblanco@hotmail.com>
- * @author Jonathan H. Wage <jonwage@gmail.com>
- * @author Roman Borschel <roman@code-factory.org>
+ * @deprecated this driver will be removed. Use Doctrine\Common\Persistence\Mapping\Driver\PHPDriver instead
*/
-class PHPDriver extends FileDriver
+class PHPDriver extends CommonPHPDriver
{
- const DEFAULT_FILE_EXTENSION = '.php';
-
- /**
- *
- * @var ClassMetadata
- */
- protected $_metadata;
-
- /**
- * {@inheritDoc}
- */
- public function __construct($locator, $fileExtension = self::DEFAULT_FILE_EXTENSION)
- {
- parent::__construct($locator, $fileExtension);
- }
-
- /**
- * {@inheritDoc}
- */
- public function loadMetadataForClass($className, ClassMetadata $metadata)
- {
- $this->_metadata = $metadata;
- $this->getElement($className);
- }
-
- /**
- * {@inheritDoc}
- */
- 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;
- }
}
View
127 lib/Doctrine/ORM/Mapping/Driver/StaticPHPDriver.php
@@ -19,130 +19,13 @@
namespace Doctrine\ORM\Mapping\Driver;
-use Doctrine\Common\Persistence\Mapping\ClassMetadata,
- Doctrine\Common\Persistence\Mapping\Driver\MappingDriver,
- Doctrine\ORM\Mapping\MappingException;
+use Doctrine\Common\Persistence\Mapping\Driver\StaticPHPDriver as CommonStaticPHPDriver;
/**
- * The StaticPHPDriver calls a static loadMetadata() method on your entity
- * classes where you can manually populate the ClassMetadata instance.
+ * {@inheritDoc}
*
- * @license http://www.opensource.org/licenses/lgpl-license.php LGPL
- * @link www.doctrine-project.org
- * @since 2.0
- * @author Benjamin Eberlei <kontakt@beberlei.de>
- * @author Guilherme Blanco <guilhermeblanco@hotmail.com>
- * @author Jonathan H. Wage <jonwage@gmail.com>
- * @author Roman Borschel <roman@code-factory.org>
+ * @deprecated this driver will be removed. Use Doctrine\Common\Persistence\Mapping\Driver\StaticPHPDriver instead
*/
-class StaticPHPDriver implements MappingDriver
+class StaticPHPDriver extends CommonStaticPHPDriver
{
- /**
- * Paths of entity directories.
- *
- * @var array
- */
- private $_paths = array();
-
- /**
- * Map of all class names.
- *
- * @var array
- */
- private $_classNames;
-
- /**
- * The file extension of mapping documents.
- *
- * @var string
- */
- 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}
- */
- public function loadMetadataForClass($className, ClassMetadata $metadata)
- {
- call_user_func_array(array($className, 'loadMetadata'), array($metadata));
- }
-
- /**
- * {@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 \RecursiveIteratorIterator(
- new \RecursiveDirectoryIterator($path),
- \RecursiveIteratorIterator::LEAVES_ONLY
- );
-
- foreach ($iterator as $file) {
- if ($file->getBasename($this->_fileExtension) == $file->getBasename()) {
- continue;
- }
-
- $sourceFile = realpath($file->getPathName());
- 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;
- }
-
- /**
- * {@inheritDoc}
- */
- public function isTransient($className)
- {
- return method_exists($className, 'loadMetadata') ? false : true;
- }
-}
+}
2  lib/vendor/doctrine-common
@@ -1 +1 @@
-Subproject commit 8df9cdf3b921a3b59bbba51d5ba9063509ef6a1a
+Subproject commit f7cdf27f04c27ce02e2c14a18ff9064cc37f7284
View
131 tests/Doctrine/Tests/ORM/Mapping/DriverChainTest.php
@@ -1,131 +0,0 @@
-<?php
-
-namespace Doctrine\Tests\ORM\Mapping;
-
-use Doctrine\ORM\Mapping\Driver\DriverChain;
-
-require_once __DIR__ . '/../../TestInit.php';
-
-class DriverChainTest extends \Doctrine\Tests\OrmTestCase
-{
- public function testDelegateToMatchingNamespaceDriver()
- {
- $className = 'Doctrine\Tests\ORM\Mapping\DriverChainEntity';
- $classMetadata = new \Doctrine\ORM\Mapping\ClassMetadata($className);
-
- $chain = new DriverChain();
-
- $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\Common\Persistence\Mapping\Driver\MappingDriver');
- $driver2->expects($this->at(0))
- ->method('loadMetadataForClass')
- ->with($this->equalTo($className), $this->equalTo($classMetadata));
- $driver2->expects($this->at(1))
- ->method('isTransient')
- ->with($this->equalTo($className))
- ->will($this->returnValue( true ));
-
- $chain->addDriver($driver1, 'Doctrine\Tests\Models\Company');
- $chain->addDriver($driver2, 'Doctrine\Tests\ORM\Mapping');
-
- $chain->loadMetadataForClass($className, $classMetadata);
-
- $this->assertTrue( $chain->isTransient($className) );
- }
-
- public function testLoadMetadata_NoDelegatorFound_ThrowsMappingException()
- {
- $className = 'Doctrine\Tests\ORM\Mapping\DriverChainEntity';
- $classMetadata = new \Doctrine\ORM\Mapping\ClassMetadata($className);
-
- $chain = new DriverChain();
-
- $this->setExpectedException('Doctrine\ORM\Mapping\MappingException');
- $chain->loadMetadataForClass($className, $classMetadata);
- }
-
- public function testGatherAllClassNames()
- {
- $className = 'Doctrine\Tests\ORM\Mapping\DriverChainEntity';
- $classMetadata = new \Doctrine\ORM\Mapping\ClassMetadata($className);
-
- $chain = new DriverChain();
-
- $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\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')));
-
- $chain->addDriver($driver1, 'Doctrine\Tests\Models\Company');
- $chain->addDriver($driver2, 'Doctrine\Tests\ORM\Mapping');
-
- $this->assertEquals(array(
- 'Doctrine\Tests\Models\Company\Foo',
- 'Doctrine\Tests\ORM\Mapping\Bar',
- 'Doctrine\Tests\ORM\Mapping\Baz'
- ), $chain->getAllClassNames());
- }
-
- /**
- * @group DDC-706
- */
- public function testIsTransient()
- {
- $chain = new DriverChain();
- $chain->addDriver($this->createAnnotationDriver(), 'Doctrine\Tests\Models\CMS');
-
- $this->assertTrue($chain->isTransient('stdClass'), "stdClass isTransient");
- $this->assertFalse($chain->isTransient('Doctrine\Tests\Models\CMS\CmsUser'), "CmsUser is not Transient");
- }
-
- /**
- * @group DDC-1412
- */
- public function testDefaultDriver()
- {
- $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();
-
- $companyDriver->expects($this->never())
- ->method('loadMetadataForClass');
- $companyDriver->expects($this->once())
- ->method('isTransient')
- ->with($this->equalTo($managerClassName))
- ->will($this->returnValue(false));
-
- $dafaultDriver->expects($this->never())
- ->method('loadMetadataForClass');
- $dafaultDriver->expects($this->once())
- ->method('isTransient')
- ->with($this->equalTo($entityClassName))
- ->will($this->returnValue(true));
-
- $this->assertNull($chain->getDefaultDriver());
-
- $chain->setDefaultDriver($dafaultDriver);
- $chain->addDriver($companyDriver, 'Doctrine\Tests\Models\Company');
-
- $this->assertSame($dafaultDriver, $chain->getDefaultDriver());
-
- $this->assertTrue($chain->isTransient($entityClassName));
- $this->assertFalse($chain->isTransient($managerClassName));
- }
-}
-
-class DriverChainEntity
-{
-
-}
View
4 tests/Doctrine/Tests/ORM/Mapping/PHPMappingDriverTest.php
@@ -3,7 +3,7 @@
namespace Doctrine\Tests\ORM\Mapping;
use Doctrine\ORM\Mapping\ClassMetadata,
- Doctrine\ORM\Mapping\Driver\PHPDriver,
+ Doctrine\Common\Persistence\Mapping\Driver\PHPDriver,
Doctrine\ORM\Tools\Export\ClassMetadataExporter;
require_once __DIR__ . '/../../TestInit.php';
@@ -28,7 +28,7 @@ protected function _loadDriver()
/**
* All class are entitier for php driver
- *
+ *
* @group DDC-889
*/
public function testinvalidEntityOrMappedSuperClassShouldMentionParentClasses()
View
2  tests/Doctrine/Tests/ORM/Mapping/StaticPHPMappingDriverTest.php
@@ -3,7 +3,7 @@
namespace Doctrine\Tests\ORM\Mapping;
use Doctrine\ORM\Mapping\ClassMetadata,
- Doctrine\ORM\Mapping\Driver\StaticPHPDriver,
+ Doctrine\Common\Persistence\Mapping\Driver\StaticPHPDriver,
Doctrine\ORM\Tools\Export\ClassMetadataExporter;
require_once __DIR__ . '/../../TestInit.php';
View
13 tests/Doctrine/Tests/ORM/Tools/Export/AbstractClassMetadataExporterTest.php
@@ -68,15 +68,14 @@ protected function _createEntityManager($metadataDriver)
protected function _createMetadataDriver($type, $path)
{
$mappingDriver = array(
- 'php' => 'PHPDriver',
- 'annotation' => 'AnnotationDriver',
- 'xml' => 'XmlDriver',
- 'yaml' => 'YamlDriver',
+ 'php' => 'Doctrine\Common\Persistence\Mapping\Driver\PHPDriver',
+ 'annotation' => 'Doctrine\ORM\Mapping\Driver\AnnotationDriver',
+ 'xml' => 'Doctrine\ORM\Mapping\Driver\XmlDriver',
+ 'yaml' => 'Doctrine\ORM\Mapping\Driver\YamlDriver',
);
$this->assertArrayHasKey($type, $mappingDriver, "There is no metadata driver for the type '" . $type . "'.");
- $driverName = $mappingDriver[$type];
+ $class = $mappingDriver[$type];
- $class = 'Doctrine\ORM\Mapping\Driver\\' . $driverName;
if ($type === 'annotation') {
$driver = $this->createAnnotationDriver(array($path));
} else {
@@ -388,5 +387,5 @@ class Phonenumber
}
class Group
{
-
+
}
Something went wrong with that request. Please try again.