qqq
This commit is contained in:
@@ -3,35 +3,9 @@ declare(strict_types=1);
|
|||||||
|
|
||||||
namespace Kiri\Router\Annotate;
|
namespace Kiri\Router\Annotate;
|
||||||
|
|
||||||
use Kiri\Router\Base\Middleware as MiddlewareManager;
|
|
||||||
use ReflectionException;
|
|
||||||
|
|
||||||
abstract class AbstractRequestMethod
|
abstract class AbstractRequestMethod
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param object $class
|
|
||||||
* @param string $method
|
|
||||||
* @return void
|
|
||||||
* @throws ReflectionException
|
|
||||||
* @throws \Exception
|
|
||||||
*/
|
|
||||||
public function registerMiddleware(object $class, string $method): void
|
|
||||||
{
|
|
||||||
$reflectionMethod = \Kiri::getDi()->getMethod($class::class, $method);
|
|
||||||
$middleware = $reflectionMethod->getAttributes(Middleware::class);
|
|
||||||
|
|
||||||
$middlewareManager = \Kiri::getDi()->get(MiddlewareManager::class);
|
|
||||||
foreach ($middleware as $value) {
|
|
||||||
if (!class_exists($value->getName())) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
/** @var Middleware $instance */
|
|
||||||
$instance = $value->newInstance();
|
|
||||||
|
|
||||||
$middlewareManager->set($class::class, $method, $instance->middleware);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,12 +4,14 @@ declare(strict_types=1);
|
|||||||
namespace Kiri\Router\Annotate;
|
namespace Kiri\Router\Annotate;
|
||||||
|
|
||||||
|
|
||||||
|
use ReflectionException;
|
||||||
|
|
||||||
#[\Attribute(\Attribute::TARGET_CLASS)]
|
#[\Attribute(\Attribute::TARGET_CLASS)]
|
||||||
class AutoController
|
class AutoController
|
||||||
{
|
{
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @throws \ReflectionException
|
* @throws ReflectionException
|
||||||
*/
|
*/
|
||||||
public function dispatch(object $object): void
|
public function dispatch(object $object): void
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -14,10 +14,10 @@ class Delete extends AbstractRequestMethod implements InjectRouteInterface
|
|||||||
{
|
{
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
/**
|
* @param string $path
|
||||||
* @param string $path
|
* @param string $version
|
||||||
*/
|
*/
|
||||||
public function __construct(readonly public string $path, readonly public string $version = 'v1')
|
public function __construct(readonly public string $path, readonly public string $version = 'v1')
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,11 +14,10 @@ class Head extends AbstractRequestMethod implements InjectRouteInterface
|
|||||||
{
|
{
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param string $path
|
||||||
/**
|
* @param string $version
|
||||||
* @param string $path
|
*/
|
||||||
*/
|
|
||||||
public function __construct(readonly public string $path, readonly public string $version = 'v1')
|
public function __construct(readonly public string $path, readonly public string $version = 'v1')
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,11 +14,10 @@ class Options extends AbstractRequestMethod implements InjectRouteInterface
|
|||||||
{
|
{
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param string $path
|
||||||
/**
|
* @param string $version
|
||||||
* @param string $path
|
*/
|
||||||
*/
|
|
||||||
public function __construct(readonly public string $path, readonly public string $version = 'v1')
|
public function __construct(readonly public string $path, readonly public string $version = 'v1')
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,11 +14,10 @@ class Put extends AbstractRequestMethod implements InjectRouteInterface
|
|||||||
{
|
{
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param string $path
|
||||||
/**
|
* @param string $version
|
||||||
* @param string $path
|
*/
|
||||||
*/
|
|
||||||
public function __construct(readonly public string $path, readonly public string $version = 'v1')
|
public function __construct(readonly public string $path, readonly public string $version = 'v1')
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,10 +12,11 @@ class Route extends AbstractRequestMethod implements InjectRouteInterface
|
|||||||
{
|
{
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param string $path
|
* @param string $path
|
||||||
* @param RequestMethod $method
|
* @param RequestMethod $method
|
||||||
*/
|
* @param string $version
|
||||||
|
*/
|
||||||
public function __construct(readonly public string $path, readonly public RequestMethod $method, readonly public string $version = 'v1')
|
public function __construct(readonly public string $path, readonly public RequestMethod $method, readonly public string $version = 'v1')
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user