chore: resolve all PSR-12 line length warnings in src directory
Some checks failed
CI / build (push) Has been cancelled
Some checks failed
CI / build (push) Has been cancelled
This commit is contained in:
parent
83c18bd82d
commit
dd081da81c
|
|
@ -288,7 +288,9 @@ class TestRouteCommand
|
|||
|
||||
if ($result->isFound()) {
|
||||
echo "Match Found!" . PHP_EOL;
|
||||
echo "Route: " . $result->getRoute()->getName() . " [" . $result->getRoute()->getMethod() . " " . $result->getRoute()->getPath() . "]" . PHP_EOL;
|
||||
echo "Route: " . $result->getRoute()->getName() . " [" .
|
||||
$result->getRoute()->getMethod() . " " .
|
||||
$result->getRoute()->getPath() . "]" . PHP_EOL;
|
||||
echo "Parameters: " . json_encode($result->getParameters()) . PHP_EOL;
|
||||
exit(0);
|
||||
} else {
|
||||
|
|
|
|||
|
|
@ -61,8 +61,11 @@ class ModuleLoader
|
|||
* @param string|null $moduleName Optional module name
|
||||
* @return void
|
||||
*/
|
||||
private function loadModuleRoutes(string $routesFile, string|null $prefix = null, string|null $moduleName = null): void
|
||||
{
|
||||
private function loadModuleRoutes(
|
||||
string $routesFile,
|
||||
string|null $prefix = null,
|
||||
string|null $moduleName = null
|
||||
): void {
|
||||
$moduleRoutes = require $routesFile;
|
||||
|
||||
$options = [];
|
||||
|
|
|
|||
|
|
@ -41,7 +41,15 @@ class RouteGroup
|
|||
$defaults = $this->options['defaults'] ?? [];
|
||||
|
||||
if ($this->router) {
|
||||
return $this->router->registerCustomRoute('GET', $fullPath, $handler, $name, $middleware, $validation, $defaults);
|
||||
return $this->router->registerCustomRoute(
|
||||
'GET',
|
||||
$fullPath,
|
||||
$handler,
|
||||
$name,
|
||||
$middleware,
|
||||
$validation,
|
||||
$defaults
|
||||
);
|
||||
}
|
||||
|
||||
return new RouteDefinition('GET', $fullPath, $fullPath, $handler, $name, $middleware, $validation, $defaults);
|
||||
|
|
@ -55,7 +63,15 @@ class RouteGroup
|
|||
$defaults = $this->options['defaults'] ?? [];
|
||||
|
||||
if ($this->router) {
|
||||
return $this->router->registerCustomRoute('POST', $fullPath, $handler, $name, $middleware, $validation, $defaults);
|
||||
return $this->router->registerCustomRoute(
|
||||
'POST',
|
||||
$fullPath,
|
||||
$handler,
|
||||
$name,
|
||||
$middleware,
|
||||
$validation,
|
||||
$defaults
|
||||
);
|
||||
}
|
||||
|
||||
return new RouteDefinition('POST', $fullPath, $fullPath, $handler, $name, $middleware, $validation, $defaults);
|
||||
|
|
@ -69,7 +85,15 @@ class RouteGroup
|
|||
$defaults = $this->options['defaults'] ?? [];
|
||||
|
||||
if ($this->router) {
|
||||
return $this->router->registerCustomRoute('PUT', $fullPath, $handler, $name, $middleware, $validation, $defaults);
|
||||
return $this->router->registerCustomRoute(
|
||||
'PUT',
|
||||
$fullPath,
|
||||
$handler,
|
||||
$name,
|
||||
$middleware,
|
||||
$validation,
|
||||
$defaults
|
||||
);
|
||||
}
|
||||
|
||||
return new RouteDefinition('PUT', $fullPath, $fullPath, $handler, $name, $middleware, $validation, $defaults);
|
||||
|
|
@ -83,7 +107,15 @@ class RouteGroup
|
|||
$defaults = $this->options['defaults'] ?? [];
|
||||
|
||||
if ($this->router) {
|
||||
return $this->router->registerCustomRoute('PATCH', $fullPath, $handler, $name, $middleware, $validation, $defaults);
|
||||
return $this->router->registerCustomRoute(
|
||||
'PATCH',
|
||||
$fullPath,
|
||||
$handler,
|
||||
$name,
|
||||
$middleware,
|
||||
$validation,
|
||||
$defaults
|
||||
);
|
||||
}
|
||||
|
||||
return new RouteDefinition('PATCH', $fullPath, $fullPath, $handler, $name, $middleware, $validation, $defaults);
|
||||
|
|
@ -97,10 +129,27 @@ class RouteGroup
|
|||
$defaults = $this->options['defaults'] ?? [];
|
||||
|
||||
if ($this->router) {
|
||||
return $this->router->registerCustomRoute('DELETE', $fullPath, $handler, $name, $middleware, $validation, $defaults);
|
||||
return $this->router->registerCustomRoute(
|
||||
'DELETE',
|
||||
$fullPath,
|
||||
$handler,
|
||||
$name,
|
||||
$middleware,
|
||||
$validation,
|
||||
$defaults
|
||||
);
|
||||
}
|
||||
|
||||
return new RouteDefinition('DELETE', $fullPath, $fullPath, $handler, $name, $middleware, $validation, $defaults);
|
||||
return new RouteDefinition(
|
||||
'DELETE',
|
||||
$fullPath,
|
||||
$fullPath,
|
||||
$handler,
|
||||
$name,
|
||||
$middleware,
|
||||
$validation,
|
||||
$defaults
|
||||
);
|
||||
}
|
||||
|
||||
public function redirect(string $path, string $destination, int $status = 302): RouteDefinition
|
||||
|
|
@ -111,10 +160,27 @@ class RouteGroup
|
|||
$defaults = $this->options['defaults'] ?? [];
|
||||
|
||||
if ($this->router) {
|
||||
return $this->router->registerCustomRoute('REDIRECT', $fullPath, $destination, null, $middleware, $validation, $defaults)->attr('status', $status);
|
||||
return $this->router->registerCustomRoute(
|
||||
'REDIRECT',
|
||||
$fullPath,
|
||||
$destination,
|
||||
null,
|
||||
$middleware,
|
||||
$validation,
|
||||
$defaults
|
||||
)->attr('status', $status);
|
||||
}
|
||||
|
||||
return (new RouteDefinition('REDIRECT', $fullPath, $fullPath, $destination, null, $middleware, $validation, $defaults))->attr('status', $status);
|
||||
return (new RouteDefinition(
|
||||
'REDIRECT',
|
||||
$fullPath,
|
||||
$fullPath,
|
||||
$destination,
|
||||
null,
|
||||
$middleware,
|
||||
$validation,
|
||||
$defaults
|
||||
))->attr('status', $status);
|
||||
}
|
||||
|
||||
public function fallback(mixed $handler): self
|
||||
|
|
@ -125,7 +191,13 @@ class RouteGroup
|
|||
$middleware = $this->options['middleware'] ?? [];
|
||||
|
||||
if ($this->router) {
|
||||
$this->router->registerCustomRoute('FALLBACK', $this->joinPaths($prefix, '/_fallback'), $handler, null, $middleware)
|
||||
$this->router->registerCustomRoute(
|
||||
'FALLBACK',
|
||||
$this->joinPaths($prefix, '/_fallback'),
|
||||
$handler,
|
||||
null,
|
||||
$middleware
|
||||
)
|
||||
->attr('_fallback', $handler)
|
||||
->attr('_fallback_prefix', $this->normalizePath($prefix));
|
||||
}
|
||||
|
|
@ -133,8 +205,15 @@ class RouteGroup
|
|||
return $this;
|
||||
}
|
||||
|
||||
public function registerCustomRoute(string $method, string $path, mixed $handler, string|null $name = null, array $middleware = [], array $validation = [], array $defaults = []): RouteDefinition
|
||||
{
|
||||
public function registerCustomRoute(
|
||||
string $method,
|
||||
string $path,
|
||||
mixed $handler,
|
||||
string|null $name = null,
|
||||
array $middleware = [],
|
||||
array $validation = [],
|
||||
array $defaults = []
|
||||
): RouteDefinition {
|
||||
$fullPath = $this->buildFullPath($path);
|
||||
$mergedMiddleware = array_merge($this->options['middleware'] ?? [], $middleware);
|
||||
|
||||
|
|
|
|||
|
|
@ -112,8 +112,14 @@ class RouteMatcher
|
|||
* @param array $attributes Extracted attributes
|
||||
* @return bool
|
||||
*/
|
||||
private function isMatch(string $method, string $path, string $host, RouteDefinition $route, array &$attributes, ?string $overridePath = null): bool
|
||||
{
|
||||
private function isMatch(
|
||||
string $method,
|
||||
string $path,
|
||||
string $host,
|
||||
RouteDefinition $route,
|
||||
array &$attributes,
|
||||
?string $overridePath = null
|
||||
): bool {
|
||||
$routeMethod = strtoupper($route->getMethod());
|
||||
if ($routeMethod !== $method && $routeMethod !== 'REDIRECT') {
|
||||
return false;
|
||||
|
|
@ -128,7 +134,9 @@ class RouteMatcher
|
|||
}
|
||||
}
|
||||
|
||||
$pattern = $overridePath ? $this->compilePatternFromPath($overridePath, $route) : $this->getPatternForRoute($route);
|
||||
$pattern = $overridePath
|
||||
? $this->compilePatternFromPath($overridePath, $route)
|
||||
: $this->getPatternForRoute($route);
|
||||
|
||||
if (preg_match($pattern, $path, $matches)) {
|
||||
$attributes = array_filter($matches, 'is_string', ARRAY_FILTER_USE_KEY);
|
||||
|
|
@ -175,8 +183,9 @@ class RouteMatcher
|
|||
$validation = $route->getValidation();
|
||||
$defaults = $route->getDefaults();
|
||||
|
||||
// Replace {{param?}} and {{param}} with regex
|
||||
$pattern = preg_replace_callback('#/\{\{([a-zA-Z0-9_]+)(\?)?\}\}#', function ($matches) use ($validation, $defaults) {
|
||||
$pattern = preg_replace_callback(
|
||||
'#/\{\{([a-zA-Z0-9_]+)(\?)?\}\}#',
|
||||
function ($matches) use ($validation, $defaults) {
|
||||
$name = $matches[1];
|
||||
$optional = (isset($matches[2]) && $matches[2] === '?') || array_key_exists($name, $defaults);
|
||||
|
||||
|
|
@ -201,7 +210,9 @@ class RouteMatcher
|
|||
}
|
||||
|
||||
return '/(?P<' . $name . '>' . $regex . ')';
|
||||
}, $path);
|
||||
},
|
||||
$path
|
||||
);
|
||||
|
||||
$pattern = str_replace('//', '/', $pattern);
|
||||
|
||||
|
|
@ -215,8 +226,10 @@ class RouteMatcher
|
|||
* @param array $attributes
|
||||
* @return RouteDefinition
|
||||
*/
|
||||
private function applyAttributes(RouteDefinition $route, array $attributes): RouteDefinition
|
||||
{
|
||||
private function applyAttributes(
|
||||
RouteDefinition $route,
|
||||
array $attributes
|
||||
): RouteDefinition {
|
||||
$data = $route->toArray();
|
||||
$data['attributes'] = array_merge($data['attributes'], $attributes);
|
||||
|
||||
|
|
|
|||
|
|
@ -49,13 +49,27 @@ class Router
|
|||
return $this->registerRoute('DELETE', $path, $handler, $name);
|
||||
}
|
||||
|
||||
public function registerCustomRoute(string $method, string $path, mixed $handler, string|null $name = null, array $middleware = [], array $validation = [], array $defaults = []): RouteDefinition
|
||||
{
|
||||
public function registerCustomRoute(
|
||||
string $method,
|
||||
string $path,
|
||||
mixed $handler,
|
||||
string|null $name = null,
|
||||
array $middleware = [],
|
||||
array $validation = [],
|
||||
array $defaults = []
|
||||
): RouteDefinition {
|
||||
return $this->registerRoute($method, $path, $handler, $name, $middleware, $validation, $defaults);
|
||||
}
|
||||
|
||||
private function registerRoute(string $method, string $path, mixed $handler, string|null $name = null, array $middleware = [], array $validation = [], array $defaults = []): RouteDefinition
|
||||
{
|
||||
private function registerRoute(
|
||||
string $method,
|
||||
string $path,
|
||||
mixed $handler,
|
||||
string|null $name = null,
|
||||
array $middleware = [],
|
||||
array $validation = [],
|
||||
array $defaults = []
|
||||
): RouteDefinition {
|
||||
$normalizedPath = $this->normalizePath($path);
|
||||
$routeDefinition = new RouteDefinition(
|
||||
$method,
|
||||
|
|
@ -211,7 +225,9 @@ class Router
|
|||
} elseif ($isOptional[$index] === '?') {
|
||||
$path = str_replace($pattern, '', $path);
|
||||
} else {
|
||||
throw new \InvalidArgumentException(sprintf('Missing required parameter "%s" for route URL generation', $name));
|
||||
throw new \InvalidArgumentException(
|
||||
sprintf('Missing required parameter "%s" for route URL generation', $name)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue