From 0424d870999c9fb0a044a8b5773f250376d2368f Mon Sep 17 00:00:00 2001 From: "Roman S. Borschel" Date: Sun, 8 Aug 2010 15:01:03 +0200 Subject: [PATCH] [DDC-386][DDC-675] Fixed. --- lib/Doctrine/ORM/EntityManager.php | 21 +++++++++++++------ lib/Doctrine/ORM/Query/Lexer.php | 2 +- lib/Doctrine/ORM/Query/Parser.php | 2 +- .../ORM/Functional/BasicFunctionalTest.php | 6 ++++-- 4 files changed, 21 insertions(+), 10 deletions(-) diff --git a/lib/Doctrine/ORM/EntityManager.php b/lib/Doctrine/ORM/EntityManager.php index 397ff8938..0cd887fe1 100644 --- a/lib/Doctrine/ORM/EntityManager.php +++ b/lib/Doctrine/ORM/EntityManager.php @@ -25,6 +25,7 @@ use Closure, Exception, Doctrine\DBAL\LockMode, Doctrine\ORM\Mapping\ClassMetadata, Doctrine\ORM\Mapping\ClassMetadataFactory, + Doctrine\ORM\Query\ResultSetMapping, Doctrine\ORM\Proxy\ProxyFactory; /** @@ -225,7 +226,14 @@ class EntityManager } /** - * Returns the metadata for a class. + * Returns the ORM metadata descriptor for a class. + * + * The class name must be the fully-qualified class name without a leading backslash + * (as it is returned by get_class($obj)) or an aliased class name. + * + * Examples: + * MyProject\Domain\User + * sales:PriceRequest * * @return Doctrine\ORM\Mapping\ClassMetadata * @internal Performance-sensitive method. @@ -268,7 +276,7 @@ class EntityManager * @param ResultSetMapping $rsm The ResultSetMapping to use. * @return NativeQuery */ - public function createNativeQuery($sql, \Doctrine\ORM\Query\ResultSetMapping $rsm) + public function createNativeQuery($sql, ResultSetMapping $rsm) { $query = new NativeQuery($this); $query->setSql($sql); @@ -338,7 +346,7 @@ class EntityManager */ public function getReference($entityName, $identifier) { - $class = $this->metadataFactory->getMetadataFor($entityName); + $class = $this->metadataFactory->getMetadataFor(ltrim($entityName, '\\')); // Check identity map first, if its already in there just return it. if ($entity = $this->unitOfWork->tryGetById($identifier, $class->rootEntityName)) { @@ -374,7 +382,7 @@ class EntityManager */ public function getPartialReference($entityName, $identifier) { - $class = $this->metadataFactory->getMetadataFor($entityName); + $class = $this->metadataFactory->getMetadataFor(ltrim($entityName, '\\')); // Check identity map first, if its already in there just return it. if ($entity = $this->unitOfWork->tryGetById($identifier, $class->rootEntityName)) { @@ -534,11 +542,12 @@ class EntityManager /** * Gets the repository for an entity class. * - * @param string $entityName The name of the Entity. - * @return EntityRepository The repository. + * @param string $entityName The name of the entity. + * @return EntityRepository The repository class. */ public function getRepository($entityName) { + $entityName = ltrim($entityName, '\\'); if (isset($this->repositories[$entityName])) { return $this->repositories[$entityName]; } diff --git a/lib/Doctrine/ORM/Query/Lexer.php b/lib/Doctrine/ORM/Query/Lexer.php index 7026f6616..57ffc3ebe 100644 --- a/lib/Doctrine/ORM/Query/Lexer.php +++ b/lib/Doctrine/ORM/Query/Lexer.php @@ -119,7 +119,7 @@ class Lexer extends \Doctrine\Common\Lexer protected function getCatchablePatterns() { return array( - '[a-z_][a-z0-9_\:\\\]*[a-z0-9_]{1}', + '[a-z_\\\][a-z0-9_\:\\\]*[a-z0-9_]{1}', '(?:[0-9]+(?:[\.][0-9]+)*)(?:e[+-]?[0-9]+)?', "'(?:[^']|'')*'", '\?[1-9][0-9]*|:[a-z][a-z0-9_]+' diff --git a/lib/Doctrine/ORM/Query/Parser.php b/lib/Doctrine/ORM/Query/Parser.php index 21a86862d..aeedf47d1 100644 --- a/lib/Doctrine/ORM/Query/Parser.php +++ b/lib/Doctrine/ORM/Query/Parser.php @@ -765,7 +765,7 @@ class Parser { $this->match(Lexer::T_IDENTIFIER); - $schemaName = $this->_lexer->token['value']; + $schemaName = ltrim($this->_lexer->token['value'], '\\'); if (strrpos($schemaName, ':') !== false) { list($namespaceAlias, $simpleClassName) = explode(':', $schemaName); diff --git a/tests/Doctrine/Tests/ORM/Functional/BasicFunctionalTest.php b/tests/Doctrine/Tests/ORM/Functional/BasicFunctionalTest.php index d12a183d9..73a0c65cf 100644 --- a/tests/Doctrine/Tests/ORM/Functional/BasicFunctionalTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/BasicFunctionalTest.php @@ -129,7 +129,7 @@ class BasicFunctionalTest extends \Doctrine\Tests\OrmFunctionalTestCase $this->_em->clear(); - $user2 = $this->_em->createQuery('select u from Doctrine\Tests\Models\CMS\CmsUser u where u.id=?1') + $user2 = $this->_em->createQuery('select u from \Doctrine\Tests\Models\CMS\CmsUser u where u.id=?1') ->setParameter(1, $userId) ->getSingleResult(); @@ -440,7 +440,9 @@ class BasicFunctionalTest extends \Doctrine\Tests\OrmFunctionalTestCase $this->_em->clear(); - $articleNew = $this->_em->find('Doctrine\Tests\Models\CMS\CmsArticle', $articleId); + // test find() with leading backslash at the same time + $articleNew = $this->_em->find('\Doctrine\Tests\Models\CMS\CmsArticle', $articleId); + $this->assertTrue($this->_em->contains($articleNew)); $this->assertEquals("Lorem ipsum dolor sunt.", $articleNew->text); $this->assertNotSame($article, $articleNew);