-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[PropertyInfo] Singularize array mutator in ReflectionExtractor #18166
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
Comments
Looks like a bug to me. Maybe can we use our own inflector: https://github.com/symfony/symfony/blob/master/src/Symfony/Component/PropertyAccess/StringUtil.php#L147 |
I suspect |
Of course, the alternative would be just to copy the |
PropertyInfo and PropertyAccess components are often used together. They must have exactly the same behavior regarding singulars, so they must rely on the same inflection backend. I'm not a fond of copy/pasting the class. Maybe can we extract the StringUtil class to its own tiny component? /cc @fabpot @webmozart |
I've just taken another look at this. Maybe we could just use A property access extractor ( |
@dunglas I noticed that the return value signature for |
To answer my own question:
No. Because that operates at the instance level. |
@dunglas Does that indiciate that they should probably be in the same package? What about moving the new code from PropertyInfo to the older PropertyAccess component? |
@webmozart I've no strong opinion about that. Both components are often used together but they are also commonly used separately. They don't solve the exact same problem. For instance https://github.com/dunglas/php-to-json-schema uses only PropertyInfo and symfony/form (and many other components) only uses PropertyAccess. I usually prefer a set of small decoupled components able to work together than a big monolith. What would be the benefit to merge both components? For this specific issue, having a new component (like proposed in #18260) or relying on a third party library (like Doctrine Inflector) looks like a better solution: pluralizing and singularizing words is something very useful and common (e.g. API Platform use Doctrine Inflector for a lot of things, including routing) and isn't related at all with properties. |
…cess) (teohhanhui) This PR was merged into the 3.1-dev branch. Discussion ---------- Add Inflector component (from StringUtil of PropertyAccess) | Q | A | ------------- | --- | Branch? | master | Bug fix? | no | New feature? | no | BC breaks? | no | Deprecations? | yes | Tests pass? | no | Fixed tickets | N/A | License | MIT | Doc PR | N/A As proposed by @dunglas here: #18166 (comment) This will help us fix #18166 Commits ------- 8abebf6 Add Inflector component (from StringUtil of PropertyAccess)
@fabpot This was accidentally closed from the commit message. |
I think it'd be preferrable to use the PropertyAccess component for checking property access (duh...), but currently it only works with an instance. The same functionality is duplicated in PropertyInfo's But I do not agree that PropertyInfo be merged into PropertyAccess, because its purpose is to provide other types of metadata about the property (e.g. Doctrine, PHPDoc). These features would not be a good fit in PropertyAccess. |
ReflectionExtractor
currently supports array mutators (add
,remove
) but it's not very useful as the singular method name is not being checked.If we can use
doctrine/inflector
to singularize the property name, we'll be able to pick up a lot more useful information in many cases. I'll open a PR if this is desirable (looking at thecomposer.json
of Symfony components, I understand that it has to be an optional dependency).The text was updated successfully, but these errors were encountered: