改名
This commit is contained in:
+27
-28
@@ -5,38 +5,37 @@ namespace Annotation\Route;
|
||||
|
||||
|
||||
use Annotation\Attribute;
|
||||
use Http\Route\MiddlewareManager;
|
||||
use ReflectionException;
|
||||
use Http\IInterface\MiddlewareInterface;
|
||||
use Http\Route\MiddlewareManager;
|
||||
|
||||
/**
|
||||
* Class Middleware
|
||||
* @package Annotation\Route
|
||||
*/
|
||||
#[\Attribute(\Attribute::TARGET_METHOD)] class Middleware extends Attribute
|
||||
#[\Attribute(\Attribute::TARGET_METHOD | \Attribute::IS_REPEATABLE)] class Middleware extends Attribute
|
||||
{
|
||||
|
||||
|
||||
/**
|
||||
* Interceptor constructor.
|
||||
* @param string|array $middleware
|
||||
* @throws
|
||||
*/
|
||||
public function __construct(public string|array $middleware)
|
||||
{
|
||||
if (is_string($this->middleware)) {
|
||||
$this->middleware = [$this->middleware];
|
||||
}
|
||||
$array = [];
|
||||
foreach ($this->middleware as $value) {
|
||||
$sn = di($value);
|
||||
if (!($sn instanceof MiddlewareInterface)) {
|
||||
continue;
|
||||
}
|
||||
$array[] = [$sn, 'onHandler'];
|
||||
}
|
||||
$this->middleware = $array;
|
||||
}
|
||||
/**
|
||||
* Interceptor constructor.
|
||||
* @param string|array $middleware
|
||||
* @throws
|
||||
*/
|
||||
public function __construct(public string|array $middleware)
|
||||
{
|
||||
if (is_string($this->middleware)) {
|
||||
$this->middleware = [$this->middleware];
|
||||
}
|
||||
$array = [];
|
||||
foreach ($this->middleware as $value) {
|
||||
$sn = di($value);
|
||||
if (!($sn instanceof MiddlewareInterface)) {
|
||||
continue;
|
||||
}
|
||||
$array[] = [$sn, 'onHandler'];
|
||||
}
|
||||
$this->middleware = $array;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
@@ -44,11 +43,11 @@ use Http\IInterface\MiddlewareInterface;
|
||||
* @param mixed|null $method
|
||||
* @return $this
|
||||
*/
|
||||
public function execute(mixed $class, mixed $method = null): mixed
|
||||
{
|
||||
MiddlewareManager::add($class, $method, $this->middleware);
|
||||
return parent::execute($class, $method);
|
||||
}
|
||||
public function execute(mixed $class, mixed $method = null): mixed
|
||||
{
|
||||
MiddlewareManager::add($class, $method, $this->middleware);
|
||||
return parent::execute($class, $method);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user