-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[PropertyAccess] add naming strategy #23789
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 naming strategy #23789
Conversation
I have added the configuration and few tests. |
src/Symfony/Component/PropertyAccess/PropertyAccessorBuilder.php
Outdated
Show resolved
Hide resolved
You are the genius! |
i added more tests |
Moving to 4.1 as review is pending (ping @symfony/deciders) |
Could the changes proposed in #22190 be relevant here? Do we need to think of ways to make both PRs interact? |
rebased on master & typehints added |
@@ -1113,6 +1113,10 @@ private function registerPropertyAccessConfiguration(array $config, ContainerBui | |||
->replaceArgument(0, $config['magic_call']) | |||
->replaceArgument(1, $config['throw_exception_on_invalid_index']) | |||
; | |||
|
|||
if (isset($config['naming_strategy']) && $config['naming_strategy']) { |
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.
perhaps add a cannotBeEmpty()
in config, so only isset() is needed here.
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.
no need for isset() actually as the node does not seem to be removed if not set (hence will have an empty value). A cannot be empty
would break BC IIRC.
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.
A cannot be empty would break BC IIRC.
Why so? This is a new config node.
No real opinion about isset($config['node'])
vs. null !== $config['node']
.
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.
👍 for this approach
src/Symfony/Component/PropertyAccess/NamingStrategy/CamelCaseStrategy.php
Outdated
Show resolved
Hide resolved
src/Symfony/Component/PropertyAccess/NamingStrategy/CamelCaseStrategy.php
Outdated
Show resolved
Hide resolved
src/Symfony/Component/PropertyAccess/NamingStrategy/NamingStrategyInterface.php
Outdated
Show resolved
Hide resolved
src/Symfony/Component/PropertyAccess/PropertyAccessorBuilder.php
Outdated
Show resolved
Hide resolved
comments addressed |
What's the status here? 🤔 |
* @param string $class | ||
* @param string $property | ||
* | ||
* @return array |
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 structure should be used for return? Maybe better split for getAdders
and getRemovers
and return array of strings for both methods?
* Returns all possible setters. | ||
* | ||
* @param string $class | ||
* @param string $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.
I think this PHPDocs has no sense: they just duplicates typehints. But we can better describe return: @return string[]
.
I'm from issue #23656 which is about a problem with the PropertyAccessor. The problem is that the PropertyAccessor always camelizes properties before searching for the right methods.
The other referenced issues (above) are pointing out a lot more problems about how the PropertyAccessor creates the method names:
#22190 & #22191 should fix all this, but:
The simplest way to solve these problems is to extract how the method names are created. The advatages of this method are:
Simple override example:
An underscore strategy or a yaml based configuration strategy would also be possible.
What do you think about this solution?
Todos: