Revert "改名"
This reverts commit fdf58326
This commit is contained in:
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
|
||||
|
||||
namespace Kiri\Annotation\Route;
|
||||
|
||||
|
||||
use Kiri\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(array $request, array $response)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
<?php
|
||||
|
||||
|
||||
namespace Kiri\Annotation\Route;
|
||||
|
||||
|
||||
use Kiri\Annotation\Attribute;
|
||||
use Http\Handler\Abstracts\MiddlewareManager;
|
||||
use Psr\Http\Server\MiddlewareInterface;
|
||||
|
||||
/**
|
||||
* Class Middleware
|
||||
* @package Annotation\Route
|
||||
*/
|
||||
#[\Attribute(\Attribute::TARGET_METHOD | \Attribute::IS_REPEATABLE)] 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) {
|
||||
if (!in_array(MiddlewareInterface::class, class_implements($value))) {
|
||||
throw new \Exception('The middleware');
|
||||
}
|
||||
$array[] = $value;
|
||||
}
|
||||
$this->middleware = $array;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param mixed $class
|
||||
* @param mixed|null $method
|
||||
* @return $this
|
||||
* @throws \ReflectionException
|
||||
*/
|
||||
public function execute(mixed $class, mixed $method = null): mixed
|
||||
{
|
||||
MiddlewareManager::add($class, $method, $this->middleware);
|
||||
return parent::execute($class, $method);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
<?php
|
||||
|
||||
|
||||
namespace Kiri\Annotation\Route;
|
||||
|
||||
|
||||
use Kiri\Annotation\Attribute;
|
||||
use Http\Handler\Router;
|
||||
use Kiri\Kiri;
|
||||
|
||||
#[\Attribute(\Attribute::TARGET_METHOD | \Attribute::IS_REPEATABLE)] 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')
|
||||
{
|
||||
$this->uri = '/' . ltrim($this->uri, '/');
|
||||
$this->method = strtoupper($this->method);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param mixed $class
|
||||
* @param mixed|null $method
|
||||
* @return bool
|
||||
* @throws \ReflectionException
|
||||
*/
|
||||
public function execute(mixed $class, mixed $method = null): bool
|
||||
{
|
||||
$di = Kiri::getDi()->get(Router::class);
|
||||
$di->addRoute($this->method, $this->uri, $class . '@' . $method);
|
||||
return parent::execute($class, $method);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
|
||||
|
||||
namespace Kiri\Annotation\Route;
|
||||
|
||||
|
||||
use Kiri\Annotation\Attribute;
|
||||
|
||||
/**
|
||||
* 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(string $event, ?string $uri = null, string $version = 'v.1.0')
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user