From 237934f8c4a22b9e4b2d5ef547bdfb6c078d9f9c Mon Sep 17 00:00:00 2001 From: Maxim Grynykha Date: Sat, 27 Mar 2021 22:16:40 +0200 Subject: [PATCH 1/3] init: task-40 From 4b07daea94e4ec1c667f656942fe664629454f0e Mon Sep 17 00:00:00 2001 From: Maxim Grynykha Date: Sat, 27 Mar 2021 22:31:31 +0200 Subject: [PATCH 2/3] feat: add new function for part - splice() --- src/Urling/PartParsers/PathParser.php | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/src/Urling/PartParsers/PathParser.php b/src/Urling/PartParsers/PathParser.php index e67284b..28a0a54 100644 --- a/src/Urling/PartParsers/PathParser.php +++ b/src/Urling/PartParsers/PathParser.php @@ -33,6 +33,29 @@ public function contains($needle): bool return $is_contains; } + /** + * Get routes after first(1) segment of routes string + * - $urling->url->routes->splice(1); + * + * Get one route starting on first segment - "ismaxim" + * - $urling->url->routes->splice(1, 1); + * + * @param int $offset + * @param int|null $length + * + * @return string + */ + public function splice(int $offset, $length = null): string + { + $routes = (array) $this->explode(); + + $splice = (!$length) + ? array_splice($routes, $offset) + : array_splice($routes, $offset, $length); + + return implode("/", $splice); + } + /** * @return array|array|null */ From 0df89b0e6b093fda610cefd6abed489c148aa5c9 Mon Sep 17 00:00:00 2001 From: Maxim Grynykha Date: Sat, 27 Mar 2021 20:35:17 +0000 Subject: [PATCH 3/3] Apply fixes from StyleCI --- src/Urling/PartParsers/PathParser.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Urling/PartParsers/PathParser.php b/src/Urling/PartParsers/PathParser.php index 28a0a54..3eafb75 100644 --- a/src/Urling/PartParsers/PathParser.php +++ b/src/Urling/PartParsers/PathParser.php @@ -38,11 +38,11 @@ public function contains($needle): bool * - $urling->url->routes->splice(1); * * Get one route starting on first segment - "ismaxim" - * - $urling->url->routes->splice(1, 1); - * + * - $urling->url->routes->splice(1, 1); + * * @param int $offset * @param int|null $length - * + * * @return string */ public function splice(int $offset, $length = null): string