Skip to content

Commit

Permalink
Introduce keys method to RequestWrapper interface.
Browse files Browse the repository at this point in the history
This method is introduced to retrieve all keys from the wrapped $_GET, $_POST, and $_COOKIE superglobals
in order to enable the consumer to loop over multiple request parameter using the RequestWrapper infrastructure.
  • Loading branch information
thojou authored and chfsx committed Aug 13, 2024
1 parent d4b3a98 commit 085ac4e
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -58,4 +58,12 @@ public function has(string $key): bool
{
return isset($this->raw_values[$key]);
}

/**
* @inheritDoc
*/
public function keys(): array
{
return array_keys($this->raw_values);
}
}
7 changes: 7 additions & 0 deletions components/ILIAS/HTTP/src/Wrapper/RequestWrapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,11 @@ public function retrieve(string $key, Transformation $transformation);


public function has(string $key): bool;

/**
* Get all keys from the request
*
* @return array<string|int>
*/
public function keys(): array;
}
3 changes: 3 additions & 0 deletions components/ILIAS/HTTP/tests/Services/WrapperTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ public function testQuery(): void
$this->assertTrue($query->has('key_one'));
$this->assertTrue($query->has('key_two'));
$this->assertFalse($query->has('key_three'));
$this->assertEquals(['key_one', 'key_two'], $query->keys());

$string_trafo = $this->refinery->kindlyTo()->string();
$int_trafo = $this->refinery->kindlyTo()->int();
Expand All @@ -106,6 +107,7 @@ public function testPost(): void
$this->assertTrue($post->has('key_one'));
$this->assertTrue($post->has('key_two'));
$this->assertFalse($post->has('key_three'));
$this->assertEquals(['key_one', 'key_two'], $post->keys());

$string_trafo = $this->refinery->kindlyTo()->string();
$int_trafo = $this->refinery->kindlyTo()->int();
Expand All @@ -130,6 +132,7 @@ public function testCookie(): void
$this->assertTrue($cookie->has('key_one'));
$this->assertTrue($cookie->has('key_two'));
$this->assertFalse($cookie->has('key_three'));
$this->assertEquals(['key_one', 'key_two'], $cookie->keys());

$string_trafo = $this->refinery->kindlyTo()->string();
$int_trafo = $this->refinery->kindlyTo()->int();
Expand Down

0 comments on commit 085ac4e

Please sign in to comment.