Skip to content

Commit 3fbcde8

Browse files
authored
Update Routes.php
1 parent 39e5fdf commit 3fbcde8

File tree

1 file changed

+4
-7
lines changed

1 file changed

+4
-7
lines changed

src/Routes.php

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ public function generate(RouteMap $routes, string $name, array $params = []): st
7676
}
7777

7878
$path = '';
79-
$segments = explode('/', $route->path);
79+
$segments = $this->tokenizer->splitPath($route->path);
8080

8181
foreach ($segments as $segment) {
8282
if (!empty($segment)) {
@@ -178,10 +178,7 @@ private function buildRegexp(RouteRecord $route): string
178178
if ($this->tokenizer->isToken($segment)) {
179179
list($id, $pattern) = $this->tokenizer->parseToken($segment);
180180
$pattern = $route->tokens[$id] ?? $pattern;
181-
if (!$pattern) {
182-
$pattern = $route->tokens[$id] ?? '.+';
183-
$pattern = "$pattern";
184-
}
181+
if (!$pattern) $pattern = $route->tokens[$id] ?? '.+';
185182
if (!$this->tokenizer->isRequired($segment)) $regexp .= "(/$pattern)?";
186183
else $regexp .= '/'.$pattern;
187184
} else {
@@ -216,7 +213,7 @@ protected function preparePathAndMethod(string $uri, string $requestMethod): arr
216213
private function parseParams(RouteRecord $route, string $path): RouteRecord
217214
{
218215
$paths = explode('/', $path);
219-
$segments = explode('/', $route->path);
216+
$segments = $this->tokenizer->splitPath($route->path);
220217

221218
$params = [];
222219
foreach ($segments as $i => $segment) {
@@ -279,7 +276,7 @@ public function match(RouteMap $routes, string $uri, string $requestMethod):? Ro
279276

280277
$parseParams = static function(array $route, string $path) use ($routes): RouteRecord {
281278
$paths = explode('/', $path);
282-
$segments = explode('/', $route['path']);
279+
$segments = $routes->tokenizer->splitPath('/', $route['path']);
283280

284281
$route['params'] = [];
285282
foreach ($segments as $i => $segment) {

0 commit comments

Comments
 (0)