From e8bed84e6e6923297abb3f7df7d09b814bc91103 Mon Sep 17 00:00:00 2001 From: Dennis Eichhorn Date: Sun, 17 Mar 2019 17:53:57 +0100 Subject: [PATCH] Fix abstraction --- Uri/Argument.php | 33 +++++++++++++++++++++++++++++---- 1 file changed, 29 insertions(+), 4 deletions(-) diff --git a/Uri/Argument.php b/Uri/Argument.php index eb2bbbcd8..2eee20d95 100644 --- a/Uri/Argument.php +++ b/Uri/Argument.php @@ -39,6 +39,22 @@ final class Argument implements UriInterface */ private $rootPath = '/'; + /** + * Path offset. + * + * @var int + * @since 1.0.0 + */ + private $pathOffset = 0; + + /** + * Path elements. + * + * @var array + * @since 1.0.0 + */ + private $pathElements = []; + /** * Uri. * @@ -186,6 +202,8 @@ final class Argument implements UriInterface $this->path = $path; } + + $this->pathElements = \explode('/', $this->path); } /** @@ -253,7 +271,14 @@ final class Argument implements UriInterface public function setRootPath(string $root) : void { $this->rootPath = $root; - $this->set($this->uri); + } + + /** + * {@inheritdoc} + */ + public function setPathOffset(int $offset = 0) : void + { + $this->pathOffset = $offset; } /** @@ -334,9 +359,9 @@ final class Argument implements UriInterface /** * {@inheritdoc} */ - public function getPathElement(int $pos = null) : string + public function getPathElement(int $pos = 0) : string { - return \explode('/', $this->path)[$pos] ?? ''; + return $this->pathElements[$pos + $this->pathOffset] ?? ''; } /** @@ -344,7 +369,7 @@ final class Argument implements UriInterface */ public function getPathElements() : array { - return \explode('/', $this->path); + return $this->pathElements; } /**