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

[JsonPath] Add utils methodsfirst andlast toJsonPath builder#60188

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

Merged
GromNaN merged 1 commit intosymfony:7.3fromalexandre-daubois:better-path-builder
Apr 10, 2025
Merged
Show file tree
Hide file tree
Changes fromall commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletionsrc/Symfony/Component/JsonPath/JsonPath.php
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -43,11 +43,21 @@ public function deepScan(): static
return new self($this->path.'..');
}

public functionanyIndex(): static
Copy link
Member

@GromNaNGromNaNApr 10, 2025
edited
Loading

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

That's good that you renamed this method. Its name wasn't clear (to me).

public functionall(): static
{
return new self($this->path.'[*]');
}

public function first(): static
{
return new self($this->path.'[0]');
}

public function last(): static
{
return new self($this->path.'[-1]');
}

public function slice(int $start, ?int $end = null, ?int $step = null): static
{
$slice = $start;
Expand Down
27 changes: 27 additions & 0 deletionssrc/Symfony/Component/JsonPath/Tests/JsonPathTest.php
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -35,4 +35,31 @@ public function testBuildWithFilter()

$this->assertSame('$.users[?(@.age > 18)]', (string) $path);
}

public function testAll()
{
$path = new JsonPath();
$path = $path->key('users')
->all();

$this->assertSame('$.users[*]', (string) $path);
}

public function testFirst()
{
$path = new JsonPath();
$path = $path->key('users')
->first();

$this->assertSame('$.users[0]', (string) $path);
}

public function testLast()
{
$path = new JsonPath();
$path = $path->key('users')
->last();

$this->assertSame('$.users[-1]', (string) $path);
}
}
Loading

[8]ページ先頭

©2009-2025 Movatter.jp