-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[PropertyInfo] Support singular adder and remover #18337
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
AppVeyor errors not related. |
return array($reflectionMethod, $prefix); | ||
if (null !== $singulars && in_array($prefix, self::$arrayMutatorPrefixes)) { | ||
$names = $singulars; | ||
$names[] = $ucProperty; |
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 think the plural version should have the highest precedence.
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 prefer to keep it as is: if someone rely on the old behavior (say it has both methods, currently the singular is used), it should not change or it will be a BC break.
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 see the plural version of the adder/remover being checked at all in PropertyAccessor
. Did I miss anything?
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.
It's not supported by the PropertyAccess component but it is supported by the PropertyInfo component. Changing this behavior would be a BC break.
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'm not sure I get what you mean. The PropertyInfo component currently only supports the plural version. How would it be a BC break if we give the highest precedence to the plural version?
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.
Sorry I just got it...
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.
As in:
$names = $singulars;
array_unshift($names, $ucProperty);
or its equivalent.
@dunglas The Inflector component was merged. |
@dunglas please update your PR. |
Inflector component integrated and @teohhanhui comments fixed. Status: needs review |
try { | ||
$reflectionMethod = new \ReflectionMethod($class, $prefix.$ucProperty); | ||
if (in_array($prefix, self::$arrayMutatorPrefixes)) { | ||
array_unshift($names, $ucProperty); |
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 would keep on prepending...
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.
What about:
$ucProperty = ucfirst($property);
$ucSingulars = (array) Inflector::singularize($ucProperty);
foreach (self::$mutatorPrefixes as $prefix) {
$names = array($ucProperty);
if (in_array($prefix, self::$arrayMutatorPrefixes)) {
$names = array_merge($names, $ucSingulars);
}
...
}
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.
Perfect.
Changes from @teohhanhui are merged. This is ready to be merged. |
|
||
foreach ($reflectionProperties as $reflectionProperty) { | ||
foreach ((array) Inflector::singularize($reflectionProperty->name) as $name) { | ||
if ($name === lcfirst($matches[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.
Should we use strtolower()
when comparing as method names are case-insensitive (like is the regular expression used at the beginning of this method)?
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.
Done.
Travis errors not related. |
return array($reflectionMethod, $prefix); | ||
} | ||
} catch (\ReflectionException $reflectionException) { | ||
// Try the next prefix if the method doesn't exist |
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 now not true anymore. We try the next name (or next prefix) 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.
// Try the next one if method does not exist
👍 |
👍 |
@fabpot ok to merge this one for the rc1? |
@symfony/deciders, unfortunately this PR hasn't been merged in 3.1. |
@dunglas But the |
We can add |
Fix #18166 with only a soft dependency to the PropertyAccess component. If #18260 is accepted, this PR can be reworked to use this new component, in the meantime it fixes the problem with a soft dependency.
I don't now if it should be considered as a bug fix (and then merged in 2.8) or as a new feature. It's technically a bug fix but I'm not sure that introducing a new soft dependency is acceptable if older branches. What do you think @symfony/deciders?