Skip to content

Commit

Permalink
Merge pull request #8820 from beberlei/GH-8818-EntityNamespaceAliasDe…
Browse files Browse the repository at this point in the history
…precation

[GH-8818] Deprecate entity namespace short aliases.
  • Loading branch information
greg0ire authored Aug 5, 2021
2 parents e09f126 + 913700b commit 12705b5
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 1 deletion.
10 changes: 10 additions & 0 deletions UPGRADE.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,16 @@ Overriding this method is not recommended, which is why the method is documented
+ public function toIterable($stmt, ResultSetMapping $resultSetMapping, array $hints = []): iterable
```

## Deprecated: Entity Namespace Aliases

Entity namespace aliases are deprecated, use the magic ::class constant to abbreviate full class names
in EntityManager, EntityRepository and DQL.

```diff
- $entityManager->find('MyBundle:User', $id);
+ $entityManager->find(User::class, $id);
```

# Upgrade to 2.9

## Minor BC BREAK: Setup tool needs cache implementation
Expand Down
1 change: 0 additions & 1 deletion docs/en/reference/dql-doctrine-query-language.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1527,7 +1527,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
7 changes: 7 additions & 0 deletions lib/Doctrine/ORM/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,13 @@ public function addEntityNamespace($alias, $namespace)
*/
public function getEntityNamespace($entityNamespaceAlias)
{
Deprecation::trigger(
'doctrine/orm',
'https://github.com/doctrine/orm/issues/8818',
'Entity short namespace aliases such as "%s" are deprecated, use ::class constant instead.',
$entityNamespaceAlias
);

if (! isset($this->_attributes['entityNamespaces'][$entityNamespaceAlias])) {
throw UnknownEntityNamespace::fromNamespaceAlias($entityNamespaceAlias);
}
Expand Down
5 changes: 5 additions & 0 deletions tests/Doctrine/Tests/ORM/ConfigurationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use Doctrine\Common\Cache\ArrayCache;
use Doctrine\Common\Cache\Cache;
use Doctrine\Common\Proxy\AbstractProxyFactory;
use Doctrine\Deprecations\PHPUnit\VerifyDeprecations;
use Doctrine\ORM\Cache\CacheConfiguration;
use Doctrine\ORM\Cache\Exception\MetadataCacheNotConfigured;
use Doctrine\ORM\Cache\Exception\MetadataCacheUsesNonPersistentCache;
Expand Down Expand Up @@ -39,6 +40,8 @@
*/
class ConfigurationTest extends DoctrineTestCase
{
use VerifyDeprecations;

/** @var Configuration */
private $configuration;

Expand Down Expand Up @@ -111,6 +114,8 @@ public function testNewDefaultAnnotationDriver(): void

public function testSetGetEntityNamespace(): void
{
$this->expectDeprecationWithIdentifier('https://github.com/doctrine/orm/issues/8818');

$this->configuration->addEntityNamespace('TestNamespace', __NAMESPACE__);
self::assertSame(__NAMESPACE__, $this->configuration->getEntityNamespace('TestNamespace'));
$namespaces = ['OtherNamespace' => __NAMESPACE__];
Expand Down

0 comments on commit 12705b5

Please sign in to comment.