-
-
Notifications
You must be signed in to change notification settings - Fork 515
Deprecate not overriding Type::closureToPHP()
#2960
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
base: 2.16.x
Are you sure you want to change the base?
Conversation
491601d to
6ec2603
Compare
…he implementation in 3.0
6ec2603 to
de2d92d
Compare
|
|
||
| public function closureToPHP(): string | ||
| { | ||
| return '$return = array_values($value);'; |
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.
null is already handled by the generated hydrator code.
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.
Pull request overview
This PR deprecates the current default implementation of Type::closureToPHP() in preparation for MongoDB ODM 3.0, where the default will change to call convertToPHPValue() instead of returning the value unchanged.
- Adds deprecation warnings for
closureToMongo()and the defaultclosureToPHP()implementation - Implements
closureToPHP()forCollectionTypeandHashTypewhich were previously missing - Adds
ClosureToPHPtrait toTimestampTypeandKeyTypefor the new behavior
Reviewed changes
Copilot reviewed 9 out of 9 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| src/Types/Type.php | Adds deprecation warnings to closureToMongo() and closureToPHP() methods |
| src/Types/CollectionType.php | Implements closureToPHP() to match convertToPHPValue() behavior |
| src/Types/HashType.php | Implements closureToPHP() to match convertToPHPValue() behavior |
| src/Types/TimestampType.php | Adds ClosureToPHP trait for proper type conversion |
| src/Types/KeyType.php | Adds ClosureToPHP trait for proper type conversion |
| src/Types/ClosureToPHP.php | Documents trait deprecation in 3.0 |
| tests/Tests/Types/TypeTest.php | Adds test to verify closureToPHP() behavior |
| tests/Tests/Functional/CustomTypeTest.php | Adds test for deprecation warning with custom type |
| UPGRADE-2.16.md | Documents upgrade path for custom types |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Summary
The default implementation of
Type::closureToPhp()is incorrect as it forwards the unmodified value.mongodb-odm/src/Types/Type.php
Lines 142 to 145 in bf2e243
In 3.0, I want to change the default implementation to use the one from the
ClosureToPHPtrait that calls the type class.mongodb-odm/src/Types/ClosureToPHP.php
Lines 14 to 16 in bf2e243
Also adding the missing implementation for
collectionandhash.