-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[PropertyAccess] add support for magic call #7263
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
[PropertyAccess] add support for magic call #7263
Conversation
@@ -224,6 +253,9 @@ private function &readProperty(&$object, $property) | |||
} elseif ($reflClass->hasMethod('__get')) { | |||
// needed to support magic method __get | |||
$result[self::VALUE] = $object->$property; | |||
} elseif ($this->magicCall && $reflClass->hasMethod('__call')) { |
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.
You should first check the public property before __call IMO to be more BC
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.
@stof the problem with that is __call won't be called if you have a private property, because exception is raised.
This is disable by default so this is BC :)
maybe I can talk with @bschussek to refactor the way PropertyAccess throw exceptions without trying next case
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.
see #7711
No need for FQCN in phpdoc. |
@vicb fixed ;) |
I add the documentation for this PR |
* | ||
* @return PropertyAccessor | ||
*/ | ||
public function enableMagicCall($enable = true) |
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.
Please remove the argument $enable and add a method disableMagicCall()
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.
Btw. both enableMagicCall()
and disableMagicCall()
should be moved to a new class PropertyAccessorBuilder
. PropertyAccessor
is immutable. (see how the same pattern is implemented in the Validator component)
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 agree with @bschussek
@bschussek I created the PropertyAccessorBuilder, tell me if this is what you expected. |
@@ -24,12 +24,15 @@ class PropertyAccessor implements PropertyAccessorInterface | |||
const VALUE = 0; | |||
const IS_REF = 1; | |||
|
|||
private $magicCall = false; |
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.
This is redundant if you are defining it in the constructor
Looks good apart from the few mentioned issues! Please do also add this to the component's CHANGELOG. |
And please also squash your commits when you're done. |
@bschussek naming fixed, commit squashed :) |
I don't understand why we would need |
@fabpot I create the builder like @bschussek what is your point of view on this ? If it's not needed I can remove it :) |
Frankly, I don't understand why we have a |
@fabpot You don't understand why we have the interface or why we have the builder? We have the interface so we can type-hint against the builder without type-hinting against the implementation, nothing more. We have the builder so that users can configure $validator = new Validator(array(
// configuration
)); only a bit more convenient because your IDE tells you how to configure the builder, while it doesn't tell you which entries you can pass to the array. |
Also, configuration code can be extracted into the builder, as done in ValidatorBuilder for example. |
👍 on this PR |
Please add |
"We have the interface so we can type-hint against the builder without type-hinting against the implementation, nothing more." <- that part does not make sense to me. Why not type-hinting on the implementation for a builder? You will never have any other implementation anyway. |
I thought that so many times in other cases, until it happened :P Just to make sure. |
add a new propertyAccessorBuilder to enable / disable the use of __call by the PropertyAccessor
@bschussek done |
Come on. Have a look at the builder, I can't buy that you will have another implementation. And anyway, even if you can come up with something, you can still extend the existing one. But having such a specialized interface for a builder seems overkill to me. |
The builder is very simple as of now because important functionalities are still missing, such as the generation and caching of class-specific property accessors, configurable property paths etc. With these things, the builder code will become more complicated as well. I don't think that we in the core will have another implementation of the interface, but userland projects might well do if they want to add some functionality. I don't see why they should have to extend a class here when we provide interfaces everywhere else. After all, creating an interface doesn't cost us anything. |
The issue with the interface for the builder is that the BC concern will prevent us adding anything new in the builder as it would be a BC break for other implementations. |
@stof has nailed the argument very well for this particular case. |
The poll ends tomorrow night (April 24 23:55 CET). I'll post the results then. |
This PR was merged into the master branch. Discussion ---------- [PropertyAccess] add support for magic call Hi, I add support for magic call with the `PropertyAccess` the is basic implementation, if no `getter`, `isser`, or `hasser` or `_get` is found and there is `__call` then the PropertyAccess call the getter the same for setter. This functionality is disable by default | Q | A | ------------- | --- | Bug fix? | no | New feature? | yes | BC breaks? | no | Deprecations? | no | Tests pass? | seems OK (failure/errors are the same on master) | Fixed tickets | #4683, #6413, #5309 | License | MIT | Doc PR | symfony/symfony-docs#2472 - [x] submit changes to the documentation @bschussek is this ok ? Commits ------- a785baa [PropertyAccess] add support for magic call, related to #4683
Hi,
I add support for magic call with the
PropertyAccess
the is basic implementation, if no
getter
,isser
, orhasser
or_get
is found and there is__call
then the PropertyAccess call the getterthe same for setter.
This functionality is disable by default
@bschussek is this ok ?