Skip to content

Commit

Permalink
Merge pull request #49 from ismaxim/task-40-add-method-splice-for-routes
Browse files Browse the repository at this point in the history
init: task-40
  • Loading branch information
maximgrynykha authored Mar 27, 2021
2 parents 1475d79 + 0df89b0 commit a8daa95
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions src/Urling/PartParsers/PathParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, string|null>|array<int, string|null>|null
*/
Expand Down

0 comments on commit a8daa95

Please sign in to comment.