eee
This commit is contained in:
+12
-5
@@ -4,7 +4,6 @@ declare(strict_types=1);
|
|||||||
namespace Kiri\Router\Base;
|
namespace Kiri\Router\Base;
|
||||||
|
|
||||||
use Kiri;
|
use Kiri;
|
||||||
use Psr\Http\Server\MiddlewareInterface;
|
|
||||||
|
|
||||||
class Middleware
|
class Middleware
|
||||||
{
|
{
|
||||||
@@ -26,15 +25,23 @@ class Middleware
|
|||||||
* @return void
|
* @return void
|
||||||
* @throws
|
* @throws
|
||||||
*/
|
*/
|
||||||
public static function set(string $className, string $method, string $middleware): void
|
public static function set(string $className, string $method, string|object $middleware): void
|
||||||
{
|
{
|
||||||
$path = $className . '::' . $method;
|
$path = $className . '::' . $method;
|
||||||
if (!isset(static::$manager[$path])) {
|
if (!isset(static::$manager[$path])) {
|
||||||
static::$manager[$path] = static::$mapping[$path] = [];
|
static::$manager[$path] = static::$mapping[$path] = [];
|
||||||
}
|
}
|
||||||
if (!in_array($middleware, static::$mapping[$path])) {
|
|
||||||
static::$manager[$path][] = Kiri::getDi()->get($middleware);
|
if (is_object($middleware)) {
|
||||||
static::$mapping[$path][] = $middleware;
|
if (!in_array($middleware::class, static::$mapping[$path])) {
|
||||||
|
static::$manager[$path][] = $middleware;
|
||||||
|
static::$mapping[$path][] = $middleware::class;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (!in_array($middleware, static::$mapping[$path])) {
|
||||||
|
static::$manager[$path][] = Kiri::getDi()->get($middleware);
|
||||||
|
static::$mapping[$path][] = $middleware;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user