Skip to content

Commit

Permalink
Remove support for entity namespace aliases
Browse files Browse the repository at this point in the history
  • Loading branch information
Majkl578 committed Jan 11, 2018
1 parent a0071b1 commit 63cb801
Show file tree
Hide file tree
Showing 18 changed files with 20 additions and 428 deletions.
14 changes: 14 additions & 0 deletions UPGRADE.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,19 @@
# Upgrade to 3.0

## BC Break: Removed support for entity namespace aliases

The support for namespace aliases has been removed.
Please migrate to using `::class` for referencing classes.

These methods have been removed:

* `Doctrine\ORM\Configuration::addEntityNamespace()`
* `Doctrine\ORM\Configuration::getEntityNamespace()`
* `Doctrine\ORM\Configuration::setEntityNamespaces()`
* `Doctrine\ORM\Configuration::getEntityNamespaces()`
* `Doctrine\ORM\Mapping\AbstractClassMetadataFactory::getFqcnFromAlias()`
* `Doctrine\ORM\ORMException::unknownEntityNamespace()`

## BC Break: Removed same-namespace class name resolution

Support for same-namespace class name resolution in mappings has been removed.
Expand Down
3 changes: 1 addition & 2 deletions docs/en/reference/dql-doctrine-query-language.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1462,7 +1462,6 @@ Terminals

- identifier (name, email, ...) must match ``[a-z_][a-z0-9_]*``
- fully_qualified_name (Doctrine\Tests\Models\CMS\CmsUser) matches PHP's fully qualified class names
- aliased_name (CMS:CmsUser) uses two identifiers, one for the namespace alias and one for the class inside it
- string ('foo', 'bar''s house', '%ninja%', ...)
- char ('/', '\\', ' ', ...)
- integer (-1, 0, 1, 34, ...)
Expand Down Expand Up @@ -1497,7 +1496,7 @@ Identifiers
AliasIdentificationVariable :: = identifier
/* identifier that must be a class name (the "User" of "FROM User u"), possibly as a fully qualified class name or namespace-aliased */
AbstractSchemaName ::= fully_qualified_name | aliased_name | identifier
AbstractSchemaName ::= fully_qualified_name | identifier
/* Alias ResultVariable declaration (the "total" of "COUNT(*) AS total") */
AliasResultVariable = identifier
Expand Down
14 changes: 0 additions & 14 deletions lib/Doctrine/ORM/AbstractQuery.php
Original file line number Diff line number Diff line change
Expand Up @@ -405,7 +405,6 @@ public function processParameterValue($value)
*/
public function setResultSetMapping(Query\ResultSetMapping $rsm)
{
$this->translateNamespaces($rsm);
$this->resultSetMapping = $rsm;

return $this;
Expand All @@ -421,19 +420,6 @@ protected function getResultSetMapping()
return $this->resultSetMapping;
}

/**
* Allows to translate entity namespaces to full qualified names.
*/
private function translateNamespaces(Query\ResultSetMapping $rsm)
{
$translate = function ($alias) {
return $this->em->getClassMetadata($alias)->getClassName();
};

$rsm->aliasMap = array_map($translate, $rsm->aliasMap);
$rsm->declaringClasses = array_map($translate, $rsm->declaringClasses);
}

/**
* Set a cache profile for hydration caching.
*
Expand Down
47 changes: 0 additions & 47 deletions lib/Doctrine/ORM/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,6 @@ class Configuration extends DBALConfiguration
*/
private $metadataCache;

/**
* @var string[] indexed by alias
*/
private $entityNamespaces = [];

/**
* @var string[] of DQL, indexed by query name
*/
Expand Down Expand Up @@ -211,48 +206,6 @@ public function newDefaultAnnotationDriver(array $paths = []) : AnnotationDriver
return new AnnotationDriver($reader, $paths);
}

/**
* Adds a namespace under a certain alias.
*/
public function addEntityNamespace(string $alias, string $namespace) : void
{
$this->entityNamespaces[$alias] = $namespace;
}

/**
* Resolves a registered namespace alias to the full namespace.
*
* @throws ORMException
*/
public function getEntityNamespace(string $entityNamespaceAlias) : string
{
if (! isset($this->entityNamespaces[$entityNamespaceAlias])) {
throw ORMException::unknownEntityNamespace($entityNamespaceAlias);
}

return trim($this->entityNamespaces[$entityNamespaceAlias], '\\');
}

/**
* Sets the entity alias map.
*
* @param string[] $entityNamespaces indexed by namespace alias
*/
public function setEntityNamespaces(array $entityNamespaces) : void
{
$this->entityNamespaces = $entityNamespaces;
}

/**
* Retrieves the list of registered entity namespace aliases.
*
* @return string[] indexed by namespace alias
*/
public function getEntityNamespaces() : array
{
return $this->entityNamespaces;
}

/**
* Gets the cache driver implementation that is used for the mapping metadata.
*/
Expand Down
14 changes: 0 additions & 14 deletions lib/Doctrine/ORM/Mapping/AbstractClassMetadataFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -307,12 +307,6 @@ protected function onNotFoundMetadata(

private function normalizeClassName(string $className) : string
{
if (strpos($className, ':') !== false) {
[$namespaceAlias, $simpleClassName] = explode(':', $className, 2);

return $this->getFqcnFromAlias($namespaceAlias, $simpleClassName);
}

return StaticClassNameConverter::getRealClass($className);
}

Expand All @@ -322,14 +316,6 @@ private function normalizeClassName(string $className) : string
*/
abstract protected function initialize() : void;

/**
* Gets the fully qualified class-name from the namespace alias.
*
* @param string $namespaceAlias
* @param string $simpleClassName
*/
abstract protected function getFqcnFromAlias($namespaceAlias, $simpleClassName) : string;

/**
* Returns the mapping driver implementation.
*/
Expand Down
8 changes: 0 additions & 8 deletions lib/Doctrine/ORM/Mapping/ClassMetadataFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -518,14 +518,6 @@ private function completeFieldIdentifierGeneratorMapping(FieldMetadata $field)
}
}

/**
* {@inheritDoc}
*/
protected function getFqcnFromAlias($namespaceAlias, $simpleClassName) : string
{
return $this->em->getConfiguration()->getEntityNamespace($namespaceAlias) . '\\' . $simpleClassName;
}

/**
* {@inheritDoc}
*/
Expand Down
10 changes: 0 additions & 10 deletions lib/Doctrine/ORM/ORMException.php
Original file line number Diff line number Diff line change
Expand Up @@ -252,16 +252,6 @@ public static function proxyClassesAlwaysRegenerating()
return new self('Proxy Classes are always regenerating.');
}

/**
* @param string $entityNamespaceAlias
*
* @return ORMException
*/
public static function unknownEntityNamespace($entityNamespaceAlias)
{
return new self(sprintf("Unknown Entity namespace alias '%s'.", $entityNamespaceAlias));
}

/**
* @param string $className
*
Expand Down
18 changes: 5 additions & 13 deletions lib/Doctrine/ORM/Query/Parser.php
Original file line number Diff line number Diff line change
Expand Up @@ -914,7 +914,7 @@ public function AliasIdentificationVariable()
}

/**
* AbstractSchemaName ::= fully_qualified_name | aliased_name | identifier
* AbstractSchemaName ::= fully_qualified_name | identifier
*
* @return string
*/
Expand All @@ -923,20 +923,12 @@ public function AbstractSchemaName()
if ($this->lexer->isNextToken(Lexer::T_FULLY_QUALIFIED_NAME)) {
$this->match(Lexer::T_FULLY_QUALIFIED_NAME);

$schemaName = $this->lexer->token['value'];
} elseif ($this->lexer->isNextToken(Lexer::T_IDENTIFIER)) {
$this->match(Lexer::T_IDENTIFIER);

$schemaName = $this->lexer->token['value'];
} else {
$this->match(Lexer::T_ALIASED_NAME);

list($namespaceAlias, $simpleClassName) = explode(':', $this->lexer->token['value']);

$schemaName = $this->em->getConfiguration()->getEntityNamespace($namespaceAlias) . '\\' . $simpleClassName;
return $this->lexer->token['value'];
}

return $schemaName;
$this->match(Lexer::T_IDENTIFIER);

return $this->lexer->token['value'];
}

/**
Expand Down
11 changes: 0 additions & 11 deletions tests/Doctrine/Tests/ORM/ConfigurationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,17 +66,6 @@ public function testNewDefaultAnnotationDriver()
self::assertInstanceOf(AnnotationNamespace\PrePersist::class, $annotation);
}

public function testSetGetEntityNamespace()
{
$this->configuration->addEntityNamespace('TestNamespace', __NAMESPACE__);
self::assertSame(__NAMESPACE__, $this->configuration->getEntityNamespace('TestNamespace'));
$namespaces = ['OtherNamespace' => __NAMESPACE__];
$this->configuration->setEntityNamespaces($namespaces);
self::assertSame($namespaces, $this->configuration->getEntityNamespaces());
$this->expectException(ORMException::class);
$this->configuration->getEntityNamespace('NonExistingNamespace');
}

public function testSetGetQueryCacheImpl()
{
self::assertNull($this->configuration->getQueryCacheImpl()); // defaults
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,6 @@ protected function setUp()
parent::setUp();
}

public function tearDown()
{
if ($this->em) {
$this->em->getConfiguration()->setEntityNamespaces([]);
}
parent::tearDown();
}

public function loadFixture()
{
$today = new DateTimeModel();
Expand Down
37 changes: 0 additions & 37 deletions tests/Doctrine/Tests/ORM/Functional/EntityRepositoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,6 @@ protected function setUp()
parent::setUp();
}

public function tearDown()
{
if ($this->em) {
$this->em->getConfiguration()->setEntityNamespaces([]);
}
parent::tearDown();
}

public function loadFixture()
{
$user = new CmsUser;
Expand Down Expand Up @@ -261,19 +253,6 @@ public function testFindAll()
self::assertCount(4, $users);
}

public function testFindByAlias()
{
$user1Id = $this->loadFixture();
$repos = $this->em->getRepository(CmsUser::class);

$this->em->getConfiguration()->addEntityNamespace('CMS', 'Doctrine\Tests\Models\CMS');

$repos = $this->em->getRepository('CMS:CmsUser');

$users = $repos->findAll();
self::assertCount(4, $users);
}

public function testCount()
{
$this->loadFixture();
Expand Down Expand Up @@ -647,22 +626,6 @@ public function testSetDefaultRepositoryInvalidClassError()
$this->em->getConfiguration()->setDefaultRepositoryClassName(DDC753InvalidRepository::class);
}

/**
* @group DDC-3257
*/
public function testSingleRepositoryInstanceForDifferentEntityAliases()
{
$config = $this->em->getConfiguration();

$config->addEntityNamespace('Aliased', 'Doctrine\Tests\Models\CMS');
$config->addEntityNamespace('AliasedAgain', 'Doctrine\Tests\Models\CMS');

$repository = $this->em->getRepository(CmsUser::class);

self::assertSame($repository, $this->em->getRepository('Aliased:CmsUser'));
self::assertSame($repository, $this->em->getRepository('AliasedAgain:CmsUser'));
}

/**
* @group DDC-3257
*/
Expand Down
56 changes: 0 additions & 56 deletions tests/Doctrine/Tests/ORM/Functional/NewOperatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -210,62 +210,6 @@ public function testShouldAssumeFromEntityNamespaceWhenNotGiven()
self::assertInstanceOf(CmsUserDTO::class, $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();

self::assertCount(3, $result);

self::assertInstanceOf(CmsUserDTO::class, $result[0]);
self::assertInstanceOf(CmsUserDTO::class, $result[1]);
self::assertInstanceOf(CmsUserDTO::class, $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();

self::assertCount(3, $result);

self::assertInstanceOf(CmsUserDTO::class, $result[0]);
self::assertInstanceOf(CmsUserDTO::class, $result[1]);
self::assertInstanceOf(CmsUserDTO::class, $result[2]);
}

public function testShouldSupportLiteralExpression()
{
$dql = "
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,6 @@ protected function setUp()
parent::setUp();
}

public function tearDown()
{
if ($this->em) {
$this->em->getConfiguration()->setEntityNamespaces([]);
}
parent::tearDown();
}

public function loadTweetFixture()
{
$author = new TweetUser();
Expand Down
Loading

0 comments on commit 63cb801

Please sign in to comment.