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

[PropertyAccess] [For reference only] Allow custom property accessors#38515

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

Closed

Conversation

lrlopez
Copy link
Contributor

Disclaimer: this is just a relaunch of PR#22190 targeting "5.x" instead of "master".@fabpot asked to create this PR because he's not able to switch the target repository as the old PR is already closed. Take into account that this code was intended to be merged into 3.4 a loooong time ago...

QA
Branch5.x
Bug fix?no
New feature?yes
BC breaks?no
Deprecations?no
Tests pass?yes
Fixed tickets#18016,#5013,#9336,#5219, among others
LicenseMIT
Doc PRsymfony/symfony-docs#6400

Here is the first of the two PR related to#18016. This implements changes on thePropertyAccess component and will be followed by another one leveraging the new features into theFrameworkBundle.

Now it is possible to override the property accessors (getters, setters, adders and removers) using annotations or YAML config files. Metadata is automatically cached in the pool configured for the property path cache.

Some examples of how to use the new feature:

Annotations:

/** * @PropertyAccessor(getter="getCurrentValue", setter="updateValue") */protected$value;/** * @PropertyAccessor(adder="joinMember", remover="detachMember") */protected$members;publicfunctiongetCurrentValue(){return$this->value;}publicfunctionupdateValue($newValue){$this->value =$newValue;return$this;}publicfunctionjoinMember($newMember){// Add $newMember to the collection}publicfunctiondetachMember($oldMember){// Remove $oldMember from the collection}// Notice that "calculated" is not a real property!/** * @GetterAccessor(property="calculated") */publicfunctiongetCalculated(){// whatever...}// You can omit 'property' in method annotations/** * @SetterAccessor("calculated") */publicfunctionsetCalculated($calculated){// whatever...}

YAML:

'AppBundle\Entity\Example':properties:value:getter:getCurrentValuesetter:updateValuemembers:adder:joinMemberremover:detachMembercalculated:getter:getCalculatedsetter:setCalculated

XML:

<?xml version="1.0" ?><property-accessxmlns="http://symfony.com/schema/dic/property-access-mapping"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation="http://symfony.com/schema/dic/property-access-mapping http://symfony.com/schema/dic/property-access-mapping/property-access-mapping-1.0.xsd">    <classname="AppBundle\Entity\Example">        <propertyname="value"getter="getCurrentValue"setter="updateValue" />        <propertyname="members"adder="joinMember"remover="detachMember" />        <propertyname="calculated"getter="getCalculated"setter="setCalculated" />    </class></property-access>

@fabpot
Copy link
Member

I really like this feature but as nobody ever resumed the work, I'm going to close it now :(

Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers
No reviews
Assignees
No one assigned
Projects
None yet
Milestone
6.2
Development

Successfully merging this pull request may close these issues.

4 participants
@lrlopez@fabpot@nicolas-grekas@carsonbot

[8]ページ先頭

©2009-2025 Movatter.jp