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