-
-
Notifications
You must be signed in to change notification settings - Fork 505
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
Add PHP 8.0 Attribute mapping support #2344
Conversation
Thank you for the work done so far! @beberlei could I ask you to help out with reviewing this since you made the same change in ORM? I'm a little strapped for time right now, but we'll try to give feedback as quick as possible. We definitely want this feature in ODM, so thank you again for getting this started! |
tests/Doctrine/ODM/MongoDB/Tests/PersistentCollection/CollWithPHP80Types.php
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see this extends the AnnoationDriver with no extra changes. This will not work or you must require PHP 8.1, because nested attributes are not supported in 8.0.
I am not super familiar with the ODM, one example i saw #[Indexes] nesting index attributes.
What we did in ORM is copy adapted the Attribute driver and flattened the attribute hierachy
@beberlei You are right but the |
bfef05d
to
d72e3d3
Compare
That makes sense then, i never used the ODM before and am clueless about use of nested annotations there, just wanted to make sure that its adressed |
lib/Doctrine/ODM/MongoDB/Mapping/Annotations/DiscriminatorField.php
Outdated
Show resolved
Hide resolved
9edc694
to
4f6fbb8
Compare
cc69843
to
0c9b20a
Compare
OK I revisited all annotations and compared with changes from #2243 - there were a few places where I missed the default values or properties that shouldn't be set in constructor. The only problematic one is |
a701452
to
bffbb53
Compare
I think we're fine not supporting |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Gave this a review, but I'd still appreciate someone else taking a look. Great work @IonBazan!
tests/Doctrine/ODM/MongoDB/Tests/Mapping/AbstractAnnotationDriverTest.php
Show resolved
Hide resolved
tests/Doctrine/ODM/MongoDB/Tests/Mapping/AbstractAnnotationDriverTest.php
Show resolved
Hide resolved
tests/Doctrine/ODM/MongoDB/Tests/Mapping/AbstractAnnotationDriverTest.php
Show resolved
Hide resolved
lib/Doctrine/ODM/MongoDB/Mapping/Annotations/File/ChunkSize.php
Outdated
Show resolved
Hide resolved
b32d49a
to
5b4a286
Compare
lib/Doctrine/ODM/MongoDB/Mapping/Annotations/File/UploadDate.php
Outdated
Show resolved
Hide resolved
Just wanted to let you know I'll get to this PR somewhen next week. I'm a bit swamped at work before going on vacation ;) |
/** | ||
* The AnnotationDriver reads the mapping metadata from docblock annotations. | ||
*/ | ||
class AttributeDriver extends AnnotationDriver |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was trying the branch and I had to add the constructor like in https://github.com/doctrine/orm/blob/106ed8009a0c581a1566775cbd4d2c4cc93976b1/lib/Doctrine/ORM/Mapping/Driver/AttributeDriver.php#L33-L39
Looks like the create
method was introduced for testing purposes in 5d783c3
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've added the constructor but it seems that it doesn't make much sense here. I think we should use the one from parent class.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The thing here is that using the bundle it creates the service definition for the driver here I think:
And it only receives the array of paths.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for clarification - in that case, the current constructor should work with that. I will try adding the integration to MongoDBBundle just to make sure it works.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I will try adding the integration to MongoDBBundle just to make sure it works.
For prior art, you can check out the same change in DoctrineBundle: doctrine/DoctrineBundle#1322. Changes should be pretty much the same, since the bundles share the same base architecture.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So I feel like I've already gone into too much technical detail already, feel free to ignore / resolve my comments at will. This is my first code review I've done outside of my own company. If my comments seem strange or out of place, please let me know, so I can work on it.
d380185
to
38c948f
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changes LGTM, only a question about the handling of the @Indexes
annotation which seems to have changed slightly.
@IonBazan the test failure on a sharded cluster seems unrelated - this might be a case of us not using the correct write concern for those tests on a sharded cluster. I'll investigate separately but have kicked the build to see if it passes now. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. Great work @IonBazan, this is very much appreciated! 💚
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Awesome work! thank you! 🚀
@IonBazan one last thing: could you please rebase your branch atop current |
Co-authored-by: Fran Moreno <franmomu@gmail.com>
Co-authored-by: Fran Moreno <franmomu@gmail.com>
3674d12
to
1b76c7c
Compare
Thanks @IonBazan! Great work here! |
Hi guys, this is my first contribution here 👾
@NamedArgumentConstructor
- seeUPGRADE-2.3.md
Summary
This PR adds AttributeDriver to allow mapping documents using PHP 8 Attributes to align with ORM functionality.
The driver is actually same as the AnnotationDriver and using custom Reader.
I noticed some annotations are not documented in the Annotations Reference page:
@DiscriminatorValue
- not documented at all@Inheritance
-not documented at all, seems not used anywhereDeleted in 5b4a286@QueryResultDocument
- fixed in add @QueryResultDocument annotation reference #2347Progress
@NamedArgumentConstructor
and add constructorsNotes
@NamedArgumentConstructor
and thusstrict_types
andEnum
checks are skipped (see https://github.com/doctrine/annotations/blob/f96567ba9e3848f59256b473d730e5ba39d81bfe/lib/Doctrine/Common/Annotations/DocParser.php#L569). I removed the tests relying on these features as they are no longer relevant.#[Document]
'sindexes
property cannot be used with PHP Attributes as nested Attributes are not supported. This property is deprecated anyway and top level#[Index]
attribute should be used instead.#[Indexes]
attribute cannot be used for the same reason but it is deprecated too.