diff --git a/lib/Doctrine/ORM/Mapping/ClassMetadataFactory.php b/lib/Doctrine/ORM/Mapping/ClassMetadataFactory.php index 9c6167d59..60686bf9d 100644 --- a/lib/Doctrine/ORM/Mapping/ClassMetadataFactory.php +++ b/lib/Doctrine/ORM/Mapping/ClassMetadataFactory.php @@ -102,6 +102,10 @@ class ClassMetadataFactory */ public function getMetadataFor($className) { + if($className[0] == "\\") { + $className = substr($className, 1); + } + if ( ! isset($this->_loadedMetadata[$className])) { $cacheKey = "$className\$CLASSMETADATA"; if ($this->_cacheDriver) { @@ -126,6 +130,10 @@ class ClassMetadataFactory */ public function hasMetadataFor($className) { + if($className[0] == "\\") { + $className = substr($className, 1); + } + return isset($this->_loadedMetadata[$className]); } @@ -139,6 +147,10 @@ class ClassMetadataFactory */ public function setMetadataFor($className, $class) { + if($className[0] == "\\") { + $className = substr($className, 1); + } + $this->_loadedMetadata[$className] = $class; } diff --git a/tests/Doctrine/Tests/Models/Global/GlobalNamespaceModel.php b/tests/Doctrine/Tests/Models/Global/GlobalNamespaceModel.php new file mode 100644 index 000000000..d474832ee --- /dev/null +++ b/tests/Doctrine/Tests/Models/Global/GlobalNamespaceModel.php @@ -0,0 +1,68 @@ +setProxyDir(__DIR__ . '/../../Proxies'); - $config->setProxyNamespace('Doctrine\Tests\Proxies'); - $eventManager = new EventManager(); - $conn = new ConnectionMock(array(), $driverMock, $config, $eventManager); $mockDriver = new MetadataDriverMock(); - $config->setMetadataDriverImpl($mockDriver); - - $entityManager = EntityManagerMock::create($conn, $config, $eventManager); + $entityManager = $this->_createEntityManager($mockDriver); + $conn = $entityManager->getConnection(); $mockPlatform = $conn->getDatabasePlatform(); $mockPlatform->setPrefersSequences(true); $mockPlatform->setPrefersIdentityColumns(false); @@ -65,6 +58,40 @@ class ClassMetadataFactoryTest extends \Doctrine\Tests\OrmTestCase $this->assertTrue($cm1->hasField('name')); $this->assertEquals(ClassMetadata::GENERATOR_TYPE_SEQUENCE, $cm1->generatorType); } + + public function testGetMetadataGlobalNamespaceModel() + { + require_once __DIR__."/../../Models/Global/GlobalNamespaceModel.php"; + + $reader = new \Doctrine\Common\Annotations\AnnotationReader(new \Doctrine\Common\Cache\ArrayCache); + $reader->setDefaultAnnotationNamespace('Doctrine\ORM\Mapping\\'); + $metadataDriver = new \Doctrine\ORM\Mapping\Driver\AnnotationDriver($reader); + $metadataDriver->setClassDirectory(__DIR__."/../../Models/Global/"); + + $entityManager = $this->_createEntityManager($metadataDriver); + + $mf = $entityManager->getMetadataFactory(); + $m1 = $mf->getMetadataFor("DoctrineGlobal_Article"); + $h2 = $mf->hasMetadataFor("\DoctrineGlobal_Article"); + $m2 = $mf->getMetadataFor("\DoctrineGlobal_Article"); + + $this->assertSame($m1, $m2); + $this->assertTrue($h2); + } + + protected function _createEntityManager($metadataDriver) + { + $driverMock = new DriverMock(); + $config = new \Doctrine\ORM\Configuration(); + $config->setProxyDir(__DIR__ . '/../../Proxies'); + $config->setProxyNamespace('Doctrine\Tests\Proxies'); + $eventManager = new EventManager(); + $conn = new ConnectionMock(array(), $driverMock, $config, $eventManager); + $mockDriver = new MetadataDriverMock(); + $config->setMetadataDriverImpl($metadataDriver); + + return EntityManagerMock::create($conn, $config, $eventManager); + } } /* Test subject class with overriden factory method for mocking purposes */