Skip to content

Commit

Permalink
add path value retrieval
Browse files Browse the repository at this point in the history
  • Loading branch information
Dennis Eichhorn committed Sep 21, 2023
1 parent 1775636 commit d8fd9b7
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 0 deletions.
14 changes: 14 additions & 0 deletions Uri/Argument.php
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,20 @@ public function getPathElement(int $pos = 0, bool $useOffset = true) : string
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}
*/
Expand Down
14 changes: 14 additions & 0 deletions Uri/HttpUri.php
Original file line number Diff line number Diff line change
Expand Up @@ -391,6 +391,20 @@ public function getPathElement(int $pos = 0, bool $useOffset = true) : string
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}
*/
Expand Down
11 changes: 11 additions & 0 deletions Uri/UriInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,17 @@ public function setPathOffset(int $offset = 0) : void;
*/
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.
*
Expand Down

0 comments on commit d8fd9b7

Please sign in to comment.