改名
This commit is contained in:
@@ -4,6 +4,14 @@
|
|||||||
namespace Annotation;
|
namespace Annotation;
|
||||||
|
|
||||||
|
|
||||||
|
use Annotation\Route\After;
|
||||||
|
use Annotation\Route\Interceptor;
|
||||||
|
use Annotation\Route\Limits;
|
||||||
|
use Annotation\Route\Middleware as RMiddleware;
|
||||||
|
use HttpServer\Route\Node;
|
||||||
|
use ReflectionException;
|
||||||
|
use Snowflake\Exception\ComponentException;
|
||||||
|
use Snowflake\Exception\NotFindClassException;
|
||||||
use Snowflake\Snowflake;
|
use Snowflake\Snowflake;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -23,4 +31,5 @@ abstract class Attribute implements IAnnotation
|
|||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -43,7 +43,8 @@ use Snowflake\Snowflake;
|
|||||||
// TODO: Implement setHandler() method.
|
// TODO: Implement setHandler() method.
|
||||||
$router = Snowflake::app()->getRouter();
|
$router = Snowflake::app()->getRouter();
|
||||||
|
|
||||||
$router->addRoute($this->uri, $handler, $this->method);
|
$node = $router->addRoute($this->uri, $handler, $this->method);
|
||||||
|
$node::annotationInject($node, get_class($handler[0]), $handler[1]);
|
||||||
|
|
||||||
return $router;
|
return $router;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -53,7 +53,9 @@ use Snowflake\Snowflake;
|
|||||||
|
|
||||||
$method = $this->event . '::' . (is_null($this->uri) ? 'event' : $this->uri);
|
$method = $this->event . '::' . (is_null($this->uri) ? 'event' : $this->uri);
|
||||||
|
|
||||||
$router->addRoute($method, $handler, 'sw::socket');
|
$node = $router->addRoute($method, $handler, 'sw::socket');
|
||||||
|
|
||||||
|
$node::annotationInject($node, get_class($handler[0]), $handler[1]);
|
||||||
|
|
||||||
return $router;
|
return $router;
|
||||||
}
|
}
|
||||||
|
|||||||
+35
-35
@@ -276,7 +276,7 @@ class Node extends HttpService
|
|||||||
throw new Exception('method ' . $action . ' not exists at ' . $controller . '.');
|
throw new Exception('method ' . $action . ' not exists at ' . $controller . '.');
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->annotationInject($reflect->getName(), $action);
|
static::annotationInject($this, $reflect->getName(), $action);
|
||||||
|
|
||||||
return [$reflect->newInstance(), $action];
|
return [$reflect->newInstance(), $action];
|
||||||
} catch (Throwable $exception) {
|
} catch (Throwable $exception) {
|
||||||
@@ -287,40 +287,6 @@ class Node extends HttpService
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param string $className
|
|
||||||
* @param string $action
|
|
||||||
* @return $this
|
|
||||||
* @throws ComponentException
|
|
||||||
* @throws NotFindClassException
|
|
||||||
* @throws ReflectionException
|
|
||||||
* @throws Exception
|
|
||||||
*/
|
|
||||||
private function annotationInject(string $className, string $action): static
|
|
||||||
{
|
|
||||||
$annotation = annotation()->getMethods($className, $action);
|
|
||||||
if (empty($annotation)) {
|
|
||||||
return $this;
|
|
||||||
}
|
|
||||||
foreach ($annotation as $name => $attribute) {
|
|
||||||
var_dump($this->path . ':' . get_class($attribute));
|
|
||||||
if ($attribute instanceof \Annotation\Route\Interceptor) {
|
|
||||||
$this->addInterceptor($attribute->interceptor);
|
|
||||||
}
|
|
||||||
if ($attribute instanceof \Annotation\Route\After) {
|
|
||||||
$this->addAfter($attribute->after);
|
|
||||||
}
|
|
||||||
if ($attribute instanceof RMiddleware) {
|
|
||||||
$this->addMiddleware($attribute->middleware);
|
|
||||||
}
|
|
||||||
if ($attribute instanceof \Annotation\Route\Limits) {
|
|
||||||
$this->addLimits($attribute->limits);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return $this;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param Closure|array|string $handler
|
* @param Closure|array|string $handler
|
||||||
* @throws Exception
|
* @throws Exception
|
||||||
@@ -339,6 +305,40 @@ class Node extends HttpService
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param Node $node
|
||||||
|
* @param string $className
|
||||||
|
* @param string $action
|
||||||
|
* @return Node
|
||||||
|
* @throws ComponentException
|
||||||
|
* @throws NotFindClassException
|
||||||
|
* @throws ReflectionException
|
||||||
|
* @throws Exception
|
||||||
|
*/
|
||||||
|
public static function annotationInject(Node $node, string $className, string $action): Node
|
||||||
|
{
|
||||||
|
$annotation = annotation()->getMethods($className, $action);
|
||||||
|
if (empty($annotation)) {
|
||||||
|
return $node;
|
||||||
|
}
|
||||||
|
foreach ($annotation as $name => $attribute) {
|
||||||
|
if ($attribute instanceof \Annotation\Route\Interceptor) {
|
||||||
|
$node->addInterceptor($attribute->interceptor);
|
||||||
|
}
|
||||||
|
if ($attribute instanceof \Annotation\Route\After) {
|
||||||
|
$node->addAfter($attribute->after);
|
||||||
|
}
|
||||||
|
if ($attribute instanceof RMiddleware) {
|
||||||
|
$node->addMiddleware($attribute->middleware);
|
||||||
|
}
|
||||||
|
if ($attribute instanceof \Annotation\Route\Limits) {
|
||||||
|
$node->addLimits($attribute->limits);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return $node;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param Closure|array|string $handler
|
* @param Closure|array|string $handler
|
||||||
* @throws Exception
|
* @throws Exception
|
||||||
|
|||||||
Reference in New Issue
Block a user