Skip to content

Commit 63cb801

Browse files
committed
Remove support for entity namespace aliases
1 parent a0071b1 commit 63cb801

18 files changed

+20
-428
lines changed

UPGRADE.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,19 @@
11
# Upgrade to 3.0
22

3+
## BC Break: Removed support for entity namespace aliases
4+
5+
The support for namespace aliases has been removed.
6+
Please migrate to using `::class` for referencing classes.
7+
8+
These methods have been removed:
9+
10+
* `Doctrine\ORM\Configuration::addEntityNamespace()`
11+
* `Doctrine\ORM\Configuration::getEntityNamespace()`
12+
* `Doctrine\ORM\Configuration::setEntityNamespaces()`
13+
* `Doctrine\ORM\Configuration::getEntityNamespaces()`
14+
* `Doctrine\ORM\Mapping\AbstractClassMetadataFactory::getFqcnFromAlias()`
15+
* `Doctrine\ORM\ORMException::unknownEntityNamespace()`
16+
317
## BC Break: Removed same-namespace class name resolution
418

519
Support for same-namespace class name resolution in mappings has been removed.

docs/en/reference/dql-doctrine-query-language.rst

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1462,7 +1462,6 @@ Terminals
14621462

14631463
- identifier (name, email, ...) must match ``[a-z_][a-z0-9_]*``
14641464
- fully_qualified_name (Doctrine\Tests\Models\CMS\CmsUser) matches PHP's fully qualified class names
1465-
- aliased_name (CMS:CmsUser) uses two identifiers, one for the namespace alias and one for the class inside it
14661465
- string ('foo', 'bar''s house', '%ninja%', ...)
14671466
- char ('/', '\\', ' ', ...)
14681467
- integer (-1, 0, 1, 34, ...)
@@ -1497,7 +1496,7 @@ Identifiers
14971496
AliasIdentificationVariable :: = identifier
14981497
14991498
/* identifier that must be a class name (the "User" of "FROM User u"), possibly as a fully qualified class name or namespace-aliased */
1500-
AbstractSchemaName ::= fully_qualified_name | aliased_name | identifier
1499+
AbstractSchemaName ::= fully_qualified_name | identifier
15011500
15021501
/* Alias ResultVariable declaration (the "total" of "COUNT(*) AS total") */
15031502
AliasResultVariable = identifier

lib/Doctrine/ORM/AbstractQuery.php

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -405,7 +405,6 @@ public function processParameterValue($value)
405405
*/
406406
public function setResultSetMapping(Query\ResultSetMapping $rsm)
407407
{
408-
$this->translateNamespaces($rsm);
409408
$this->resultSetMapping = $rsm;
410409

411410
return $this;
@@ -421,19 +420,6 @@ protected function getResultSetMapping()
421420
return $this->resultSetMapping;
422421
}
423422

424-
/**
425-
* Allows to translate entity namespaces to full qualified names.
426-
*/
427-
private function translateNamespaces(Query\ResultSetMapping $rsm)
428-
{
429-
$translate = function ($alias) {
430-
return $this->em->getClassMetadata($alias)->getClassName();
431-
};
432-
433-
$rsm->aliasMap = array_map($translate, $rsm->aliasMap);
434-
$rsm->declaringClasses = array_map($translate, $rsm->declaringClasses);
435-
}
436-
437423
/**
438424
* Set a cache profile for hydration caching.
439425
*

lib/Doctrine/ORM/Configuration.php

Lines changed: 0 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -62,11 +62,6 @@ class Configuration extends DBALConfiguration
6262
*/
6363
private $metadataCache;
6464

65-
/**
66-
* @var string[] indexed by alias
67-
*/
68-
private $entityNamespaces = [];
69-
7065
/**
7166
* @var string[] of DQL, indexed by query name
7267
*/
@@ -211,48 +206,6 @@ public function newDefaultAnnotationDriver(array $paths = []) : AnnotationDriver
211206
return new AnnotationDriver($reader, $paths);
212207
}
213208

214-
/**
215-
* Adds a namespace under a certain alias.
216-
*/
217-
public function addEntityNamespace(string $alias, string $namespace) : void
218-
{
219-
$this->entityNamespaces[$alias] = $namespace;
220-
}
221-
222-
/**
223-
* Resolves a registered namespace alias to the full namespace.
224-
*
225-
* @throws ORMException
226-
*/
227-
public function getEntityNamespace(string $entityNamespaceAlias) : string
228-
{
229-
if (! isset($this->entityNamespaces[$entityNamespaceAlias])) {
230-
throw ORMException::unknownEntityNamespace($entityNamespaceAlias);
231-
}
232-
233-
return trim($this->entityNamespaces[$entityNamespaceAlias], '\\');
234-
}
235-
236-
/**
237-
* Sets the entity alias map.
238-
*
239-
* @param string[] $entityNamespaces indexed by namespace alias
240-
*/
241-
public function setEntityNamespaces(array $entityNamespaces) : void
242-
{
243-
$this->entityNamespaces = $entityNamespaces;
244-
}
245-
246-
/**
247-
* Retrieves the list of registered entity namespace aliases.
248-
*
249-
* @return string[] indexed by namespace alias
250-
*/
251-
public function getEntityNamespaces() : array
252-
{
253-
return $this->entityNamespaces;
254-
}
255-
256209
/**
257210
* Gets the cache driver implementation that is used for the mapping metadata.
258211
*/

lib/Doctrine/ORM/Mapping/AbstractClassMetadataFactory.php

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -307,12 +307,6 @@ protected function onNotFoundMetadata(
307307

308308
private function normalizeClassName(string $className) : string
309309
{
310-
if (strpos($className, ':') !== false) {
311-
[$namespaceAlias, $simpleClassName] = explode(':', $className, 2);
312-
313-
return $this->getFqcnFromAlias($namespaceAlias, $simpleClassName);
314-
}
315-
316310
return StaticClassNameConverter::getRealClass($className);
317311
}
318312

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

325-
/**
326-
* Gets the fully qualified class-name from the namespace alias.
327-
*
328-
* @param string $namespaceAlias
329-
* @param string $simpleClassName
330-
*/
331-
abstract protected function getFqcnFromAlias($namespaceAlias, $simpleClassName) : string;
332-
333319
/**
334320
* Returns the mapping driver implementation.
335321
*/

lib/Doctrine/ORM/Mapping/ClassMetadataFactory.php

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -518,14 +518,6 @@ private function completeFieldIdentifierGeneratorMapping(FieldMetadata $field)
518518
}
519519
}
520520

521-
/**
522-
* {@inheritDoc}
523-
*/
524-
protected function getFqcnFromAlias($namespaceAlias, $simpleClassName) : string
525-
{
526-
return $this->em->getConfiguration()->getEntityNamespace($namespaceAlias) . '\\' . $simpleClassName;
527-
}
528-
529521
/**
530522
* {@inheritDoc}
531523
*/

lib/Doctrine/ORM/ORMException.php

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -252,16 +252,6 @@ public static function proxyClassesAlwaysRegenerating()
252252
return new self('Proxy Classes are always regenerating.');
253253
}
254254

255-
/**
256-
* @param string $entityNamespaceAlias
257-
*
258-
* @return ORMException
259-
*/
260-
public static function unknownEntityNamespace($entityNamespaceAlias)
261-
{
262-
return new self(sprintf("Unknown Entity namespace alias '%s'.", $entityNamespaceAlias));
263-
}
264-
265255
/**
266256
* @param string $className
267257
*

lib/Doctrine/ORM/Query/Parser.php

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -914,7 +914,7 @@ public function AliasIdentificationVariable()
914914
}
915915

916916
/**
917-
* AbstractSchemaName ::= fully_qualified_name | aliased_name | identifier
917+
* AbstractSchemaName ::= fully_qualified_name | identifier
918918
*
919919
* @return string
920920
*/
@@ -923,20 +923,12 @@ public function AbstractSchemaName()
923923
if ($this->lexer->isNextToken(Lexer::T_FULLY_QUALIFIED_NAME)) {
924924
$this->match(Lexer::T_FULLY_QUALIFIED_NAME);
925925

926-
$schemaName = $this->lexer->token['value'];
927-
} elseif ($this->lexer->isNextToken(Lexer::T_IDENTIFIER)) {
928-
$this->match(Lexer::T_IDENTIFIER);
929-
930-
$schemaName = $this->lexer->token['value'];
931-
} else {
932-
$this->match(Lexer::T_ALIASED_NAME);
933-
934-
list($namespaceAlias, $simpleClassName) = explode(':', $this->lexer->token['value']);
935-
936-
$schemaName = $this->em->getConfiguration()->getEntityNamespace($namespaceAlias) . '\\' . $simpleClassName;
926+
return $this->lexer->token['value'];
937927
}
938928

939-
return $schemaName;
929+
$this->match(Lexer::T_IDENTIFIER);
930+
931+
return $this->lexer->token['value'];
940932
}
941933

942934
/**

tests/Doctrine/Tests/ORM/ConfigurationTest.php

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -66,17 +66,6 @@ public function testNewDefaultAnnotationDriver()
6666
self::assertInstanceOf(AnnotationNamespace\PrePersist::class, $annotation);
6767
}
6868

69-
public function testSetGetEntityNamespace()
70-
{
71-
$this->configuration->addEntityNamespace('TestNamespace', __NAMESPACE__);
72-
self::assertSame(__NAMESPACE__, $this->configuration->getEntityNamespace('TestNamespace'));
73-
$namespaces = ['OtherNamespace' => __NAMESPACE__];
74-
$this->configuration->setEntityNamespaces($namespaces);
75-
self::assertSame($namespaces, $this->configuration->getEntityNamespaces());
76-
$this->expectException(ORMException::class);
77-
$this->configuration->getEntityNamespace('NonExistingNamespace');
78-
}
79-
8069
public function testSetGetQueryCacheImpl()
8170
{
8271
self::assertNull($this->configuration->getQueryCacheImpl()); // defaults

tests/Doctrine/Tests/ORM/Functional/EntityRepositoryCriteriaTest.php

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,6 @@ protected function setUp()
2323
parent::setUp();
2424
}
2525

26-
public function tearDown()
27-
{
28-
if ($this->em) {
29-
$this->em->getConfiguration()->setEntityNamespaces([]);
30-
}
31-
parent::tearDown();
32-
}
33-
3426
public function loadFixture()
3527
{
3628
$today = new DateTimeModel();

0 commit comments

Comments
 (0)