Skip to content

Commit

Permalink
Merge pull request #16 from byjg/4.9
Browse files Browse the repository at this point in the history
Add hasQueryKey()
  • Loading branch information
byjg committed Jun 3, 2024
2 parents 8587553 + 94b04f3 commit 8931289
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/CustomUriInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,5 @@ public function getUsername();
public function getPassword();
public function getQueryPart($key);
public function withQueryKeyValue($key, $value, $isEncoded = true);
public function hasQueryKey($key): bool;
}
5 changes: 5 additions & 0 deletions src/Uri.php
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,11 @@ public function getQueryPart($key): ?string
return $this->getFromArray($this->query, $key, null);
}

public function hasQueryKey($key): bool
{
return isset($this->query[$key]);
}

private function getFromArray($array, $key, $default)
{
if (isset($array[$key])) {
Expand Down
7 changes: 7 additions & 0 deletions tests/UriTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -731,4 +731,11 @@ public function testImmutable()
$this->assertEquals("", $uri->getFragment());
$this->assertEquals("fragment", $uri7->getFragment());
}

public function testHasQueryKey()
{
$uri = new Uri('http://example.com/path/to?q=foo%20bar#section-42');
$this->assertTrue($uri->hasQueryKey('q'));
$this->assertFalse($uri->hasQueryKey('q2'));
}
}

0 comments on commit 8931289

Please sign in to comment.