改名
This commit is contained in:
@@ -1,33 +0,0 @@
|
||||
<?php
|
||||
|
||||
|
||||
namespace Annotation;
|
||||
|
||||
|
||||
use Closure;
|
||||
|
||||
#[\Attribute(\Attribute::TARGET_METHOD)] class After
|
||||
{
|
||||
|
||||
|
||||
/**
|
||||
* Middleware constructor.
|
||||
* @param string|array $handler
|
||||
*/
|
||||
public function __construct(
|
||||
private string|array $handler
|
||||
)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return array|string
|
||||
*/
|
||||
public function getMiddleware(): array|string
|
||||
{
|
||||
return $this->handler;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -11,10 +11,11 @@ interface IAnnotation
|
||||
|
||||
|
||||
/**
|
||||
* @param array|Closure $closure
|
||||
* @param array|Closure $handler
|
||||
* @param array $attributes
|
||||
* @return mixed
|
||||
*/
|
||||
public function setHandler(array|Closure $closure): mixed;
|
||||
public function setHandler(array|Closure $handler, array $attributes): mixed;
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -1,33 +0,0 @@
|
||||
<?php
|
||||
|
||||
|
||||
namespace Annotation;
|
||||
|
||||
|
||||
use Closure;
|
||||
|
||||
#[\Attribute(\Attribute::TARGET_METHOD)] class Interceptor
|
||||
{
|
||||
|
||||
|
||||
/**
|
||||
* Middleware constructor.
|
||||
* @param string|array $handler
|
||||
*/
|
||||
public function __construct(
|
||||
private string|array $handler
|
||||
)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return array|string
|
||||
*/
|
||||
public function getMiddleware(): array|string
|
||||
{
|
||||
return $this->handler;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -1,33 +0,0 @@
|
||||
<?php
|
||||
|
||||
|
||||
namespace Annotation;
|
||||
|
||||
|
||||
use Closure;
|
||||
|
||||
#[\Attribute(\Attribute::TARGET_METHOD)] class Limits
|
||||
{
|
||||
|
||||
|
||||
/**
|
||||
* Middleware constructor.
|
||||
* @param string|array $handler
|
||||
*/
|
||||
public function __construct(
|
||||
private string|array $handler
|
||||
)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return array|string
|
||||
*/
|
||||
public function getMiddleware(): array|string
|
||||
{
|
||||
return $this->handler;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -1,33 +0,0 @@
|
||||
<?php
|
||||
|
||||
|
||||
namespace Annotation;
|
||||
|
||||
|
||||
use Closure;
|
||||
|
||||
#[\Attribute(\Attribute::TARGET_METHOD)] class Middleware
|
||||
{
|
||||
|
||||
|
||||
/**
|
||||
* Middleware constructor.
|
||||
* @param string|array $handler
|
||||
*/
|
||||
public function __construct(
|
||||
private string|array $handler
|
||||
)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return array|string
|
||||
*/
|
||||
public function getMiddleware(): array|string
|
||||
{
|
||||
return $this->handler;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
<?php
|
||||
|
||||
|
||||
namespace Annotation;
|
||||
|
||||
|
||||
/**
|
||||
* Class RequestValidator
|
||||
* @package Annotation
|
||||
*/
|
||||
#[\Attribute(\Attribute::TARGET_METHOD)] class RequestValidator
|
||||
{
|
||||
|
||||
/**
|
||||
* RequestValidator constructor.
|
||||
* @param array $validators
|
||||
*/
|
||||
public function __construct(public array $validators)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
|
||||
namespace Annotation\Route;
|
||||
|
||||
|
||||
trait Node
|
||||
{
|
||||
|
||||
|
||||
/**
|
||||
* @param $node
|
||||
* @return mixed
|
||||
*/
|
||||
public function add($node): mixed
|
||||
{
|
||||
if (!empty($this->middleware)) {
|
||||
$node->addMiddleware($this->middleware);
|
||||
}
|
||||
if (!empty($this->interceptor)) {
|
||||
$node->addInterceptor($this->interceptor);
|
||||
}
|
||||
if (!empty($this->limits)) {
|
||||
$node->addLimits($this->limits);
|
||||
}
|
||||
if (!empty($this->after)) {
|
||||
$node->addAfter($this->after);
|
||||
}
|
||||
return $node;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,18 +1,21 @@
|
||||
<?php
|
||||
|
||||
|
||||
namespace Annotation;
|
||||
namespace Annotation\Route;
|
||||
|
||||
|
||||
use Closure;
|
||||
use Exception;
|
||||
use HttpServer\Route\Node;
|
||||
use Snowflake\Exception\ComponentException;
|
||||
use Snowflake\Exception\ConfigException;
|
||||
use Snowflake\Snowflake;
|
||||
use Annotation\IAnnotation;
|
||||
|
||||
#[\Attribute(\Attribute::TARGET_METHOD)] class Route implements IAnnotation
|
||||
{
|
||||
|
||||
use \Annotation\Route\Node;
|
||||
|
||||
/**
|
||||
* Route constructor.
|
||||
@@ -41,6 +44,7 @@ use Snowflake\Snowflake;
|
||||
* @return ?Node
|
||||
* @throws ComponentException
|
||||
* @throws ConfigException
|
||||
* @throws Exception
|
||||
*/
|
||||
public function setHandler(array|Closure $handler, array $attributes): ?Node
|
||||
{
|
||||
@@ -48,16 +52,8 @@ use Snowflake\Snowflake;
|
||||
// TODO: Implement setHandler() method.
|
||||
|
||||
$node = $router->addRoute($this->uri, $handler, $this->method);
|
||||
foreach ($attributes as $name => $attribute) {
|
||||
$first = 'add' . ucfirst($attribute);
|
||||
|
||||
$_handler = is_array($handler) ? $handler[0] : $handler;
|
||||
if (!method_exists($_handler, $first)) {
|
||||
continue;
|
||||
}
|
||||
$node->$first($attribute);
|
||||
}
|
||||
return $node;
|
||||
return $this->add($node);
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,70 @@
|
||||
<?php
|
||||
|
||||
|
||||
namespace Annotation\Route;
|
||||
|
||||
|
||||
use Closure;
|
||||
use Exception;
|
||||
use HttpServer\Route\Node;
|
||||
use ReflectionException;
|
||||
use Snowflake\Exception\ComponentException;
|
||||
use Snowflake\Exception\ConfigException;
|
||||
use Snowflake\Exception\NotFindClassException;
|
||||
use Snowflake\Snowflake;
|
||||
|
||||
/**
|
||||
* Class Socket
|
||||
* @package Annotation
|
||||
*/
|
||||
#[\Attribute(\Attribute::TARGET_METHOD)] class Socket
|
||||
{
|
||||
|
||||
const CLOSE = 'CLOSE';
|
||||
const MESSAGE = 'MESSAGE';
|
||||
const HANDSHAKE = 'HANDSHAKE';
|
||||
|
||||
use \Annotation\Route\Node;
|
||||
|
||||
|
||||
/**
|
||||
* Socket constructor.
|
||||
* @param string $event
|
||||
* @param string|null $uri
|
||||
* @param array|null $middleware
|
||||
* @param array|null $interceptor
|
||||
* @param array|null $limits
|
||||
* @param array|null $after
|
||||
*/
|
||||
public function __construct(
|
||||
public string $event,
|
||||
public ?string $uri,
|
||||
public ?array $middleware = null,
|
||||
public ?array $interceptor = null,
|
||||
public ?array $limits = null,
|
||||
public ?array $after = null
|
||||
)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param array|Closure $handler
|
||||
* @param array $attributes
|
||||
* @return Node|null
|
||||
* @throws ComponentException
|
||||
* @throws ConfigException
|
||||
* @throws Exception
|
||||
*/
|
||||
public function setHandler(array|Closure $handler, array $attributes): ?Node
|
||||
{
|
||||
$router = Snowflake::app()->getRouter();
|
||||
// TODO: Implement setHandler() method.
|
||||
|
||||
$method = $this->event . '::' . ($this->uri ?? 'event');
|
||||
$node = $router->addRoute($method, $handler, 'sw::socket');
|
||||
|
||||
return $this->add($node);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,52 +0,0 @@
|
||||
<?php
|
||||
|
||||
|
||||
namespace Annotation;
|
||||
|
||||
|
||||
use Closure;
|
||||
use HttpServer\Route\Node;
|
||||
use Snowflake\Exception\ComponentException;
|
||||
use Snowflake\Snowflake;
|
||||
|
||||
/**
|
||||
* Class Socket
|
||||
* @package Annotation
|
||||
*/
|
||||
#[\Attribute(\Attribute::TARGET_METHOD)] class Socket
|
||||
{
|
||||
|
||||
const CLOSE = 'CLOSE';
|
||||
const MESSAGE = 'MESSAGE';
|
||||
const HANDSHAKE = 'HANDSHAKE';
|
||||
|
||||
|
||||
/**
|
||||
* Socket constructor.
|
||||
* @param string $event
|
||||
* @param string|null $uri
|
||||
*/
|
||||
public function __construct(
|
||||
public string $event,
|
||||
public ?string $uri
|
||||
)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param Closure|array $closure
|
||||
* @return mixed
|
||||
* @throws ComponentException
|
||||
*/
|
||||
public function setHandler(Closure|array $closure): mixed
|
||||
{
|
||||
$router = Snowflake::app()->getRouter();
|
||||
// TODO: Implement setHandler() method.
|
||||
|
||||
$method = $this->event . '::' . ($this->uri ?? 'event');
|
||||
|
||||
return $router->addRoute($method, $closure, 'sw::socket');
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user