You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
feature #60188 [JsonPath] Add two utils methods to JsonPath builder (alexandre-daubois)
This PR was merged into the 7.3 branch.
Discussion
----------
[JsonPath] Add two utils methods to `JsonPath` builder
| Q | A
| ------------- | ---
| Branch? | 7.3
| Bug fix? | no
| New feature? | yes
| Deprecations? | no
| Issues | -
| License | MIT
Small DX improvements that goes with #60105 and #60083.
This PR adds two new methods, `first()` and `last()`, added to JsonPath builder. This voluntary reminds methods from the DomCrawler component. The goal is not to add every possible method, but I think `first()` and `last()` are common enough to be added.
I also propose to rename `anyIndex()` to `all()`.
```php
$path = new JsonPath();
// Get the first user of the collection
$path = $path->key('users')->first();
```
```php
$path = new JsonPath();
// Get the last user of the collection
$path = $path->key('users')->last();
```
```php
$path = new JsonPath();
// Get all users of the collection
$path = $path->key('users')->all();
```
Commits
-------
3bc3559 [JsonPath][DX] Add utils methods to `JsonPath` builder
0 commit comments