Skip to content

Commit

Permalink
Deprecate document namespace short aliases
Browse files Browse the repository at this point in the history
  • Loading branch information
franmomu committed Oct 5, 2021
1 parent 38fc494 commit cbe380f
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 0 deletions.
10 changes: 10 additions & 0 deletions UPGRADE-2.3.md
Expand Up @@ -22,3 +22,13 @@ This does not apply to `@Indexes` which is deprecated and can't be used as
Attribute. Use `@Index` and `@UniqueIndex` instead.

`@Inheritance` annotation has been removed as it was never used.

## Deprecated: Document Namespace Aliases

Document namespace aliases are deprecated, use the magic ::class constant to abbreviate full class names
in DocumentManager and DocumentRepository.

```diff
- $documentManager->find('MyBundle:User', $id);
+ $documentManager->find(User::class, $id);
```
1 change: 1 addition & 0 deletions composer.json
Expand Up @@ -27,6 +27,7 @@
"doctrine/annotations": "^1.6",
"doctrine/cache": "^1.11 || ^2.0",
"doctrine/collections": "^1.5",
"doctrine/deprecations": "^0.5.3",
"doctrine/event-manager": "^1.0",
"doctrine/instantiator": "^1.1",
"doctrine/persistence": "^2.2",
Expand Down
8 changes: 8 additions & 0 deletions lib/Doctrine/ODM/MongoDB/Configuration.php
Expand Up @@ -8,6 +8,7 @@
use Doctrine\Common\Cache\Cache;
use Doctrine\Common\Cache\Psr6\CacheAdapter;
use Doctrine\Common\Cache\Psr6\DoctrineProvider;
use Doctrine\Deprecations\Deprecation;
use Doctrine\ODM\MongoDB\Mapping\ClassMetadataFactory;
use Doctrine\ODM\MongoDB\Mapping\Driver\AnnotationDriver;
use Doctrine\ODM\MongoDB\PersistentCollection\DefaultPersistentCollectionFactory;
Expand Down Expand Up @@ -140,6 +141,13 @@ public function addDocumentNamespace(string $alias, string $namespace): void
*/
public function getDocumentNamespace(string $documentNamespaceAlias): string
{
Deprecation::trigger(
'doctrine/mongodb-odm',
'https://github.com/doctrine/mongodb-odm/pull/2374',
'Document short namespace aliases such as "%s" are deprecated, use ::class constant instead.',
$documentNamespaceAlias
);

if (! isset($this->attributes['documentNamespaces'][$documentNamespaceAlias])) {
throw MongoDBException::unknownDocumentNamespace($documentNamespaceAlias);
}
Expand Down

0 comments on commit cbe380f

Please sign in to comment.