Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[GH-8818] Deprecate entity namespace short aliases. #8820

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions UPGRADE.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,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__);
$this->assertSame(__NAMESPACE__, $this->configuration->getEntityNamespace('TestNamespace'));
$namespaces = ['OtherNamespace' => __NAMESPACE__];
Expand Down