-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[PropertyAccess] Allow custom methods on property accesses #18016
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
Conversation
e461527
to
8d700aa
Compare
@@ -17,7 +17,8 @@ | |||
], | |||
"require": { | |||
"php": ">=5.5.9", | |||
"symfony/polyfill-php70": "~1.0" | |||
"symfony/polyfill-php70": "~1.0", | |||
"doctrine/annotations": "~1.2" |
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 don't think that's a good idea to add a new dependency to this component.
Maybe put it in require-dev
/ suggest
instead ?
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.
Yep, you're right. Thank you!
8d700aa
to
0f303e9
Compare
830fee6
to
5bd8b55
Compare
This looks really good. |
YAML and XML mapping should be working now... |
9b55f63
to
18ad328
Compare
I like the idea, it will be an alternative to #15200 |
$serializerLoaders = array(); | ||
if (isset($config['enable_annotations']) && $config['enable_annotations']) { | ||
$annotationLoader = new Definition( | ||
'Symfony\Component\PropertyAccess\Mapping\Loader\AnnotationLoader', |
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.
Prefer AnnotationLoader::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.
Ah, ok. That change would make the PR incompatible with PHP 5.4, but if its headed to Symfony 3.1 that shouldn't be a problem
It's probably out of scope for this PR, but the code for handling metadata is duplicated in most components. Maybe can we introduce a new |
WDYT about only supporting annotations at first and split xml/yaml support in another PR ? |
* @param bool $magicCall | ||
* @param bool $throwExceptionOnInvalidIndex | ||
* @param CacheItemPoolInterface $cacheItemPool | ||
* @param ClassMetadataFactoryInterface $classMetadataFactory |
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 type hint is not same (MetadataFactoryInterface|null
)
Hi again guys, I intend to resume (and hopefully finish) this PR in October so I'm starting to plan how to address all the pointed issues. I still have two questions on how to proceed, though:
I hope some of you can help me to decide 😜 |
@lrlopez Still interested in finishing this one? |
Note that having a big caching layer would be less critical with #22051 and would probably allow a simpler implementation here. |
3.3 feature-freeze in 7 days :) |
Then I'd better hurry up in order to make the cut :) |
Quick status report: I'm currently splitting this PR into two: the first covers the changes applied to the The new Should I find no problems, I expect to publish the PRs tonight in order to start receiving feedback. |
Closing this one then. Thanks. |
…rface and implementation on reflection (joelwurtz, Korbeil) This PR was merged into the 5.1-dev branch. Discussion ---------- [PropertyInfo] Add accessor and mutator extractor interface and implementation on reflection | Q | A | ------------- | --- | Branch? | master | Bug fix? | no | New feature? | yes | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | #30248, partially: #22190, #18016, #5013, #9336, #5219, | License | MIT | Doc PR | TODO This PR brings accessor / mutator extraction on the PropertyInfo component, There is no link to existing code, as IMO it should be in another PR as this will add a dependency on property access to the property info component and not sure this is something wanted (although, it will reduce a lot of code base on the property access component as a lot of code seems to be duplicated) Code is extracted from #30248 also there is some new features (that can be removed if not wanted) * Allow extracting private accessor / mutator (will do a new PR that improve private extraction on reflection latter) * Allow extracting static accessor / mutators * Allow extracting constructor mutators Current implementation try to be as close as the PropertyAccess implementation and i did not reuse some methods already available in the class as there is some differences in implementation, but maybe it will be a good time to make this consistent (Looking forward to your input) ? Things that should be done in a new PR: * Linking property info to property access to remove a lot of duplicate code * Add a new system that allow adding Virtual Property based on this extractor Commits ------- 0a92dab Rebase, fix tests, review & update CHANGELOG fc25086 [PropertyInfo] Add accessor and mutator extractor interface and implementation on reflection
Some tests do not pass but failures seem not be related to the changes of this PR.
Some examples of how to use the new feature:
Annotations:
YAML:
XML:
Check-list: