111
This commit is contained in:
@@ -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');
|
||||
|
||||
|
||||
Reference in New Issue
Block a user