This commit is contained in:
2023-12-18 21:55:44 +08:00
parent 5ab8cf0812
commit 7c0ab8c639
10 changed files with 93 additions and 64 deletions
+7 -6
View File
@@ -3,11 +3,10 @@ declare(strict_types=1);
namespace Kiri\Router\Annotate;
use Exception;
use Kiri\Router\Constrict\RequestMethod;
use Kiri\Router\Interface\InjectRouteInterface;
use Kiri\Router\OptionsController;
use Kiri\Router\Router;
use ReflectionClass;
use ReflectionException;
#[\Attribute(\Attribute::TARGET_METHOD | \Attribute::IS_REPEATABLE)]
@@ -25,19 +24,21 @@ class Delete extends AbstractRequestMethod implements InjectRouteInterface
/**
* @param object $class
* @param ReflectionClass $class
* @param string $method
* @return void
* @throws
* @throws ReflectionException
*/
public function dispatch(object $class, string $method): void
public function dispatch(ReflectionClass $class, string $method): void
{
$controller = \Kiri::getDi()->makeReflection($class);
// TODO: Implement dispatch() method.
$path = '/' . ltrim($this->path, '/');
if (!empty($this->version)) {
$path = '/' . trim($this->version) . $path;
}
Router::addRoute(RequestMethod::REQUEST_DELETE, $path, [$class, $method]);
Router::addRoute(RequestMethod::REQUEST_DELETE, $path, [$controller, $method]);
}
+12 -9
View File
@@ -8,6 +8,7 @@ use Kiri\Router\Constrict\RequestMethod;
use Kiri\Router\Interface\InjectRouteInterface;
use Kiri\Router\OptionsController;
use Kiri\Router\Router;
use ReflectionClass;
use ReflectionException;
#[\Attribute(\Attribute::TARGET_METHOD | \Attribute::IS_REPEATABLE)]
@@ -24,20 +25,22 @@ class Get extends AbstractRequestMethod implements InjectRouteInterface
}
/**
* @param object $class
* @param string $method
* @return void
* @throws
*/
public function dispatch(object $class, string $method): void
/**
* @param ReflectionClass $class
* @param string $method
* @return void
* @throws ReflectionException
*/
public function dispatch(ReflectionClass $class, string $method): void
{
// TODO: Implement dispatch() method.
$controller = \Kiri::getDi()->makeReflection($class);
// TODO: Implement dispatch() method.
$path = '/' . ltrim($this->path, '/');
if (!empty($this->version)) {
$path = '/' . trim($this->version) . $path;
}
Router::addRoute(RequestMethod::REQUEST_GET, $path, [$class, $method]);
Router::addRoute(RequestMethod::REQUEST_GET, $path, [$controller, $method]);
}
}
+7 -5
View File
@@ -3,10 +3,11 @@ declare(strict_types=1);
namespace Kiri\Router\Annotate;
use Exception;
use Kiri;
use Kiri\Router\Constrict\RequestMethod;
use Kiri\Router\Interface\InjectRouteInterface;
use Kiri\Router\Router;
use ReflectionClass;
use ReflectionException;
#[\Attribute(\Attribute::TARGET_METHOD | \Attribute::IS_REPEATABLE)]
@@ -24,19 +25,20 @@ class Head extends AbstractRequestMethod implements InjectRouteInterface
/**
* @param object $class
* @param ReflectionClass $class
* @param string $method
* @return void
* @throws
* @throws ReflectionException
*/
public function dispatch(object $class, string $method): void
public function dispatch(ReflectionClass $class, string $method): void
{
$controller = Kiri::getDi()->makeReflection($class);
// TODO: Implement dispatch() method.
$path = '/' . ltrim($this->path, '/');
if (!empty($this->version)) {
$path = '/' . trim($this->version) . $path;
}
Router::addRoute(RequestMethod::REQUEST_HEAD, $path, [$class, $method]);
Router::addRoute(RequestMethod::REQUEST_HEAD, $path, [$controller, $method]);
}
+18 -4
View File
@@ -4,12 +4,26 @@ declare(strict_types=1);
namespace Kiri\Router\Annotate;
use Kiri\Router\Interface\InjectRouteInterface;
use ReflectionClass;
#[\Attribute(\Attribute::TARGET_METHOD)]
class Interceptor
class Interceptor implements InjectRouteInterface
{
public function __construct()
{
}
public function __construct()
{
}
/**
* @param ReflectionClass $class
* @param string $method
* @return void
*/
public function dispatch(ReflectionClass $class, string $method): void
{
// TODO: Implement dispatch() method.
}
}
+11 -11
View File
@@ -3,11 +3,12 @@ declare(strict_types=1);
namespace Kiri\Router\Annotate;
use Kiri\Di\Interface\InjectPropertyInterface;
use Kiri\Router\Base\Middleware as MiddlewareManager;
use Kiri\Router\Interface\InjectRouteInterface;
use ReflectionClass;
#[\Attribute(\Attribute::TARGET_METHOD | \Attribute::IS_REPEATABLE)]
class Middleware implements InjectPropertyInterface
class Middleware implements InjectRouteInterface
{
/**
@@ -18,17 +19,16 @@ class Middleware implements InjectPropertyInterface
}
/**
* @param object $class
* @param string $property
* @return void
* @throws
*/
public function dispatch(object $class, string $property): void
{
/**
* @param ReflectionClass $class
* @param string $method
* @return void
*/
public function dispatch(ReflectionClass $class, string $method): void
{
$middlewareManager = \Kiri::getDi()->get(MiddlewareManager::class);
$middlewareManager->set($class::class, $property, $this->middleware);
$middlewareManager->set($class->getName(), $method, $this->middleware);
}
+7 -5
View File
@@ -3,11 +3,11 @@ declare(strict_types=1);
namespace Kiri\Router\Annotate;
use Exception;
use Kiri;
use Kiri\Router\Constrict\RequestMethod;
use Kiri\Router\Interface\InjectRouteInterface;
use Kiri\Router\Router;
use ReflectionException;
use ReflectionClass;
#[\Attribute(\Attribute::TARGET_METHOD | \Attribute::IS_REPEATABLE)]
class Options extends AbstractRequestMethod implements InjectRouteInterface
@@ -29,14 +29,16 @@ class Options extends AbstractRequestMethod implements InjectRouteInterface
* @return void
* @throws
*/
public function dispatch(object $class, string $method): void
{
public function dispatch(ReflectionClass $class, string $method): void
{
$controller = Kiri::getDi()->makeReflection($class);
// TODO: Implement dispatch() method.
$path = '/' . ltrim($this->path, '/');
if (!empty($this->version)) {
$path = '/' . trim($this->version) . $path;
}
Router::addRoute(RequestMethod::REQUEST_OPTIONS, $path, [$class, $method]);
Router::addRoute(RequestMethod::REQUEST_OPTIONS, $path, [$controller, $method]);
}
+12 -10
View File
@@ -3,11 +3,11 @@ declare(strict_types=1);
namespace Kiri\Router\Annotate;
use Exception;
use Kiri;
use Kiri\Router\Constrict\RequestMethod;
use Kiri\Router\Interface\InjectRouteInterface;
use Kiri\Router\OptionsController;
use Kiri\Router\Router;
use ReflectionClass;
use ReflectionException;
#[\Attribute(\Attribute::TARGET_METHOD | \Attribute::IS_REPEATABLE)]
@@ -24,20 +24,22 @@ class Post extends AbstractRequestMethod implements InjectRouteInterface
}
/**
* @param object $class
* @param string $method
* @return void
* @throws
*/
public function dispatch(object $class, string $method): void
/**
* @param ReflectionClass $class
* @param string $method
* @return void
* @throws ReflectionException
*/
public function dispatch(ReflectionClass $class, string $method): void
{
// TODO: Implement dispatch() method.
$controller = Kiri::getDi()->makeReflection($class);
$path = '/' . ltrim($this->path, '/');
if (!empty($this->version)) {
$path = '/' . trim($this->version) . $path;
}
Router::addRoute(RequestMethod::REQUEST_POST, $path, [$class, $method]);
Router::addRoute(RequestMethod::REQUEST_POST, $path, [$controller, $method]);
}
+5 -5
View File
@@ -3,12 +3,11 @@ declare(strict_types=1);
namespace Kiri\Router\Annotate;
use Exception;
use Kiri;
use Kiri\Router\Constrict\RequestMethod;
use Kiri\Router\Interface\InjectRouteInterface;
use Kiri\Router\OptionsController;
use Kiri\Router\Router;
use ReflectionException;
use ReflectionClass;
#[\Attribute(\Attribute::TARGET_METHOD | \Attribute::IS_REPEATABLE)]
class Put extends AbstractRequestMethod implements InjectRouteInterface
@@ -30,14 +29,15 @@ class Put extends AbstractRequestMethod implements InjectRouteInterface
* @return void
* @throws
*/
public function dispatch(object $class, string $method): void
public function dispatch(ReflectionClass $class, string $method): void
{
$controller = Kiri::getDi()->makeReflection($class);
// TODO: Implement dispatch() method.
$path = '/' . ltrim($this->path, '/');
if (!empty($this->version)) {
$path = '/' . trim($this->version) . $path;
}
Router::addRoute(RequestMethod::REQUEST_PUT, $path, [$class, $method]);
Router::addRoute(RequestMethod::REQUEST_PUT, $path, [$controller, $method]);
}
}
+6 -3
View File
@@ -5,6 +5,7 @@ namespace Kiri\Router\Annotate;
use Kiri\Router\Constrict\RequestMethod;
use Kiri\Router\Interface\InjectRouteInterface;
use Kiri\Router\Router;
use ReflectionClass;
use ReflectionException;
#[\Attribute(\Attribute::TARGET_METHOD | \Attribute::IS_REPEATABLE)]
@@ -23,17 +24,19 @@ class Route extends AbstractRequestMethod implements InjectRouteInterface
/**
* @param object $class
* @param ReflectionClass $class
* @param string $method
* @return void
* @throws ReflectionException
*/
public function dispatch(object $class, string $method): void
public function dispatch(ReflectionClass $class, string $method): void
{
$controller = \Kiri::getDi()->makeReflection($class);
// TODO: Implement dispatch() method.
$path = '/' . ltrim($this->path, '/');
if (!empty($this->version)) {
$path = '/' . trim($this->version) . $path;
}
Router::addRoute([$this->method], $path, [$class, $method]);
Router::addRoute([$this->method], $path, [$controller, $method]);
}
}
+8 -6
View File
@@ -3,15 +3,17 @@ declare(strict_types=1);
namespace Kiri\Router\Interface;
use ReflectionClass;
interface InjectRouteInterface
{
/**
* @param object $class
* @param string $method
* @return void
*/
public function dispatch(object $class, string $method): void;
/**
* @param ReflectionClass $class
* @param string $method
* @return void
*/
public function dispatch(ReflectionClass $class, string $method): void;
}