-
-
Notifications
You must be signed in to change notification settings - Fork 45
Allow access to sibling properties in nested context (#752) #791
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
base: master
Are you sure you want to change the base?
Changes from 3 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -18,6 +18,8 @@ | |
| use function is_array; | ||
| use function is_int; | ||
| use function is_object; | ||
| use function array_key_exists; | ||
| use function count; | ||
|
|
||
| /** | ||
| * A handler for {@see Nested} rule. Validates nested structures. | ||
|
|
@@ -93,8 +95,19 @@ public function validate(mixed $value, RuleInterface $rule, ValidationContext $c | |
| } else { | ||
| $valuePathList = StringHelper::parsePath($valuePath); | ||
| $property = end($valuePathList); | ||
|
|
||
| $scopeData = $data; | ||
| for ($i = 0, $limit = count($valuePathList) - 1; $i < $limit; $i++) { | ||
| $key = $valuePathList[$i]; | ||
| if (!is_array($scopeData) || !array_key_exists($key, $scopeData)) { | ||
| $scopeData = []; | ||
|
Comment on lines
+99
to
+103
|
||
| break; | ||
| } | ||
| $scopeData = $scopeData[$key]; | ||
| } | ||
|
|
||
| $itemResult = $context->validate( | ||
| ArrayHelper::keyExists($data, $valuePathList) ? [$property => $validatedValue] : [], | ||
| $scopeData, | ||
| [$property => $rules], | ||
| ); | ||
| } | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.