Fix DDC-1412
This commit is contained in:
parent
1d46d2b9af
commit
0fce3c8f97
@ -39,7 +39,34 @@ class DriverChain implements Driver
|
|||||||
/**
|
/**
|
||||||
* @var array
|
* @var array
|
||||||
*/
|
*/
|
||||||
private $_drivers = array();
|
private $drivers = array();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The default driver
|
||||||
|
*
|
||||||
|
* @var Driver
|
||||||
|
*/
|
||||||
|
private $defaultDriver;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the default driver.
|
||||||
|
*
|
||||||
|
* @return Driver
|
||||||
|
*/
|
||||||
|
public function getDefaultDriver()
|
||||||
|
{
|
||||||
|
return $this->defaultDriver;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the default driver.
|
||||||
|
*
|
||||||
|
* @param Driver $driver
|
||||||
|
*/
|
||||||
|
public function setDefaultDriver(Driver $driver)
|
||||||
|
{
|
||||||
|
$this->defaultDriver = $driver;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add a nested driver.
|
* Add a nested driver.
|
||||||
@ -49,7 +76,7 @@ class DriverChain implements Driver
|
|||||||
*/
|
*/
|
||||||
public function addDriver(Driver $nestedDriver, $namespace)
|
public function addDriver(Driver $nestedDriver, $namespace)
|
||||||
{
|
{
|
||||||
$this->_drivers[$namespace] = $nestedDriver;
|
$this->drivers[$namespace] = $nestedDriver;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -59,7 +86,7 @@ class DriverChain implements Driver
|
|||||||
*/
|
*/
|
||||||
public function getDrivers()
|
public function getDrivers()
|
||||||
{
|
{
|
||||||
return $this->_drivers;
|
return $this->drivers;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -70,13 +97,18 @@ class DriverChain implements Driver
|
|||||||
*/
|
*/
|
||||||
public function loadMetadataForClass($className, ClassMetadataInfo $metadata)
|
public function loadMetadataForClass($className, ClassMetadataInfo $metadata)
|
||||||
{
|
{
|
||||||
foreach ($this->_drivers as $namespace => $driver) {
|
foreach ($this->drivers as $namespace => $driver) {
|
||||||
if (strpos($className, $namespace) === 0) {
|
if (strpos($className, $namespace) === 0) {
|
||||||
$driver->loadMetadataForClass($className, $metadata);
|
$driver->loadMetadataForClass($className, $metadata);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ($this->defaultDriver !== null) {
|
||||||
|
$this->defaultDriver->loadMetadataForClass($className, $metadata);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
throw MappingException::classIsNotAValidEntityOrMappedSuperClass($className);
|
throw MappingException::classIsNotAValidEntityOrMappedSuperClass($className);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -89,7 +121,7 @@ class DriverChain implements Driver
|
|||||||
{
|
{
|
||||||
$classNames = array();
|
$classNames = array();
|
||||||
$driverClasses = array();
|
$driverClasses = array();
|
||||||
foreach ($this->_drivers AS $namespace => $driver) {
|
foreach ($this->drivers AS $namespace => $driver) {
|
||||||
$oid = spl_object_hash($driver);
|
$oid = spl_object_hash($driver);
|
||||||
if (!isset($driverClasses[$oid])) {
|
if (!isset($driverClasses[$oid])) {
|
||||||
$driverClasses[$oid] = $driver->getAllClassNames();
|
$driverClasses[$oid] = $driver->getAllClassNames();
|
||||||
@ -114,12 +146,16 @@ class DriverChain implements Driver
|
|||||||
*/
|
*/
|
||||||
public function isTransient($className)
|
public function isTransient($className)
|
||||||
{
|
{
|
||||||
foreach ($this->_drivers AS $namespace => $driver) {
|
foreach ($this->drivers AS $namespace => $driver) {
|
||||||
if (strpos($className, $namespace) === 0) {
|
if (strpos($className, $namespace) === 0) {
|
||||||
return $driver->isTransient($className);
|
return $driver->isTransient($className);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ($this->defaultDriver !== null) {
|
||||||
|
return $this->defaultDriver->isTransient($className);
|
||||||
|
}
|
||||||
|
|
||||||
// class isTransient, i.e. not an entity or mapped superclass
|
// class isTransient, i.e. not an entity or mapped superclass
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -88,6 +88,42 @@ class DriverChainTest extends \Doctrine\Tests\OrmTestCase
|
|||||||
$this->assertTrue($chain->isTransient('stdClass'), "stdClass isTransient");
|
$this->assertTrue($chain->isTransient('stdClass'), "stdClass isTransient");
|
||||||
$this->assertFalse($chain->isTransient('Doctrine\Tests\Models\CMS\CmsUser'), "CmsUser is not Transient");
|
$this->assertFalse($chain->isTransient('Doctrine\Tests\Models\CMS\CmsUser'), "CmsUser is not Transient");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @group DDC-1412
|
||||||
|
*/
|
||||||
|
public function testDefaultDriver()
|
||||||
|
{
|
||||||
|
$companyDriver = $this->getMock('Doctrine\ORM\Mapping\Driver\Driver');
|
||||||
|
$dafaultDriver = $this->getMock('Doctrine\ORM\Mapping\Driver\Driver');
|
||||||
|
$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
|
class DriverChainEntity
|
||||||
|
Loading…
Reference in New Issue
Block a user