Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 6 additions & 7 deletions src/Route.php
Original file line number Diff line number Diff line change
Expand Up @@ -717,8 +717,7 @@ protected static function buildAnnotationRouteDefinitions(array $controllerFiles
// Null path means "method restriction only" for default route, do not register.
continue;
}
$path = static::normalizeRoutePath($route->path, $controllerClass . '::' . $method->getName());
$fullPath = $prefix ? rtrim($prefix, '/') . $path : $path;
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

重复的修剪,static::normalizeRoutePrefix已经修剪过了
https://github.com/walkor/webman-framework/blob/master/src/Route.php#L692-L698

$path = $prefix. static::normalizeRoutePath($prefix, $route->path);

$methods = [];
foreach ($route->methods as $m) {
Expand All @@ -727,7 +726,7 @@ protected static function buildAnnotationRouteDefinitions(array $controllerFiles

$definitions[] = [
'methods' => $methods,
'path' => $fullPath,
'path' => $path,
'callback' => [$controllerClass, $method->getName()],
'name' => $route->name,
];
Expand Down Expand Up @@ -801,15 +800,15 @@ protected static function normalizeRoutePrefix(string $prefix): string

/**
* Normalize route path.
* @param string $prefix
* @param string $path
* @param string $source
* @return string
*/
protected static function normalizeRoutePath(string $path, string $source): string
protected static function normalizeRoutePath(string $prefix, string $path): string
{
$path = trim($path);
if ($path === '' || $path[0] !== '/') {
throw new RuntimeException("Annotation route path must start with '/': $path ($source)");
if ($prefix === '' && $path[0] !== '/') {
$path = '/' . $path;
}
return $path;
}
Expand Down