改名
This commit is contained in:
+21
-15
@@ -4,13 +4,16 @@
|
||||
namespace Annotation\Route;
|
||||
|
||||
|
||||
use Annotation\IAnnotation;
|
||||
use ReflectionException;
|
||||
use Snowflake\Exception\NotFindClassException;
|
||||
use Snowflake\Snowflake;
|
||||
|
||||
/**
|
||||
* Class Interceptor
|
||||
* @package Annotation\Route
|
||||
*/
|
||||
#[\Attribute(\Attribute::TARGET_METHOD)] class After
|
||||
#[\Attribute(\Attribute::TARGET_METHOD)] class After implements IAnnotation
|
||||
{
|
||||
|
||||
|
||||
@@ -18,27 +21,30 @@ use Snowflake\Snowflake;
|
||||
* Interceptor constructor.
|
||||
* @param \HttpServer\IInterface\After|\HttpServer\IInterface\After[] $after
|
||||
* @throws
|
||||
* if ($object instanceof Interceptor) {
|
||||
$classes[$key] = [$object, 'Interceptor'];
|
||||
}
|
||||
if ($object instanceof Limits) {
|
||||
$classes[$key] = [$object, 'next'];
|
||||
}
|
||||
if ($object instanceof After) {
|
||||
$classes[$key] = [$object, 'onHandler'];
|
||||
}
|
||||
if ($object instanceof Middleware) {
|
||||
$classes[$key] = [$object, 'onHandler'];
|
||||
}
|
||||
*/
|
||||
public function __construct(public string|array $after)
|
||||
{
|
||||
if (is_string($this->after)) {
|
||||
$this->after = [$this->after];
|
||||
if (!is_string($this->after)) {
|
||||
return;
|
||||
}
|
||||
$this->after = [$this->after];
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param array $handler
|
||||
* @return array|string
|
||||
* @throws ReflectionException
|
||||
* @throws NotFindClassException
|
||||
*/
|
||||
public function execute(array $handler): array|string
|
||||
{
|
||||
// TODO: Implement execute() method.
|
||||
foreach ($this->after as $key => $item) {
|
||||
$this->after[$key] = [Snowflake::createObject($item), 'onHandler'];
|
||||
}
|
||||
return $this->after;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -4,11 +4,13 @@
|
||||
namespace Annotation\Route;
|
||||
|
||||
|
||||
use Annotation\IAnnotation;
|
||||
|
||||
/**
|
||||
* Class Document
|
||||
* @package Annotation\Route
|
||||
*/
|
||||
#[\Attribute(\Attribute::TARGET_METHOD)] class Document
|
||||
#[\Attribute(\Attribute::TARGET_METHOD)] class Document implements IAnnotation
|
||||
{
|
||||
|
||||
const INTEGER = 'int';
|
||||
@@ -31,4 +33,15 @@ namespace Annotation\Route;
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param array $handler
|
||||
* @return array
|
||||
*/
|
||||
public function execute(array $handler): array
|
||||
{
|
||||
// TODO: Implement execute() method.
|
||||
return [$this->request, $this->response];
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -4,13 +4,16 @@
|
||||
namespace Annotation\Route;
|
||||
|
||||
|
||||
use Annotation\IAnnotation;
|
||||
use ReflectionException;
|
||||
use Snowflake\Exception\NotFindClassException;
|
||||
use Snowflake\Snowflake;
|
||||
|
||||
/**
|
||||
* Class Interceptor
|
||||
* @package Annotation\Route
|
||||
*/
|
||||
#[\Attribute(\Attribute::TARGET_METHOD)] class Interceptor
|
||||
#[\Attribute(\Attribute::TARGET_METHOD)] class Interceptor implements IAnnotation
|
||||
{
|
||||
|
||||
|
||||
@@ -21,12 +24,26 @@ use Snowflake\Snowflake;
|
||||
*/
|
||||
public function __construct(public string|array $interceptor)
|
||||
{
|
||||
if (is_string($this->interceptor)) {
|
||||
$this->interceptor = [$this->interceptor];
|
||||
if (!is_string($this->interceptor)) {
|
||||
return;
|
||||
}
|
||||
$this->interceptor = [$this->interceptor];
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param array $handler
|
||||
* @return array|string
|
||||
* @throws ReflectionException
|
||||
* @throws NotFindClassException
|
||||
*/
|
||||
public function execute(array $handler): array|string
|
||||
{
|
||||
// TODO: Implement execute() method.
|
||||
foreach ($this->interceptor as $key => $item) {
|
||||
$this->interceptor[$key] = [Snowflake::createObject($item), 'Interceptor'];
|
||||
}
|
||||
return $this->interceptor;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -4,13 +4,16 @@
|
||||
namespace Annotation\Route;
|
||||
|
||||
|
||||
use Annotation\IAnnotation;
|
||||
use ReflectionException;
|
||||
use Snowflake\Exception\NotFindClassException;
|
||||
use Snowflake\Snowflake;
|
||||
|
||||
/**
|
||||
* Class Limits
|
||||
* @package Annotation\Route
|
||||
*/
|
||||
#[\Attribute(\Attribute::TARGET_METHOD)] class Limits
|
||||
#[\Attribute(\Attribute::TARGET_METHOD)] class Limits implements IAnnotation
|
||||
{
|
||||
|
||||
|
||||
@@ -21,12 +24,26 @@ use Snowflake\Snowflake;
|
||||
*/
|
||||
public function __construct(public string|array $limits)
|
||||
{
|
||||
if (is_string($this->limits)) {
|
||||
$this->limits = [$this->limits];
|
||||
if (!is_string($this->limits)) {
|
||||
return;
|
||||
}
|
||||
$this->limits = [$this->limits];
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param array $handler
|
||||
* @return array|string
|
||||
* @throws ReflectionException
|
||||
* @throws NotFindClassException
|
||||
*/
|
||||
public function execute(array $handler): array|string
|
||||
{
|
||||
// TODO: Implement execute() method.
|
||||
foreach ($this->limits as $key => $item) {
|
||||
$this->limits[$key] = [Snowflake::createObject($item), 'next'];
|
||||
}
|
||||
return $this->limits;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -4,13 +4,17 @@
|
||||
namespace Annotation\Route;
|
||||
|
||||
|
||||
use Annotation\IAnnotation;
|
||||
use JetBrains\PhpStorm\Pure;
|
||||
use ReflectionException;
|
||||
use Snowflake\Exception\NotFindClassException;
|
||||
use Snowflake\Snowflake;
|
||||
|
||||
/**
|
||||
* Class Middleware
|
||||
* @package Annotation\Route
|
||||
*/
|
||||
#[\Attribute(\Attribute::TARGET_METHOD)] class Middleware
|
||||
#[\Attribute(\Attribute::TARGET_METHOD)] class Middleware implements IAnnotation
|
||||
{
|
||||
|
||||
|
||||
@@ -21,12 +25,27 @@ use Snowflake\Snowflake;
|
||||
*/
|
||||
public function __construct(public string|array $middleware)
|
||||
{
|
||||
if (is_string($this->middleware)) {
|
||||
$this->middleware = [$this->middleware];
|
||||
if (!is_string($this->middleware)) {
|
||||
return;
|
||||
}
|
||||
$this->middleware = [$this->middleware];
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param array $handler
|
||||
* @return array|string
|
||||
* @throws ReflectionException
|
||||
* @throws NotFindClassException
|
||||
*/
|
||||
public function execute(array $handler): array|string
|
||||
{
|
||||
// TODO: Implement execute() method.
|
||||
foreach ($this->middleware as $key => $item) {
|
||||
$this->middleware[$key] = [Snowflake::createObject($item), 'onHandler'];
|
||||
}
|
||||
return $this->middleware;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -7,6 +7,7 @@ namespace Annotation\Route;
|
||||
use Closure;
|
||||
use Exception;
|
||||
use HttpServer\Route\Node;
|
||||
use HttpServer\Route\Router;
|
||||
use Snowflake\Exception\ComponentException;
|
||||
use Snowflake\Exception\ConfigException;
|
||||
use Snowflake\Snowflake;
|
||||
@@ -29,18 +30,19 @@ use Annotation\IAnnotation;
|
||||
|
||||
|
||||
/**
|
||||
* @param array|Closure $handler
|
||||
* @return ?Node
|
||||
* @param array $handler
|
||||
* @return Router
|
||||
* @throws ComponentException
|
||||
* @throws ConfigException
|
||||
* @throws Exception
|
||||
*/
|
||||
public function setHandler(array|Closure $handler): ?Node
|
||||
public function execute(array $handler): Router
|
||||
{
|
||||
$router = Snowflake::app()->getRouter();
|
||||
// TODO: Implement setHandler() method.
|
||||
$router = Snowflake::app()->getRouter();
|
||||
|
||||
return $router->addRoute($this->uri, $handler, $this->method);
|
||||
$router->addRoute($this->uri, $handler, $this->method);
|
||||
|
||||
return $router;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -8,6 +8,7 @@ use Annotation\IAnnotation;
|
||||
use Closure;
|
||||
use Exception;
|
||||
use HttpServer\Route\Node;
|
||||
use HttpServer\Route\Router;
|
||||
use ReflectionException;
|
||||
use Snowflake\Exception\ComponentException;
|
||||
use Snowflake\Exception\ConfigException;
|
||||
@@ -39,20 +40,21 @@ use Snowflake\Snowflake;
|
||||
|
||||
|
||||
/**
|
||||
* @param array|Closure $handler
|
||||
* @return Node|null
|
||||
* @param array $handler
|
||||
* @return Router
|
||||
* @throws ComponentException
|
||||
* @throws ConfigException
|
||||
* @throws Exception
|
||||
*/
|
||||
public function setHandler(array|Closure $handler): ?Node
|
||||
public function execute(array $handler): Router
|
||||
{
|
||||
$router = Snowflake::app()->getRouter();
|
||||
// TODO: Implement setHandler() method.
|
||||
$router = Snowflake::app()->getRouter();
|
||||
|
||||
$method = $this->event . '::' . (is_null($this->uri) ? 'event' : $this->uri);
|
||||
|
||||
return $router->addRoute($method, $handler, 'sw::socket');
|
||||
$router->addRoute($method, $handler, 'sw::socket');
|
||||
|
||||
return $router;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user