Skip to content

Conversation

@GromNaN
Copy link
Member

@GromNaN GromNaN commented Nov 25, 2025

Q A
Type improvement
BC Break no (deprecation)
Fixed issues Related #2931

Summary

  • Move the classes from Doctrine\ODM\MongoDB\Mapping\Annotations to Doctrine\ODM\MongoDB\Mapping\Attribute. Removing the @Annotation so that they can't be used for legacy annotations.
  • For the classes in the Annotations namespace, they extend those from the Attribute namespace. Adding the legacy @Annotation for BC.
  • The EncryptQuery enum is moved to the parent Doctrine\ODM\MongoDB\Mapping namespace
  • The abstract annotation classes are aliased to the new abstract attribute classes, so that it's not breaking type comparison
  • Documentation updated

Related initiative in Symfony: symfony/symfony#51381

@GromNaN GromNaN added this to the 2.16.0 milestone Nov 25, 2025
@GromNaN
Copy link
Member Author

GromNaN commented Nov 25, 2025

This will force users to migrate without offering anything in return, except for consistency in the namespace with other projects (and not yet ORM). We can only do this if ORM also decides to do so.

@GromNaN
Copy link
Member Author

GromNaN commented Nov 25, 2025

In fact, ORM don't have this subnamespace (example: Doctrine\ORM\Mapping\Entity). So, we should consider whether we want to keep the namespace or move all the attribute classes to Doctrine\ODM\MongoDB\Mapping.
@alcaeus you had the idea that we should use the attribute classes as model classes for all the class metadata. In that case, that would make sense to remove the subnamespace Attribute.

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR modernizes the MongoDB ODM library's attribute system by moving attribute classes from the Annotations namespace to the new Attribute namespace. The old Annotations namespace is maintained as a deprecated alias to ensure backward compatibility while guiding users toward the new naming convention.

Key Changes:

  • Introduced new Doctrine\ODM\MongoDB\Mapping\Attribute namespace for all attribute classes
  • Added deprecation triggers when old Annotations namespace classes are loaded
  • Updated all test files and internal references to use the new namespace
  • Maintained backward compatibility through class aliases

Reviewed changes

Copilot reviewed 300 out of 434 changed files in this pull request and generated 11 comments.

Show a summary per file
File Description
src/Mapping/Attribute/*.php New attribute classes in the Attribute namespace with class aliases to Annotations namespace for backward compatibility
src/Mapping/Annotations/*.php Converted to deprecation stubs that trigger warnings and load the new Attribute classes
tests/**/*.php Updated import statements from Annotations to Attribute namespace
src/Mapping/Driver/*.php Updated internal references to use new Attribute namespace
src/Mapping/ClassMetadata.php Updated type hints to reference Attribute namespace
UPGRADE-2.16.md Added migration guide for the namespace change
phpstan-baseline.neon Updated static analysis baseline with new namespace references

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@GromNaN GromNaN force-pushed the attribute-namespace branch from 71eff05 to 5e39484 Compare November 30, 2025 17:01
Copy link
Member

@malarzm malarzm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can't quite grasp it, but there's a "class_alias was problematic in the past" dangling in my head. Saying it out loud in case I'd jog somebody's memory with it. Alernative would be to:

  1. Move classes to Attributes (and drop final, leave it as a phpdoc)
  2. Classes in Annotations would extend their counterpart, emit a deprecation in ctor and forward everything
  3. Remove Annotations/* in 3.0 and bring back final in Attribute/*

Also I'd like to see docs updated for 2.16 - folks copying documentation should not be greeted by a deprecation :)

@greg0ire
Copy link
Member

greg0ire commented Dec 8, 2025

I can't quite grasp it, but there's a "class_alias was problematic in the past" dangling in my head. Saying it out loud in case I'd jog somebody's memory with it.

@malarzm I wrote an article about that, and @alcaeus wrote a medium article about the aftermath of doing this for doctrine/persistence as well.

@malarzm
Copy link
Member

malarzm commented Dec 8, 2025

@greg0ire ha! Thanks for the links, I tried to look in our blog and google but prolly I was too specific with "orm namespace change" :)

@GromNaN GromNaN force-pushed the attribute-namespace branch from 5e39484 to 4ae6e4d Compare December 8, 2025 20:44
@GromNaN GromNaN force-pushed the attribute-namespace branch 4 times, most recently from fd80856 to 90f1565 Compare December 9, 2025 20:56
@GromNaN
Copy link
Member Author

GromNaN commented Dec 9, 2025

I updated the PR, including the docs to use inheritance. That way the new classes in the Attribute namespace cannot be used as annotation.

New PR description:

  • Move the classes from Doctrine\ODM\MongoDB\Mapping\Annotations to Doctrine\ODM\MongoDB\Mapping\Attribute. Removing the @Annotation so that they can't be used for legacy annotations.
  • For the classes in the Annotations namespace, they extend those from the Attribute namespace. Adding the legacy @Annotation for BC.
  • The EncryptQuery enum is moved to the parent Doctrine\ODM\MongoDB\Mapping namespace
  • The abstract annotation classes are aliased to the new abstract attribute classes, so that it's not breaking type comparison
  • Documentation updated

I've kept the tests unchanged, ensuring full BC of existing code.

@GromNaN GromNaN requested a review from Copilot December 9, 2025 21:03
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 125 out of 125 changed files in this pull request and generated 7 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@GromNaN GromNaN force-pushed the attribute-namespace branch from 90f1565 to 7c7544d Compare December 9, 2025 21:09
@GromNaN GromNaN requested a review from IonBazan December 11, 2025 20:38
Copy link
Member

@alcaeus alcaeus left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure how to proceed with the missing Annotation interface on the attribute class aliases. Found one issue where annotation classes were used in the attribute reader.

}

// @phpstan-ignore class.notFound
class_alias(AbstractDocument::class, \Doctrine\ODM\MongoDB\Mapping\Annotations\AbstractDocument::class);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Noted that this works in conjunction with the class_exists call in the AbstractDocument annotation file.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Exact, having the class_alias in the same file as the class declaration ensure we always have both declared, even if the attribute is used first.
And the class_exists only triggers the autoloader.

Comment on lines +23 to +24
use function array_any;
use function array_find;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like the use of array_any and array_find in this class 👏

// Make sure we only get Doctrine Annotations
if (! is_subclass_of($attributeName, Annotation::class)) {
// Make sure we only get MongoDB ODM attribute classes
if (! is_subclass_of($attributeName, MappingAttribute::class)) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Noted that this doesn't change existing behaviour, as all annotations extend the attribute classes.

@GromNaN GromNaN force-pushed the attribute-namespace branch from fcb30bc to 7a756e1 Compare December 12, 2025 15:15
Copy link
Member Author

@GromNaN GromNaN left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure how to proceed with the missing Annotation interface on the attribute class aliases. Found one issue where annotation classes were used in the attribute reader.

Do you have an example, I don't see the issue.

@alcaeus alcaeus self-requested a review December 16, 2025 09:13
@GromNaN GromNaN force-pushed the attribute-namespace branch from 7a756e1 to 416ff17 Compare December 16, 2025 09:59
@GromNaN GromNaN force-pushed the attribute-namespace branch from 416ff17 to 0e9bf0d Compare December 16, 2025 11:20
@GromNaN
Copy link
Member Author

GromNaN commented Dec 16, 2025

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 125 out of 125 changed files in this pull request and generated no new comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@GromNaN GromNaN merged commit c14f767 into doctrine:2.16.x Dec 16, 2025
29 checks passed
@GromNaN GromNaN deleted the attribute-namespace branch December 16, 2025 17:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants