改名
This commit is contained in:
@@ -0,0 +1,48 @@
|
||||
<?php
|
||||
|
||||
|
||||
namespace Annotation\Route;
|
||||
|
||||
|
||||
use Annotation\Attribute;
|
||||
|
||||
/**
|
||||
* Class Document
|
||||
* @package Annotation\Route
|
||||
*/
|
||||
#[\Attribute(\Attribute::TARGET_METHOD)] class Document extends Attribute
|
||||
{
|
||||
|
||||
const INTEGER = 'int';
|
||||
const STRING = 'string';
|
||||
const BOOLEAN = 'bool';
|
||||
const FLOAT = 'float';
|
||||
|
||||
const ALIAS = [
|
||||
self::INTEGER => '整数',
|
||||
self::STRING => '字符串',
|
||||
self::BOOLEAN => '布尔值',
|
||||
self::FLOAT => '浮点',
|
||||
];
|
||||
|
||||
|
||||
public function __construct(
|
||||
public array $request,
|
||||
public array $response
|
||||
)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param mixed $class
|
||||
* @param mixed|null $method
|
||||
* @return array
|
||||
*/
|
||||
public function execute(mixed $class, mixed $method = null): array
|
||||
{
|
||||
// TODO: Implement execute() method.
|
||||
return [$this->request, $this->response];
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
<?php
|
||||
|
||||
|
||||
namespace Annotation\Route;
|
||||
|
||||
|
||||
use Annotation\Attribute;
|
||||
use Exception;
|
||||
use Http\HttpFilter;
|
||||
use ReflectionException;
|
||||
use Kiri\Exception\ComponentException;
|
||||
use Kiri\Exception\NotFindClassException;
|
||||
use Kiri\Kiri;
|
||||
|
||||
/**
|
||||
* Class Filter
|
||||
* @package Annotation\Route
|
||||
*/
|
||||
#[\Attribute(\Attribute::TARGET_METHOD)] class Filter extends Attribute
|
||||
{
|
||||
|
||||
/**
|
||||
* Filter constructor.
|
||||
* @param array $rules
|
||||
*/
|
||||
public function __construct(public array $rules)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param mixed $class
|
||||
* @param mixed|null $method
|
||||
* @return bool
|
||||
*/
|
||||
public function execute(mixed $class, mixed $method = null): bool
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
<?php
|
||||
|
||||
|
||||
namespace Annotation\Route;
|
||||
|
||||
|
||||
use Annotation\Attribute;
|
||||
use Http\Route\MiddlewareManager;
|
||||
use ReflectionException;
|
||||
use Kiri\Kiri;
|
||||
use Http\IInterface\MiddlewareInterface ;
|
||||
|
||||
/**
|
||||
* Class Middleware
|
||||
* @package Annotation\Route
|
||||
*/
|
||||
#[\Attribute(\Attribute::TARGET_METHOD)] class Middleware extends Attribute
|
||||
{
|
||||
|
||||
|
||||
/**
|
||||
* Interceptor constructor.
|
||||
* @param string|array $middleware
|
||||
* @throws
|
||||
*/
|
||||
public function __construct(public string|array $middleware)
|
||||
{
|
||||
if (is_string($this->middleware)) {
|
||||
$this->middleware = [$this->middleware];
|
||||
}
|
||||
|
||||
$array = [];
|
||||
foreach ($this->middleware as $value) {
|
||||
$sn = di($value);
|
||||
if (!($sn instanceof MiddlewareInterface)) {
|
||||
continue;
|
||||
}
|
||||
$array[] = [$sn, 'onHandler'];
|
||||
}
|
||||
$this->middleware = $array;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param mixed $class
|
||||
* @param mixed|null $method
|
||||
* @return $this
|
||||
* @throws ReflectionException
|
||||
*/
|
||||
public function execute(mixed $class, mixed $method = null): static
|
||||
{
|
||||
$middleware = Kiri::getDi()->get(MiddlewareManager::class);
|
||||
$middleware->addMiddlewares($class, $method, $this->middleware);
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
<?php
|
||||
|
||||
|
||||
namespace Annotation\Route;
|
||||
|
||||
|
||||
use Annotation\Attribute;
|
||||
use Exception;
|
||||
use Http\Route\Router;
|
||||
use Kiri\Kiri;
|
||||
|
||||
#[\Attribute(\Attribute::TARGET_METHOD)] class Route extends Attribute
|
||||
{
|
||||
|
||||
/**
|
||||
* Route constructor.
|
||||
* @param string $uri
|
||||
* @param string $method
|
||||
* @param string $version
|
||||
*/
|
||||
public function __construct(
|
||||
public string $uri,
|
||||
public string $method,
|
||||
public string $version = 'v.1.0'
|
||||
)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param mixed $class
|
||||
* @param mixed|null $method
|
||||
* @return Router
|
||||
* @throws Exception
|
||||
*/
|
||||
public function execute(mixed $class, mixed $method = null): Router
|
||||
{
|
||||
// TODO: Implement setHandler() method.
|
||||
$router = Kiri::app()->getRouter();
|
||||
|
||||
if (is_string($class)) {
|
||||
$class = di($class);
|
||||
}
|
||||
$router->addRoute($this->uri, [$class, $method], $this->method);
|
||||
return $router;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
<?php
|
||||
|
||||
|
||||
namespace Annotation\Route;
|
||||
|
||||
|
||||
use Annotation\Attribute;
|
||||
use Exception;
|
||||
use Http\Route\Router;
|
||||
use Kiri\Kiri;
|
||||
|
||||
/**
|
||||
* Class Socket
|
||||
* @package Annotation
|
||||
*/
|
||||
#[\Attribute(\Attribute::TARGET_METHOD)] class Socket extends Attribute
|
||||
{
|
||||
|
||||
const CLOSE = 'CLOSE';
|
||||
const MESSAGE = 'MESSAGE';
|
||||
const HANDSHAKE = 'HANDSHAKE';
|
||||
|
||||
/**
|
||||
* Socket constructor.
|
||||
* @param string $event
|
||||
* @param string|null $uri
|
||||
* @param string $version
|
||||
*/
|
||||
public function __construct(public string $event, public ?string $uri = null, public string $version = 'v.1.0')
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param mixed $class
|
||||
* @param mixed|null $method
|
||||
* @return Router
|
||||
* @throws Exception
|
||||
*/
|
||||
public function execute(mixed $class, mixed $method = null): Router
|
||||
{
|
||||
// TODO: Implement setHandler() method.
|
||||
$router = Kiri::app()->getRouter();
|
||||
|
||||
$path = $this->event . '::' . (is_null($this->uri) ? 'event' : $this->uri);
|
||||
|
||||
$router->addRoute($path, [di($class), $method], 'sw::socket');
|
||||
|
||||
return $router;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user