1
0
mirror of synced 2024-12-14 07:06:04 +03:00

support namespace alias

This commit is contained in:
Fabio B. Silva 2012-08-14 21:02:52 -03:00
parent 1bd6e841bf
commit 7c754e495e
2 changed files with 63 additions and 0 deletions

View File

@ -1715,6 +1715,13 @@ class Parser
$token = $this->lexer->token;
$className = $token['value'];
if (strrpos($className, ':') !== false) {
list($namespaceAlias, $simpleClassName) = explode(':', $className);
$className = $this->em->getConfiguration()
->getEntityNamespace($namespaceAlias) . '\\' . $simpleClassName;
}
$this->match(Lexer::T_OPEN_PARENTHESIS);
$args[] = $this->NewObjectArg();

View File

@ -153,6 +153,62 @@ class NewOperatorTest extends \Doctrine\Tests\OrmFunctionalTestCase
$this->assertInstanceOf('Doctrine\Tests\Models\CMS\CmsUserDTO', $result[2]);
}
public function testShouldSupportFromEntityNamespaceAlias()
{
$dql = "
SELECT
new CmsUserDTO(u.name, e.email, a.city)
FROM
cms:CmsUser u
JOIN
u.email e
JOIN
u.address a
ORDER BY
u.name";
$this->_em->getConfiguration()
->addEntityNamespace('cms', 'Doctrine\Tests\Models\CMS');
$query = $this->_em->createQuery($dql);
$result = $query->getResult();
$this->assertCount(3, $result);
$this->assertInstanceOf('Doctrine\Tests\Models\CMS\CmsUserDTO', $result[0]);
$this->assertInstanceOf('Doctrine\Tests\Models\CMS\CmsUserDTO', $result[1]);
$this->assertInstanceOf('Doctrine\Tests\Models\CMS\CmsUserDTO', $result[2]);
}
public function testShouldSupportValueObjectNamespaceAlias()
{
$dql = "
SELECT
new cms:CmsUserDTO(u.name, e.email, a.city)
FROM
cms:CmsUser u
JOIN
u.email e
JOIN
u.address a
ORDER BY
u.name";
$this->_em->getConfiguration()
->addEntityNamespace('cms', 'Doctrine\Tests\Models\CMS');
$query = $this->_em->createQuery($dql);
$result = $query->getResult();
$this->assertCount(3, $result);
$this->assertInstanceOf('Doctrine\Tests\Models\CMS\CmsUserDTO', $result[0]);
$this->assertInstanceOf('Doctrine\Tests\Models\CMS\CmsUserDTO', $result[1]);
$this->assertInstanceOf('Doctrine\Tests\Models\CMS\CmsUserDTO', $result[2]);
}
public function testShouldSupportLiteralExpression()
{
$dql = "