111
This commit is contained in:
+4
-129
@@ -19,122 +19,9 @@ class Annotation extends Component
|
||||
|
||||
private Loader $_loader;
|
||||
|
||||
private array $_model_sets = [];
|
||||
private array $_model_gets = [];
|
||||
private array $_model_relate = [];
|
||||
|
||||
|
||||
/**
|
||||
* @param string $class
|
||||
* @param string $setName
|
||||
* @param string $method
|
||||
*/
|
||||
public function addSets(string $class, string $setName, string $method)
|
||||
{
|
||||
$this->_model_sets[$class][$setName] = $method;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $class
|
||||
* @param string $setName
|
||||
* @param string $method
|
||||
*/
|
||||
public function addGets(string $class, string $setName, string $method)
|
||||
{
|
||||
$this->_model_gets[$class][$setName] = $method;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param string $class
|
||||
* @param string $setName
|
||||
* @param string $method
|
||||
*/
|
||||
public function addRelate(string $class, string $setName, string $method)
|
||||
{
|
||||
$this->_model_relate[$class][$setName] = $method;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param $class
|
||||
* @return array
|
||||
*/
|
||||
public function getGets($class): array
|
||||
{
|
||||
return $this->_model_gets[$class] ?? [];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $class
|
||||
* @return array
|
||||
*/
|
||||
public function getSets($class): array
|
||||
{
|
||||
return $this->_model_gets[$class] ?? [];
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param string $class
|
||||
* @param string|null $setName
|
||||
* @return array|string|null
|
||||
*/
|
||||
public function getGetMethodName(string $class, string $setName = null): array|null|string
|
||||
{
|
||||
$gets = $this->_model_gets[$class] ?? null;
|
||||
if ($gets == null) {
|
||||
return null;
|
||||
}
|
||||
if (empty($setName)) return $gets;
|
||||
return $gets[$setName] ?? null;
|
||||
}
|
||||
|
||||
|
||||
public function runGet($name, $value)
|
||||
{
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param string $class
|
||||
* @param string|null $method
|
||||
* @return array|string|null
|
||||
*/
|
||||
public function getRelateMethods(string $class, string $method = null): array|null|string
|
||||
{
|
||||
$gets = $this->_model_relate[$class] ?? null;
|
||||
if ($gets == null) {
|
||||
return null;
|
||||
}
|
||||
if (empty($method)) return $gets;
|
||||
return $gets[$method] ?? null;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param string $class
|
||||
* @param string $setName
|
||||
* @return mixed|null
|
||||
*/
|
||||
public function getSetMethodName(string $class, string $setName): ?string
|
||||
{
|
||||
if (!isset($this->_model_sets[$class])) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$lists = $this->_model_sets[$class];
|
||||
|
||||
if (isset($lists[$setName])) {
|
||||
return $lists[$setName];
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public function init(): void
|
||||
{
|
||||
$this->_loader = new Loader();
|
||||
@@ -159,19 +46,7 @@ class Annotation extends Component
|
||||
return $this->_loader = $loader;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param string $className
|
||||
* @param string $method
|
||||
* @return array 根据类名获取注解
|
||||
* 根据类名获取注解
|
||||
*/
|
||||
public function getMethods(string $className, string $method = ''): mixed
|
||||
{
|
||||
return $this->_loader->getMethod($className, $method);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @param object $class
|
||||
* @throws ReflectionException
|
||||
|
||||
+2
-2
@@ -23,7 +23,7 @@ defined('ASPECT_ERROR') or define('ASPECT_ERROR', 'Aspect annotation must implem
|
||||
* Aspect constructor.
|
||||
* @param string $aspect
|
||||
*/
|
||||
public function __construct(public string $aspect)
|
||||
public function __construct(string $aspect)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -31,7 +31,7 @@ defined('ASPECT_ERROR') or define('ASPECT_ERROR', 'Aspect annotation must implem
|
||||
/**
|
||||
* @throws Exception
|
||||
*/
|
||||
public function execute(mixed $class, mixed $method = ''): bool
|
||||
public static function execute(mixed $params, mixed $class, mixed $method = ''): bool
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -22,7 +22,7 @@ use Kiri\Kiri;
|
||||
* Asynchronous constructor.
|
||||
* @param string $name
|
||||
*/
|
||||
public function __construct(public string $name)
|
||||
public function __construct(string $name)
|
||||
{
|
||||
|
||||
}
|
||||
@@ -34,10 +34,10 @@ use Kiri\Kiri;
|
||||
* @return bool
|
||||
* @throws Exception
|
||||
*/
|
||||
public function execute(mixed $class, mixed $method = null): bool
|
||||
public static function execute(mixed $params, mixed $class, mixed $method = null): bool
|
||||
{
|
||||
$async = Kiri::app()->getAsync();
|
||||
$async->addAsync($this->name, $class);
|
||||
$async->addAsync($params->name, $class);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
+6
-7
@@ -4,7 +4,6 @@
|
||||
namespace Annotation;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Class Attribute
|
||||
* @package Annotation
|
||||
@@ -13,12 +12,12 @@ abstract class Attribute implements IAnnotation
|
||||
{
|
||||
|
||||
|
||||
/**
|
||||
* @param mixed $class
|
||||
* @param mixed|string $method
|
||||
* @return mixed
|
||||
*/
|
||||
public function execute(mixed $class, mixed $method = ''): mixed
|
||||
/**
|
||||
* @param static $class
|
||||
* @param mixed|string $method
|
||||
* @return mixed
|
||||
*/
|
||||
public static function execute(mixed $params, mixed $class, mixed $method = ''): mixed
|
||||
{
|
||||
// TODO: Implement execute() method.
|
||||
return true;
|
||||
|
||||
+3
-3
@@ -21,7 +21,7 @@ use Kiri\Events\EventProvider;
|
||||
* @param string $name
|
||||
* @param array $params
|
||||
*/
|
||||
public function __construct(public string $name, public array $params = [])
|
||||
public function __construct(string $name, array $params = [])
|
||||
{
|
||||
}
|
||||
|
||||
@@ -32,13 +32,13 @@ use Kiri\Events\EventProvider;
|
||||
* @return bool
|
||||
* @throws Exception
|
||||
*/
|
||||
public function execute(mixed $class, mixed $method = null): bool
|
||||
public static function execute(mixed $params, mixed $class, mixed $method = null): bool
|
||||
{
|
||||
$pro = di(EventProvider::class);
|
||||
if (is_string($class)) {
|
||||
$class = di($class);
|
||||
}
|
||||
$pro->on($this->name, [$class, $method]);
|
||||
$pro->on($params->name, [$class, $method]);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -9,12 +9,13 @@ use Closure;
|
||||
interface IAnnotation
|
||||
{
|
||||
|
||||
/**
|
||||
* @param mixed $class
|
||||
* @param mixed $method
|
||||
* @return mixed
|
||||
*/
|
||||
public function execute(mixed $class, mixed $method = ''): mixed;
|
||||
/**
|
||||
* @param static $params
|
||||
* @param mixed $class
|
||||
* @param mixed $method
|
||||
* @return mixed
|
||||
*/
|
||||
public static function execute(mixed $params, mixed $class, mixed $method = ''): mixed;
|
||||
|
||||
|
||||
}
|
||||
|
||||
+13
-13
@@ -23,7 +23,7 @@ use ReflectionProperty;
|
||||
* @param string $value
|
||||
* @param array $construct
|
||||
*/
|
||||
public function __construct(private string $value, private array $construct = [])
|
||||
public function __construct(string $value, array $construct = [])
|
||||
{
|
||||
}
|
||||
|
||||
@@ -35,15 +35,15 @@ use ReflectionProperty;
|
||||
* @throws ReflectionException
|
||||
* @throws Exception
|
||||
*/
|
||||
public function execute(mixed $class, mixed $method = null): bool
|
||||
public static function execute(mixed $params, mixed $class, mixed $method = null): bool
|
||||
{
|
||||
if (!($method = $this->getProperty($class, $method))) {
|
||||
if (!($method = static::getProperty($class, $method))) {
|
||||
return false;
|
||||
}
|
||||
/** @var ReflectionProperty $class */
|
||||
$injectValue = $this->parseInjectValue();
|
||||
$injectValue = static::parseInjectValue($params);
|
||||
if ($method->isPrivate() || $method->isProtected()) {
|
||||
$this->setter($class, $method, $injectValue);
|
||||
static::setter($class, $method, $injectValue);
|
||||
} else {
|
||||
$class->{$method->getName()} = $injectValue;
|
||||
}
|
||||
@@ -56,7 +56,7 @@ use ReflectionProperty;
|
||||
* @param $method
|
||||
* @param $injectValue
|
||||
*/
|
||||
private function setter($class, $method, $injectValue)
|
||||
private static function setter($class, $method, $injectValue)
|
||||
{
|
||||
$method = 'set' . ucfirst(Str::convertUnderline($method->getName()));
|
||||
if (!method_exists($class, $method)) {
|
||||
@@ -72,7 +72,7 @@ use ReflectionProperty;
|
||||
* @return ReflectionProperty|bool
|
||||
* @throws ReflectionException
|
||||
*/
|
||||
private function getProperty($class, $method): ReflectionProperty|bool
|
||||
private static function getProperty($class, $method): ReflectionProperty|bool
|
||||
{
|
||||
if ($method instanceof ReflectionProperty && !$method->isStatic()) {
|
||||
return $method;
|
||||
@@ -90,15 +90,15 @@ use ReflectionProperty;
|
||||
* @return mixed
|
||||
* @throws Exception
|
||||
*/
|
||||
private function parseInjectValue(): mixed
|
||||
private static function parseInjectValue($params): mixed
|
||||
{
|
||||
if (!Kiri::app()->has($this->value)) {
|
||||
if (!empty($this->construct)) {
|
||||
return Kiri::getDi()->newObject($this->value, $this->construct);
|
||||
if (!Kiri::app()->has($params->value)) {
|
||||
if (!empty($params->construct)) {
|
||||
return Kiri::getDi()->newObject($params->value, $params->construct);
|
||||
}
|
||||
return Kiri::getDi()->get($this->value);
|
||||
return Kiri::getDi()->get($params->value);
|
||||
} else {
|
||||
return Kiri::app()->get($this->value);
|
||||
return Kiri::app()->get($params->value);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+12
-13
@@ -24,15 +24,8 @@ use Server\Events\OnWorkerExit;
|
||||
* @param bool $async_reload
|
||||
* @throws Exception
|
||||
*/
|
||||
public function __construct(public string $service, public ?array $args = [], public bool $async_reload = true)
|
||||
public function __construct(string $service, ?array $args = [], bool $async_reload = true)
|
||||
{
|
||||
if ($this->async_reload !== true) {
|
||||
return;
|
||||
}
|
||||
$pro = di(EventProvider::class);
|
||||
$pro->on(OnWorkerExit::class, function () {
|
||||
di(\Kiri\Di\LocalService::class)->remove($this->service);
|
||||
},0);
|
||||
}
|
||||
|
||||
|
||||
@@ -42,14 +35,20 @@ use Server\Events\OnWorkerExit;
|
||||
* @return bool
|
||||
* @throws Exception
|
||||
*/
|
||||
public function execute(mixed $class, mixed $method = null): bool
|
||||
public static function execute(mixed $params, mixed $class, mixed $method = null): bool
|
||||
{
|
||||
$class = ['class' => $class];
|
||||
if (!empty($this->args)) {
|
||||
$class = array_merge($class, $this->args);
|
||||
if (!empty($params->args)) {
|
||||
$class = array_merge($class, $params->args);
|
||||
}
|
||||
Kiri::set($this->service, $class);
|
||||
return true; // TODO: Change the autogenerated stub
|
||||
if ($params->async_reload !== true) {
|
||||
$pro = di(EventProvider::class);
|
||||
$pro->on(OnWorkerExit::class, function () use ($params) {
|
||||
di(\Kiri\Di\LocalService::class)->remove($params->service);
|
||||
},0);
|
||||
}
|
||||
Kiri::set($params->service, $class);
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -26,10 +26,7 @@ use Annotation\Attribute;
|
||||
];
|
||||
|
||||
|
||||
public function __construct(
|
||||
public array $request,
|
||||
public array $response
|
||||
)
|
||||
public function __construct(array $request, array $response)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -39,10 +36,10 @@ use Annotation\Attribute;
|
||||
* @param mixed|null $method
|
||||
* @return array
|
||||
*/
|
||||
public function execute(mixed $class, mixed $method = null): array
|
||||
public static function execute(mixed $params, mixed $class, mixed $method = null): array
|
||||
{
|
||||
// TODO: Implement execute() method.
|
||||
return [$this->request, $this->response];
|
||||
return [$params->request, $params->response];
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -23,7 +23,7 @@ use Kiri\Kiri;
|
||||
* Filter constructor.
|
||||
* @param array $rules
|
||||
*/
|
||||
public function __construct(public array $rules)
|
||||
public function __construct(array $rules)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -33,7 +33,7 @@ use Kiri\Kiri;
|
||||
* @param mixed|null $method
|
||||
* @return bool
|
||||
*/
|
||||
public function execute(mixed $class, mixed $method = null): bool
|
||||
public static function execute(mixed $params, mixed $class, mixed $method = null): bool
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
+18
-19
@@ -7,7 +7,7 @@ namespace Annotation\Route;
|
||||
use Annotation\Attribute;
|
||||
use Http\Route\MiddlewareManager;
|
||||
use ReflectionException;
|
||||
use Http\IInterface\MiddlewareInterface ;
|
||||
use Http\IInterface\MiddlewareInterface;
|
||||
|
||||
/**
|
||||
* Class Middleware
|
||||
@@ -22,34 +22,33 @@ use Http\IInterface\MiddlewareInterface ;
|
||||
* @param string|array $middleware
|
||||
* @throws
|
||||
*/
|
||||
public function __construct(public string|array $middleware)
|
||||
public function __construct(string|array $middleware)
|
||||
{
|
||||
if (is_string($this->middleware)) {
|
||||
$this->middleware = [$this->middleware];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param mixed $class
|
||||
* @param mixed|null $method
|
||||
* @return $this
|
||||
* @throws ReflectionException
|
||||
*/
|
||||
public static function execute(mixed $params, mixed $class, mixed $method = null): mixed
|
||||
{
|
||||
if (is_string($params->middleware)) {
|
||||
$params->middleware = [$params->middleware];
|
||||
}
|
||||
$array = [];
|
||||
foreach ($this->middleware as $value) {
|
||||
foreach ($params->middleware as $value) {
|
||||
$sn = di($value);
|
||||
if (!($sn instanceof MiddlewareInterface)) {
|
||||
continue;
|
||||
}
|
||||
$array[] = [$sn, 'onHandler'];
|
||||
}
|
||||
$this->middleware = $array;
|
||||
}
|
||||
MiddlewareManager::addMiddlewares($class, $method, $array);
|
||||
|
||||
|
||||
/**
|
||||
* @param mixed $class
|
||||
* @param mixed|null $method
|
||||
* @return $this
|
||||
* @throws ReflectionException
|
||||
*/
|
||||
public function execute(mixed $class, mixed $method = null): static
|
||||
{
|
||||
MiddlewareManager::addMiddlewares($class, $method, $this->middleware);
|
||||
return $this;
|
||||
return parent::execute($params, $class, $method);
|
||||
}
|
||||
|
||||
|
||||
|
||||
+25
-31
@@ -12,39 +12,33 @@ 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'
|
||||
)
|
||||
{
|
||||
$this->method = strtoupper($this->method);
|
||||
}
|
||||
/**
|
||||
* Route constructor.
|
||||
* @param string $uri
|
||||
* @param string $method
|
||||
* @param string $version
|
||||
*/
|
||||
public function __construct(string $uri, string $method, 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;
|
||||
}
|
||||
/**
|
||||
* @param mixed $class
|
||||
* @param mixed|null $method
|
||||
* @return Router
|
||||
* @throws Exception
|
||||
*/
|
||||
public static function execute(mixed $params, mixed $class, mixed $method = null): Router
|
||||
{
|
||||
// TODO: Implement setHandler() method.
|
||||
$router = Kiri::app()->getRouter();
|
||||
if (is_string($class)) {
|
||||
$class = di($class);
|
||||
}
|
||||
$router->addRoute($params->uri, [$class, $method], strtoupper($params->method));
|
||||
return $router;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -26,7 +26,7 @@ use Kiri\Kiri;
|
||||
* @param string|null $uri
|
||||
* @param string $version
|
||||
*/
|
||||
public function __construct(public string $event, public ?string $uri = null, public string $version = 'v.1.0')
|
||||
public function __construct(string $event, ?string $uri = null, string $version = 'v.1.0')
|
||||
{
|
||||
}
|
||||
|
||||
@@ -37,12 +37,12 @@ use Kiri\Kiri;
|
||||
* @return Router
|
||||
* @throws Exception
|
||||
*/
|
||||
public function execute(mixed $class, mixed $method = null): Router
|
||||
public static function execute(mixed $params, mixed $class, mixed $method = null): Router
|
||||
{
|
||||
// TODO: Implement setHandler() method.
|
||||
$router = Kiri::app()->getRouter();
|
||||
|
||||
$path = $this->event . '::' . (is_null($this->uri) ? 'event' : $this->uri);
|
||||
$path = $params->event . '::' . (is_null($params->uri) ? 'event' : $params->uri);
|
||||
|
||||
$router->addRoute($path, [di($class), $method], 'sw::socket');
|
||||
|
||||
|
||||
+1
-1
@@ -21,7 +21,7 @@ namespace Annotation;
|
||||
/**
|
||||
* @param string $only
|
||||
*/
|
||||
public function __construct(public string $only = Target::ALL)
|
||||
public function __construct(string $only = Target::ALL)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user