This commit is contained in:
Paolo A
2024-08-13 13:44:16 +00:00
parent 1bbb23088d
commit e796d76612
4001 changed files with 30101 additions and 40075 deletions

View File

@@ -17,12 +17,15 @@ use InvalidArgumentException;
* @method \Illuminate\Routing\Route options(string $uri, \Closure|array|string|null $action = null)
* @method \Illuminate\Routing\Route any(string $uri, \Closure|array|string|null $action = null)
* @method \Illuminate\Routing\RouteRegistrar as(string $value)
* @method \Illuminate\Routing\RouteRegistrar controller(string $controller)
* @method \Illuminate\Routing\RouteRegistrar domain(string $value)
* @method \Illuminate\Routing\RouteRegistrar middleware(array|string|null $middleware)
* @method \Illuminate\Routing\RouteRegistrar name(string $value)
* @method \Illuminate\Routing\RouteRegistrar namespace(string $value)
* @method \Illuminate\Routing\RouteRegistrar namespace(string|null $value)
* @method \Illuminate\Routing\RouteRegistrar prefix(string $prefix)
* @method \Illuminate\Routing\RouteRegistrar scopeBindings()
* @method \Illuminate\Routing\RouteRegistrar where(array $where)
* @method \Illuminate\Routing\RouteRegistrar withoutMiddleware(array|string $middleware)
*/
class RouteRegistrar
{
@@ -43,7 +46,7 @@ class RouteRegistrar
/**
* The methods to dynamically pass through to the router.
*
* @var array
* @var string[]
*/
protected $passthru = [
'get', 'post', 'put', 'patch', 'delete', 'options', 'any',
@@ -52,10 +55,19 @@ class RouteRegistrar
/**
* The attributes that can be set through this class.
*
* @var array
* @var string[]
*/
protected $allowedAttributes = [
'as', 'domain', 'middleware', 'name', 'namespace', 'prefix', 'where',
'as',
'controller',
'domain',
'middleware',
'name',
'namespace',
'prefix',
'scopeBindings',
'where',
'withoutMiddleware',
];
/**
@@ -65,6 +77,8 @@ class RouteRegistrar
*/
protected $aliases = [
'name' => 'as',
'scopeBindings' => 'scope_bindings',
'withoutMiddleware' => 'excluded_middleware',
];
/**
@@ -93,7 +107,21 @@ class RouteRegistrar
throw new InvalidArgumentException("Attribute [{$key}] does not exist.");
}
$this->attributes[Arr::get($this->aliases, $key, $key)] = $value;
if ($key === 'middleware') {
foreach ($value as $index => $middleware) {
$value[$index] = (string) $middleware;
}
}
$attributeKey = Arr::get($this->aliases, $key, $key);
if ($key === 'withoutMiddleware') {
$value = array_merge(
(array) ($this->attributes[$attributeKey] ?? []), Arr::wrap($value)
);
}
$this->attributes[$attributeKey] = $value;
return $this;
}
@@ -184,6 +212,9 @@ class RouteRegistrar
if (is_array($action) &&
! Arr::isAssoc($action) &&
Reflector::isCallable($action)) {
if (strncmp($action[0], '\\', 1)) {
$action[0] = '\\'.$action[0];
}
$action = [
'uses' => $action[0].'@'.$action[1],
'controller' => $action[0].'@'.$action[1],
@@ -213,7 +244,7 @@ class RouteRegistrar
return $this->attribute($method, is_array($parameters[0]) ? $parameters[0] : $parameters);
}
return $this->attribute($method, $parameters[0]);
return $this->attribute($method, array_key_exists(0, $parameters) ? $parameters[0] : true);
}
throw new BadMethodCallException(sprintf(