feat: add new dot-path array helpers#9990
Conversation
| explode('.', $trimmed), | ||
| static fn ($s): bool => $s !== '', |
There was a problem hiding this comment.
For micro-optimization, how about using the first-class callable strlen(...) instead of a closure to filter out empty strings while safely keeping '0'?
| explode('.', $trimmed), | |
| static fn ($s): bool => $s !== '', | |
| explode('.', $trimmed), | |
| strlen(...), |
There was a problem hiding this comment.
In this context, static fn ($s): bool => $s !== '' is explicit, while strlen(...) makes developers figure out that it means "non-empty string".
Thanks for the suggestion, but I will keep the closure here for readability reasons.
| if ($index === '*') { | ||
| $result = []; | ||
|
|
||
| continue; |
There was a problem hiding this comment.
Since the array becomes completely empty here, wouldn’t using break instead of continue be more efficient to avoid processing any remaining keys?
| continue; | |
| break; |
There was a problem hiding this comment.
In theory, you're right, but then the exception depends entirely on argument order: ['users.*.*', '*'] throws, ['*', 'users.*.*'] does not.
There was a problem hiding this comment.
Thanks! That’s a brilliant catch!
|
Thank you for the reviews. |
Description
This PR:
dot_array_has(),dot_array_set(),dot_array_unset(),dot_array_only(), anddot_array_except(), each backed by a correspondingArrayHelperstatic method.ArrayHelper::dotKeyExists()todotHas()and updates all callers, includingValidation/Rules.phpandValidation/StrictRules/Rules.php. This is a safe change sinceArrayHelperis marked as@internal.ArrayHelper::convertToArray()that usesexplode()for the common case (no escaped dots), avoiding PCRE engine overhead.Checklist: