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] Allow usage of wildcard[*]#52723

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

Open
Brajk19 wants to merge14 commits intosymfony:7.4
base:7.4
Choose a base branch
Loading
fromBrajk19:propertyaccess-wildcard

Conversation

Brajk19
Copy link
Contributor

QA
Branch?7.1
Bug fix?no
New feature?yes
Deprecations?yes
Issues
LicenseMIT

This feature allows usage of wildcards to read values from multiple arrays/objects.

Examples:

$persons = [    ['first_name' =>'Wouter',    ],    ['first_name' =>'Ryan',    ],];var_dump($propertyAccessor->getValue($persons,'[*][first_name]'));// ['Wouter', 'Ryan']
$persons = [    ['first_name' =>'Wouter','pets' => ['Tom','Jerry']    ],    ['first_name' =>'Ryan','pets' => ['Garfield']    ],];var_dump($propertyAccessor->getValue($persons,'[*][pets]'));// ['Tom', 'Jerry', 'Garfield']
$persons = [    ['first_name' =>'Wouter','pets' => ['cats' => ['Tom','Garfield'],'mouses' => ['Jerry']        ]    ],    ['first_name' =>'Ryan','pets' => ['cats' => ['Sylvester','Felix'],'mouses' => ['Speedy Gonzales']        ]    ],];var_dump($propertyAccessor->getValue($persons,'[*][pets][mouses]'));// ['Jerry', 'Speedy Gonzales']
$persons = [    ['first_name' =>'Wouter','pets' => [            ['name' =>'Tom','type' =>'cat',            ],            ['name' =>'Garfield','type' =>'cat',            ],            ['name' =>'Jerry','type' =>'mouse',            ]        ]    ],    ['first_name' =>'Ryan','pets' => [            ['name' =>'Sylvester','type' =>'cat',            ],            ['name' =>'Felix','type' =>'cat',            ],            ['name' =>'Speedy Gonzales','type' =>'mouse',            ]        ]    ],];var_dump($propertyAccessor->getValue($persons,'[*][pets][*][name]'));// ['Tom', 'Garfield', 'Jerry', 'Sylvester', 'Felix', 'Speedy Gonzales']var_dump($propertyAccessor->getValue($persons,'[*][pets][*][type]'));// ['cat', 'cat', 'mouse', 'cat', 'cat', 'mouse']var_dump($propertyAccessor->getValue($persons,'[0][pets][*][*]'));// ['Tom', 'cat', 'Garfield', 'cat', 'Jerry', 'mouse']

More examples inPropertyAccessorWildcardTest.

If there is* key in array it should be accesed with[\*]

How does it work?
Whenever [*] is detected, it is replaced with all possible values:

  • 1st example:[*][first_name] becomes[0][first_name] and[1][first_name]
  • readPropertiesUntil is then recursively called for each of them whenever wildcard is detected
  • returned paths from each of them are merged together

Notes:

  • public function isWildcard(int $index): bool should be added toPropertyPathInterfacein next major version
  • currently deprecation is triggered when method does not exists in class implementing that interface

HypeMC reacted with thumbs up emoji
@carsonbotcarsonbot added this to the7.1 milestoneNov 24, 2023
@Brajk19Brajk19 changed the title[PropertyAccess] Add option to use[PropertyAccess] Allow usage of wildcard [*]Nov 24, 2023
@OskarStarkOskarStark changed the title[PropertyAccess] Allow usage of wildcard [*][PropertyAccess] Allow usage of wildcard[*]Nov 24, 2023
@xabbuhxabbuh modified the milestones:7.1,7.2May 15, 2024
@fabpotfabpot modified the milestones:7.2,7.3Nov 20, 2024
Brajk19and others added12 commitsJanuary 10, 2025 11:49
New property `$isWildcard` is added which denotes whether certainelement is wildcard.Element is registered as wildcard if it's `[*]`.Method isWildcard should be added to PropertyPathInterface in next majorrelease.
Whenever wildcard is in property path, that wildcard is replaced withall possible values and same method `readPropertyUntil` is recursivelycalled.All returned subpaths are then merged together.
Co-authored-by: Oskar Stark <oskarstark@googlemail.com>
Co-authored-by: Oskar Stark <oskarstark@googlemail.com>
@fabpotfabpot modified the milestones:7.3,7.4May 26, 2025
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@slimusslimusslimus left review comments

@OskarStarkOskarStarkOskarStark left review comments

@xabbuhxabbuhAwaiting requested review from xabbuhxabbuh is a code owner

@ycerutoycerutoAwaiting requested review from ycerutoyceruto is a code owner

@welcoMatticwelcoMatticAwaiting requested review from welcoMattic

Assignees
No one assigned
Projects
None yet
Milestone
7.4
Development

Successfully merging this pull request may close these issues.

6 participants
@Brajk19@slimus@OskarStark@fabpot@xabbuh@carsonbot

[8]ページ先頭

©2009-2025 Movatter.jp