This commit is contained in:
2023-04-16 12:44:43 +08:00
parent 218fd19135
commit 9f5afeab54
8 changed files with 118 additions and 41 deletions
+35
View File
@@ -26,6 +26,41 @@ class Middleware
}
/**
* @param string $className
* @param string $method
* @param string $middleware
* @param array $construct
* @return void
* @throws Exception
*/
public function set(string $className, string $method, string $middleware, array $construct = []): void
{
$path = $className . '::' . $method;
if ($this->map->has($path)) {
$values = $this->map->get($path);
if (in_array($middleware, $values)) {
return;
}
if (!in_array(MiddlewareInterface::class, class_implements($middleware))) {
return;
}
}
$this->map->append($path, [$middleware, $construct]);
}
/**
* @param string $className
* @param string $method
* @return array
*/
public function get(string $className, string $method): array
{
return $this->routeMap->get($className . '::' . $method) ?? [];
}
/**
* @param string $path
* @param mixed $middleware