This commit is contained in:
2021-03-03 18:35:04 +08:00
parent 1c6cde4133
commit c337280d4e
25 changed files with 533 additions and 499 deletions
+11 -8
View File
@@ -4,32 +4,35 @@
namespace Annotation\Route;
use Annotation\IAnnotation;
use JetBrains\PhpStorm\Pure;
use ReflectionException;
use Snowflake\Exception\NotFindClassException;
use Annotation\Attribute;
use Snowflake\Snowflake;
/**
* Class Middleware
* @package Annotation\Route
*/
#[\Attribute(\Attribute::TARGET_METHOD)] class Middleware implements IAnnotation
#[\Attribute(\Attribute::TARGET_METHOD)] class Middleware extends Attribute
{
use Node;
/**
* Interceptor constructor.
* @param string|array $middleware
* @throws
*/
#[Pure] public function __construct(public string|array $middleware)
public function __construct(public string|array $middleware)
{
if (is_string($this->middleware)) {
$this->middleware = [$this->middleware];
}
foreach ($this->middleware as $key => $value) {
$sn = Snowflake::createObject($value);
if (!($sn instanceof \HttpServer\IInterface\Middleware)) {
continue;
}
$this->middleware[$key] = [$sn, 'onHandler'];
}
}