add path value retrieval

This commit is contained in:
Dennis Eichhorn 2023-09-21 02:37:39 +00:00
parent 17756362a1
commit d8fd9b74d2
3 changed files with 39 additions and 0 deletions

View File

@ -322,6 +322,20 @@ final class Argument implements UriInterface
return $this->pathElements[$pos + ($useOffset ? $this->pathOffset : 0)] ?? '';
}
/**
* {@inheritdoc}
*/
public function getPathKey(string $key) : string
{
foreach ($this->pathElements as $index => $element) {
if ($element === $key) {
return $this->pathElements[$index + 1] ?? '';
}
}
return '';
}
/**
* {@inheritdoc}
*/

View File

@ -391,6 +391,20 @@ final class HttpUri implements UriInterface
return $this->pathElements[$pos + ($useOffset ? $this->pathOffset : 0)] ?? '';
}
/**
* {@inheritdoc}
*/
public function getPathKey(string $key) : string
{
foreach ($this->pathElements as $index => $element) {
if ($element === $key) {
return $this->pathElements[$index + 1] ?? '';
}
}
return '';
}
/**
* {@inheritdoc}
*/

View File

@ -128,6 +128,17 @@ interface UriInterface
*/
public function getPathElement(int $pos = 0, bool $useOffset = true) : string;
/**
* Get the value after a key
*
* @param string $key Key to search for in path
*
* @return string
*
* @since 1.0.0
*/
public function getPathKey(string $key) : string;
/**
* Get path elements.
*