-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Use the PropertyAccessor component instead of our custom solution #625
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
@javiereguiluz I guess this leads to improved performance too? symfony/symfony#16838 |
@yceruto probably. And less lines of code for us, less bugs, less maintenance, etc. But first, let's try to make tests green for this change 😄 |
$fieldConfiguration['isReadable'] = $getter || $isPublic; | ||
$fieldConfiguration['isWritable'] = $setter || $isPublic; | ||
$fieldConfiguration['isReadable'] = $this->accessor->isReadable($instance , $fieldName); | ||
$fieldConfiguration['isWritable'] = $this->accessor->isWritable($instance, $fieldName); |
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.
Unfortunately, those methods were added in 2.5 only :/
We should have a BC layer temporary until 2.3 support is dropped.
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.
These are really bad news 😭 I'll add that BC layer then.
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.
Create a decorator for the PropertyAccessor, it should be the best solution.
I'm all in for this ! 👍 |
👍 , it makes me want time to go faster for 2.3 to reach end of life, to avoid all these workarounds 😛 |
dab5bb7
to
96ecea3
Compare
I've refactored this code completely. It now supports 2.3, but I haven't added any BC layer. The problem is divided into two parts: read a value and set a value. Before we had an
This change simplifies everything and shaves hundreds of lines of code. Thoughts? |
$accessor = new PropertyAccessor(); | ||
$object = new FooBarClass(); | ||
|
||
$this->assertSame($expectedResult, $accessor->isReadable($object, $property)); |
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.
Still not available as of 2.3 ^^'
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.
Nice catch. Fixed (with a markTestSkipped
for 2.3).
@javiereguiluz : Those changes are fine to me, especially as it simplifies things a lot. But someone might have relied one those metadata. So this is potentially a BC break I guess. 👍 |
$accessor = new PropertyAccessor(); | ||
$object = new FooBarClass(); | ||
|
||
if (!method_exists($accessor, 'isReadable')) { |
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.
CS (indentation).
However, if we completely rely on the Symfony PropertyAccessor, without decorating/modifying it, do we have to test it at all ?
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.
Yes. I know we should remove this test. I maintained it because we are doing the transition and I wanted to be sure that it works as we expect. Should I remove it this very same pull request?
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're right. Good idea in fact to keep it until now. As soon as the PR is ready to be merged, it can be removed 😃
Fixed all the details and added a note in the UPGRADE file (in c7c6331) |
@@ -27,8 +41,8 @@ Upgrade to 1.9.2 | |||
the value of boolean properties. It has been replaced by a private method | |||
called `updateEntityProperty()`. | |||
|
|||
Upgrade to 1.8.0 | |||
---------------- | |||
Upgrade to 1.8.0 (8/November/2015) |
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 like having the /
in a full date when the month is written in letters.
Either put 08/11/2015
or (better I think) put November 8th 2015
No description provided.