Merge pull request #397 from Ocramius/cleanup/removing-deprecated-metadata-drivers
Cleanup/removing deprecated metadata drivers
This commit is contained in:
commit
e0455b5550
@ -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
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
@ -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;
|
||||
}
|
||||
}
|
@ -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
vendored
2
lib/vendor/doctrine-common
vendored
@ -1 +1 @@
|
||||
Subproject commit 8df9cdf3b921a3b59bbba51d5ba9063509ef6a1a
|
||||
Subproject commit f7cdf27f04c27ce02e2c14a18ff9064cc37f7284
|
@ -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
|
||||
{
|
||||
|
||||
}
|
@ -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 @@ class PHPMappingDriverTest extends AbstractMappingDriverTest
|
||||
|
||||
/**
|
||||
* All class are entitier for php driver
|
||||
*
|
||||
*
|
||||
* @group DDC-889
|
||||
*/
|
||||
public function testinvalidEntityOrMappedSuperClassShouldMentionParentClasses()
|
||||
|
@ -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';
|
||||
|
@ -68,15 +68,14 @@ abstract class AbstractClassMetadataExporterTest extends \Doctrine\Tests\OrmTest
|
||||
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
|
||||
{
|
||||
|
||||
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user