This commit is contained in:
2023-04-15 23:31:16 +08:00
parent 2d9ac93a7a
commit 41a53200b3
69 changed files with 1678 additions and 749 deletions
+40
View File
@@ -2,7 +2,47 @@
namespace Kiri\Router\Base;
use Exception;
use Kiri\Core\HashMap;
use Psr\Http\Server\MiddlewareInterface;
class Middleware
{
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);
}
}