改名
This commit is contained in:
@@ -16,6 +16,7 @@ use Snowflake\Snowflake;
|
||||
#[\Attribute(\Attribute::TARGET_METHOD)] class After implements IAnnotation
|
||||
{
|
||||
|
||||
use Node;
|
||||
|
||||
/**
|
||||
* Interceptor constructor.
|
||||
@@ -24,6 +25,9 @@ use Snowflake\Snowflake;
|
||||
*/
|
||||
public function __construct(public string|array $after)
|
||||
{
|
||||
if (is_string($this->after)) {
|
||||
$this->after = [];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -5,6 +5,7 @@ namespace Annotation\Route;
|
||||
|
||||
|
||||
use Annotation\IAnnotation;
|
||||
use JetBrains\PhpStorm\Pure;
|
||||
use ReflectionException;
|
||||
use Snowflake\Exception\NotFindClassException;
|
||||
use Snowflake\Snowflake;
|
||||
@@ -16,14 +17,18 @@ use Snowflake\Snowflake;
|
||||
#[\Attribute(\Attribute::TARGET_METHOD)] class Interceptor implements IAnnotation
|
||||
{
|
||||
|
||||
use Node;
|
||||
|
||||
/**
|
||||
* Interceptor constructor.
|
||||
* @param string|array $interceptor
|
||||
* @throws
|
||||
*/
|
||||
public function __construct(public string|array $interceptor)
|
||||
#[Pure] public function __construct(public string|array $interceptor)
|
||||
{
|
||||
if (is_string($this->interceptor)) {
|
||||
$this->interceptor = [];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -16,6 +16,7 @@ use Snowflake\Snowflake;
|
||||
#[\Attribute(\Attribute::TARGET_METHOD)] class Limits implements IAnnotation
|
||||
{
|
||||
|
||||
use Node;
|
||||
|
||||
/**
|
||||
* Limits constructor.
|
||||
@@ -24,6 +25,9 @@ use Snowflake\Snowflake;
|
||||
*/
|
||||
public function __construct(public string|array $limits)
|
||||
{
|
||||
if (is_string($this->limits)) {
|
||||
$this->limits = [];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -17,6 +17,8 @@ use Snowflake\Snowflake;
|
||||
#[\Attribute(\Attribute::TARGET_METHOD)] class Middleware implements IAnnotation
|
||||
{
|
||||
|
||||
use Node;
|
||||
|
||||
|
||||
/**
|
||||
* Interceptor constructor.
|
||||
@@ -25,6 +27,9 @@ use Snowflake\Snowflake;
|
||||
*/
|
||||
public function __construct(public string|array $middleware)
|
||||
{
|
||||
if (is_string($this->middleware)) {
|
||||
$this->middleware = [];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -7,7 +7,6 @@ use HttpServer\IInterface\After;
|
||||
use HttpServer\IInterface\Interceptor;
|
||||
use HttpServer\IInterface\Limits;
|
||||
use HttpServer\IInterface\Middleware;
|
||||
use HttpServer\Route\Node as RNode;
|
||||
use ReflectionException;
|
||||
use Snowflake\Exception\NotFindClassException;
|
||||
use Snowflake\Snowflake;
|
||||
@@ -16,36 +15,13 @@ trait Node
|
||||
{
|
||||
|
||||
|
||||
/**
|
||||
* @param RNode $node
|
||||
* @return RNode
|
||||
* @throws
|
||||
*/
|
||||
public function add(RNode $node): RNode
|
||||
{
|
||||
if (!empty($this->middleware)) {
|
||||
$node->addMiddleware($this->reflectClass($this->middleware));
|
||||
}
|
||||
if (!empty($this->interceptor)) {
|
||||
$node->addInterceptor($this->reflectClass($this->interceptor));
|
||||
}
|
||||
if (!empty($this->limits)) {
|
||||
$node->addLimits($this->reflectClass($this->limits));
|
||||
}
|
||||
if (!empty($this->after)) {
|
||||
$node->addAfter($this->reflectClass($this->after));
|
||||
}
|
||||
return $node;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param array $classes
|
||||
* @return array
|
||||
* @throws ReflectionException
|
||||
* @throws NotFindClassException
|
||||
*/
|
||||
private function reflectClass(array $classes): array
|
||||
public function reflectClass(array $classes): array
|
||||
{
|
||||
$di = Snowflake::getDi();
|
||||
foreach ($classes as $key => $class) {
|
||||
|
||||
@@ -77,22 +77,17 @@ class Middleware
|
||||
return;
|
||||
}
|
||||
foreach ($annotation as $attribute) {
|
||||
var_dump($attribute);
|
||||
if ($attribute instanceof Interceptor) {
|
||||
var_dump($attribute);
|
||||
$node->addInterceptor($attribute->interceptor);
|
||||
$node->addInterceptor($attribute->reflectClass($attribute->interceptor));
|
||||
}
|
||||
if ($attribute instanceof After) {
|
||||
var_dump($attribute);
|
||||
$node->addAfter($attribute->after);
|
||||
$node->addInterceptor($attribute->reflectClass($attribute->after));
|
||||
}
|
||||
if ($attribute instanceof RMiddleware) {
|
||||
var_dump($attribute);
|
||||
$node->addMiddleware($attribute->middleware);
|
||||
$node->addInterceptor($attribute->reflectClass($attribute->middleware));
|
||||
}
|
||||
if ($attribute instanceof Limits) {
|
||||
var_dump($attribute);
|
||||
$node->addLimits($attribute->limits);
|
||||
$node->addInterceptor($attribute->reflectClass($attribute->limits));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user