From 67b5649ee488430edeaaae36318058473a38cc34 Mon Sep 17 00:00:00 2001 From: mahagr Date: Sun, 25 Feb 2018 17:29:29 -0600 Subject: [PATCH 1/4] Add Framework\Route::getRouteParts() function --- system/src/Grav/Framework/Route/Route.php | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/system/src/Grav/Framework/Route/Route.php b/system/src/Grav/Framework/Route/Route.php index 7ab2821b0..53525b928 100644 --- a/system/src/Grav/Framework/Route/Route.php +++ b/system/src/Grav/Framework/Route/Route.php @@ -85,6 +85,22 @@ class Route return '/' . $this->route; } + /** + * @param int $offset + * @param int|null $length + * @return array + */ + public function getRouteParts($offset = 0, $length = null) + { + $parts = explode('/', $this->route); + + if ($offset !== 0 || $length !== null) { + $parts = array_slice($parts, $offset, $length); + } + + return $parts; + } + /** * Return array of both query and Grav parameters. * From ec7831999392412731735674f8ff1994d05459e5 Mon Sep 17 00:00:00 2001 From: mahagr Date: Sun, 25 Feb 2018 17:35:01 -0600 Subject: [PATCH 2/4] Add Framework\Route::getRoute() parameters --- system/src/Grav/Framework/Route/Route.php | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/system/src/Grav/Framework/Route/Route.php b/system/src/Grav/Framework/Route/Route.php index 53525b928..704a63793 100644 --- a/system/src/Grav/Framework/Route/Route.php +++ b/system/src/Grav/Framework/Route/Route.php @@ -78,11 +78,19 @@ class Route } /** + * @param int $offset + * @param int|null $length * @return string */ - public function getRoute() + public function getRoute($offset = 0, $length = null) { - return '/' . $this->route; + if ($offset !== 0 || $length !== null) { + $route = implode('/', $this->getRouteParts($offset, $length)); + } else { + $route = $this->route; + } + + return '/' . $route; } /** From bf16e2e854d201d4581162c52035ce17c2de74bd Mon Sep 17 00:00:00 2001 From: mahagr Date: Sun, 25 Feb 2018 17:37:23 -0600 Subject: [PATCH 3/4] Framework\Route::getRoute() with parameters should return relative path --- system/src/Grav/Framework/Route/Route.php | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/system/src/Grav/Framework/Route/Route.php b/system/src/Grav/Framework/Route/Route.php index 704a63793..456a441eb 100644 --- a/system/src/Grav/Framework/Route/Route.php +++ b/system/src/Grav/Framework/Route/Route.php @@ -85,12 +85,10 @@ class Route public function getRoute($offset = 0, $length = null) { if ($offset !== 0 || $length !== null) { - $route = implode('/', $this->getRouteParts($offset, $length)); - } else { - $route = $this->route; + return implode('/', $this->getRouteParts($offset, $length)); } - return '/' . $route; + return '/' . $this->route; } /** From d5060a2012373d3d5e05d9a5488c0f2ee09fd24a Mon Sep 17 00:00:00 2001 From: mahagr Date: Sun, 25 Feb 2018 17:38:55 -0600 Subject: [PATCH 4/4] Framework\Route::getRoute() return relative path only if offset isn't 0 --- system/src/Grav/Framework/Route/Route.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/system/src/Grav/Framework/Route/Route.php b/system/src/Grav/Framework/Route/Route.php index 456a441eb..503d2a8ad 100644 --- a/system/src/Grav/Framework/Route/Route.php +++ b/system/src/Grav/Framework/Route/Route.php @@ -85,7 +85,7 @@ class Route public function getRoute($offset = 0, $length = null) { if ($offset !== 0 || $length !== null) { - return implode('/', $this->getRouteParts($offset, $length)); + return ($offset === 0 ? '/' : '') . implode('/', $this->getRouteParts($offset, $length)); } return '/' . $this->route;