Files
kiri-router/src/Base/Middleware.php
T

49 lines
777 B
PHP
Raw Normal View History

2023-04-15 23:29:27 +08:00
<?php
namespace Kiri\Router\Base;
2023-04-15 23:31:16 +08:00
use Exception;
use Kiri\Core\HashMap;
use Psr\Http\Server\MiddlewareInterface;
2023-04-15 23:29:27 +08:00
class Middleware
{
2023-04-15 23:31:16 +08:00
public HashMap $map;
public HashMap $routeMap;
/**
*
*/
public function __construct()
{
$this->routeMap = new HashMap();
$this->map = new HashMap();
}
/**
* @param string $path
* @param mixed $middleware
* @return void
* @throws Exception
*/
public function addPathMiddleware(string $path, string $middleware): void
{
if ($this->routeMap->has($path)) {
$values = $this->routeMap->get($path);
if (in_array($middleware, $values)) {
return;
}
if (!in_array(MiddlewareInterface::class, class_implements($middleware))) {
return;
}
}
$this->routeMap->append($path, $middleware);
}
2023-04-15 23:29:27 +08:00
}