Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

[PropertyInfo] Make isWriteable() more consistent with isReadable() when checking snake_case properties#51697

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Conversation

@jbtronics
Copy link
Contributor

QA
Branch?6.4
Bug fix?no
New feature?yes
Deprecations?no
TicketsRelated with issues#29933 and#16889
LicenseMIT
Doc PR

Currently PropertyInfo is a bit inconsistent in the behavior of isWriteable() and isReadable() when using it with properties in snake_case format, which are only accessible via a getter and setter. To be readable the getter function has to be in camel_case (e.g.getSnakeCase()), while the setter function has to remain in the snake case format (e.g.setSnake_case()).

In this example class:

class Dummy {privatestring$snake_case;publicfunctiongetSnakeCase():string  { }publicfunctionsetSnakeCase(string$snake_case):void  { } }

the propertysnake_case is considered readable like you would expect, but not writeable, even though the property has a useable setter and the value can be actually be modified fine by something like the PropertyAccess component.
To make the property actually considered writeable, the setter would need to be namedsetSnake_case, which is pretty inconsistent with the behavior of isReadable and makes it very hard to use this component on snake_case properties.

This inconsistencies are caused by the fact, thatisReadable in ReflectionExtractor uses thegetReadInfo() function which does a camelization of the property name internally, while theisWriteable() function uses thegetMutatorMethod() function which just perform a capitalization of the first letter.

This PR fixes this inconsistencies between isReadable() and isWriteable() by allowing to use a camelCase style setter to be considered writeable, as this is much more common then to use the mix of snake and camelCase currently required.

The getWriteInfo() function is not useable here, because it needs both a add and remove Function on collection setters to give proper infos, while the currentisWriteable() implementation considers a class with just a add or a remove function as writeable. Therefore the property name just gets camelized before being feed into thegetMutatorMethod(), which gives the desired result.

To maximize backwards compatibility, if no camelCase style setter is found, it is still checked for a snake_case setter, so that classes having these, are still considered writeable after the change.

The current behavior is causing some inconsistencies in higher level libraries, which rely on this component. In API Platform for example properties in snake_case are considered read only even though they have a (camel case) setter, because of this. See issue:api-platform/core#5641 andapi-platform/core#1554

valtzu and jbtronics reacted with thumbs up emoji
@jbtronicsjbtronicsforce-pushed theproperty_info_underscore_consistency_fix branch from8cc6f97 to97134b9CompareSeptember 20, 2023 09:33
@nicolas-grekasnicolas-grekas added this to the6.4 milestoneSep 25, 2023
@nicolas-grekasnicolas-grekasforce-pushed theproperty_info_underscore_consistency_fix branch from4af0726 to7c9e6bcCompareSeptember 29, 2023 17:23
@nicolas-grekas
Copy link
Member

Thank you@jbtronics.

Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

@nicolas-grekasnicolas-grekasnicolas-grekas approved these changes

@dunglasdunglasAwaiting requested review from dunglasdunglas is a code owner

+1 more reviewer

@maxbeckersmaxbeckersmaxbeckers left review comments

Reviewers whose approvals may not affect merge requirements

Assignees

No one assigned

Projects

None yet

Milestone

6.4

Development

Successfully merging this pull request may close these issues.

4 participants

@jbtronics@nicolas-grekas@maxbeckers@carsonbot

[8]ページ先頭

©2009-2025 Movatter.jp