eee
This commit is contained in:
+42
-38
@@ -11,50 +11,54 @@ class Middleware
|
|||||||
{
|
{
|
||||||
|
|
||||||
|
|
||||||
public HashMap $map;
|
/**
|
||||||
|
* @var array
|
||||||
|
*/
|
||||||
|
protected array $manager = [];
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public function __construct()
|
public function __construct()
|
||||||
{
|
{
|
||||||
$this->map = new HashMap();
|
}
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param string $className
|
* @param string $className
|
||||||
* @param string $method
|
* @param string $method
|
||||||
* @param string|object $middleware
|
* @param string|object $middleware
|
||||||
* @return void
|
* @return void
|
||||||
* @throws Exception
|
* @throws Exception
|
||||||
*/
|
*/
|
||||||
public function set(string $className, string $method, string|object $middleware): void
|
public function set(string $className, string $method, string|object $middleware): void
|
||||||
{
|
{
|
||||||
$path = $className . '::' . $method;
|
$path = $className . '::' . $method;
|
||||||
if ($this->map->has($path)) {
|
if (isset($this->manager[$path])) {
|
||||||
$values = $this->map->get($path);
|
$values = $this->manager[$path];
|
||||||
if (in_array($middleware, $values)) {
|
if (in_array($middleware, $values)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (!in_array(MiddlewareInterface::class, class_implements($middleware))) {
|
if (!in_array(MiddlewareInterface::class, class_implements($middleware))) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
$this->map->append($path, $middleware);
|
$this->manager[$path] = [];
|
||||||
}
|
}
|
||||||
|
$this->manager[$path][] = $middleware;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param string $className
|
* @param string $className
|
||||||
* @param string $method
|
* @param string $method
|
||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
public function get(string $className, string $method): array
|
public function get(string $className, string $method): array
|
||||||
{
|
{
|
||||||
return $this->map->get($className . '::' . $method) ?? [];
|
return $this->manager[$className . '::' . $method] ?? [];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user