变更
This commit is contained in:
@@ -0,0 +1,45 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Kiri\Router\Annotate;
|
||||
|
||||
use Kiri\Router\Base\Middleware as MiddlewareManager;
|
||||
use Kiri\Router\Interface\ValidatorInterface;
|
||||
use Kiri\Router\Validator\Validator;
|
||||
use Kiri\Router\Validator\ValidatorMiddleware;
|
||||
use ReflectionException;
|
||||
|
||||
abstract class AbstractRequestMethod
|
||||
{
|
||||
|
||||
|
||||
/**
|
||||
* @param string $path
|
||||
*/
|
||||
public function __construct(readonly public string $path)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @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) {
|
||||
/** @var Middleware $instance */
|
||||
$instance = $value->newInstance();
|
||||
|
||||
$middlewareManager->set($class::class, $method, $instance->middleware);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Kiri\Router\Annotate;
|
||||
|
||||
#[\Attribute(\Attribute::TARGET_METHOD)]
|
||||
class Aspect
|
||||
{
|
||||
|
||||
|
||||
/**
|
||||
* @param string $aspect
|
||||
*/
|
||||
public function __construct(readonly public string $aspect)
|
||||
{
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Kiri\Router\Annotate;
|
||||
|
||||
|
||||
#[\Attribute(\Attribute::TARGET_CLASS)]
|
||||
class AutoController
|
||||
{
|
||||
|
||||
/**
|
||||
* @throws \ReflectionException
|
||||
*/
|
||||
public function dispatch(object $object): void
|
||||
{
|
||||
$reflection = \Kiri::getDi()->getReflectionClass($object::class);
|
||||
foreach ($reflection->getMethods() as $method) {
|
||||
$attributes = $method->getAttributes();
|
||||
foreach ($attributes as $attribute) {
|
||||
$attribute->newInstance()->dispatch($object, $method->getName());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Kiri\Router\Annotate;
|
||||
|
||||
use Exception;
|
||||
use Kiri\Router\Constrict\RequestMethod;
|
||||
use Kiri\Router\AnnotateRouteInterface;
|
||||
use Kiri\Router\Router;
|
||||
use ReflectionException;
|
||||
|
||||
#[\Attribute(\Attribute::TARGET_METHOD | \Attribute::IS_REPEATABLE)]
|
||||
class Delete extends AbstractRequestMethod implements InjectRouteInterface
|
||||
{
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @param object $class
|
||||
* @param string $method
|
||||
* @return void
|
||||
* @throws ReflectionException
|
||||
* @throws Exception
|
||||
*/
|
||||
public function dispatch(object $class, string $method): void
|
||||
{
|
||||
// TODO: Implement dispatch() method.
|
||||
Router::addRoute(RequestMethod::REQUEST_DELETE, $this->path, [$class, $method]);
|
||||
|
||||
$this->registerMiddleware($class, $method);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Kiri\Router\Annotate;
|
||||
|
||||
|
||||
#[\Attribute(\Attribute::TARGET_METHOD)]
|
||||
class Filter
|
||||
{
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Kiri\Router\Annotate;
|
||||
|
||||
use Exception;
|
||||
use Kiri\Router\Constrict\RequestMethod;
|
||||
use Kiri\Router\AnnotateRouteInterface;
|
||||
use Kiri\Router\Router;
|
||||
use ReflectionException;
|
||||
|
||||
#[\Attribute(\Attribute::TARGET_METHOD | \Attribute::IS_REPEATABLE)]
|
||||
class Get extends AbstractRequestMethod implements InjectRouteInterface
|
||||
{
|
||||
|
||||
|
||||
/**
|
||||
* @param object $class
|
||||
* @param string $method
|
||||
* @return void
|
||||
* @throws ReflectionException
|
||||
* @throws Exception
|
||||
* @throws ReflectionException
|
||||
*/
|
||||
public function dispatch(object $class, string $method): void
|
||||
{
|
||||
// TODO: Implement dispatch() method.
|
||||
Router::addRoute(RequestMethod::REQUEST_GET, $this->path, [$class, $method]);
|
||||
|
||||
$this->registerMiddleware($class, $method);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Kiri\Router\Annotate;
|
||||
|
||||
use Exception;
|
||||
use Kiri\Router\Constrict\RequestMethod;
|
||||
use Kiri\Router\AnnotateRouteInterface;
|
||||
use Kiri\Router\Router;
|
||||
use ReflectionException;
|
||||
|
||||
#[\Attribute(\Attribute::TARGET_METHOD | \Attribute::IS_REPEATABLE)]
|
||||
class Head extends AbstractRequestMethod implements InjectRouteInterface
|
||||
{
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @param object $class
|
||||
* @param string $method
|
||||
* @return void
|
||||
* @throws ReflectionException
|
||||
* @throws Exception
|
||||
*/
|
||||
public function dispatch(object $class, string $method): void
|
||||
{
|
||||
// TODO: Implement dispatch() method.
|
||||
Router::addRoute(RequestMethod::REQUEST_HEAD, $this->path, [$class, $method]);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Kiri\Router\Annotate;
|
||||
|
||||
|
||||
#[\Attribute(\Attribute::TARGET_METHOD)]
|
||||
class Interceptor
|
||||
{
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Kiri\Router\Annotate;
|
||||
|
||||
use Kiri\Di\Interface\InjectPropertyInterface;
|
||||
|
||||
#[\Attribute(\Attribute::TARGET_METHOD | \Attribute::IS_REPEATABLE)]
|
||||
class Middleware implements InjectPropertyInterface
|
||||
{
|
||||
|
||||
/**
|
||||
* @param string $middleware
|
||||
*/
|
||||
public function __construct(readonly public string $middleware)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param object $class
|
||||
* @param string $property
|
||||
* @return void
|
||||
*/
|
||||
public function dispatch(object $class, string $property): void
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Kiri\Router\Annotate;
|
||||
|
||||
use Exception;
|
||||
use Kiri\Router\Constrict\RequestMethod;
|
||||
use Kiri\Router\AnnotateRouteInterface;
|
||||
use Kiri\Router\Router;
|
||||
use ReflectionException;
|
||||
|
||||
#[\Attribute(\Attribute::TARGET_METHOD | \Attribute::IS_REPEATABLE)]
|
||||
class Options extends AbstractRequestMethod implements InjectRouteInterface
|
||||
{
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @param object $class
|
||||
* @param string $method
|
||||
* @return void
|
||||
* @throws ReflectionException
|
||||
* @throws Exception
|
||||
*/
|
||||
public function dispatch(object $class, string $method): void
|
||||
{
|
||||
// TODO: Implement dispatch() method.
|
||||
Router::addRoute(RequestMethod::REQUEST_OPTIONS, $this->path, [$class, $method]);
|
||||
|
||||
$this->registerMiddleware($class, $method);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Kiri\Router\Annotate;
|
||||
|
||||
use Exception;
|
||||
use Kiri\Router\AnnotateRouteInterface;
|
||||
use Kiri\Router\Router;
|
||||
use ReflectionException;
|
||||
|
||||
#[\Attribute(\Attribute::TARGET_METHOD)]
|
||||
class Other extends AbstractRequestMethod implements InjectRouteInterface
|
||||
{
|
||||
|
||||
|
||||
/**
|
||||
* @param string $method
|
||||
* @param string $path
|
||||
* @param string $formValidate
|
||||
*/
|
||||
public function __construct(readonly public string $method, string $path, string $formValidate = '')
|
||||
{
|
||||
parent::__construct($path, $formValidate);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param object $class
|
||||
* @param string $method
|
||||
* @return void
|
||||
* @throws ReflectionException
|
||||
* @throws Exception
|
||||
*/
|
||||
public function dispatch(object $class, string $method): void
|
||||
{
|
||||
// TODO: Implement dispatch() method.
|
||||
Router::addRoute([$this->method], $this->path, [$class, $method]);
|
||||
|
||||
$this->registerMiddleware($class, $method);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Kiri\Router\Annotate;
|
||||
|
||||
use Exception;
|
||||
use Kiri\Router\Constrict\RequestMethod;
|
||||
use Kiri\Router\AnnotateRouteInterface;
|
||||
use Kiri\Router\Router;
|
||||
use ReflectionException;
|
||||
|
||||
#[\Attribute(\Attribute::TARGET_METHOD | \Attribute::IS_REPEATABLE)]
|
||||
class Post extends AbstractRequestMethod implements InjectRouteInterface
|
||||
{
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @param object $class
|
||||
* @param string $method
|
||||
* @return void
|
||||
* @throws ReflectionException
|
||||
* @throws Exception
|
||||
*/
|
||||
public function dispatch(object $class, string $method): void
|
||||
{
|
||||
// TODO: Implement dispatch() method.
|
||||
Router::addRoute(RequestMethod::REQUEST_POST, $this->path, [$class, $method]);
|
||||
|
||||
$this->registerMiddleware($class, $method);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Kiri\Router\Annotate;
|
||||
|
||||
use Exception;
|
||||
use Kiri\Router\Constrict\RequestMethod;
|
||||
use Kiri\Router\AnnotateRouteInterface;
|
||||
use Kiri\Router\Router;
|
||||
use Kiri\Router\Base\Middleware as MiddlewareManager;
|
||||
use ReflectionException;
|
||||
|
||||
#[\Attribute(\Attribute::TARGET_METHOD | \Attribute::IS_REPEATABLE)]
|
||||
class Put extends AbstractRequestMethod implements InjectRouteInterface
|
||||
{
|
||||
|
||||
|
||||
/**
|
||||
* @param object $class
|
||||
* @param string $method
|
||||
* @return void
|
||||
* @throws ReflectionException
|
||||
* @throws Exception
|
||||
*/
|
||||
public function dispatch(object $class, string $method): void
|
||||
{
|
||||
// TODO: Implement dispatch() method.
|
||||
Router::addRoute(RequestMethod::REQUEST_PUT, $this->path, [$class, $method]);
|
||||
|
||||
$this->registerMiddleware($class, $method);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Kiri\Router\Annotate;
|
||||
|
||||
|
||||
#[\Attribute(\Attribute::TARGET_PARAMETER)]
|
||||
class QueryData
|
||||
{
|
||||
|
||||
/**
|
||||
* @param array $rule
|
||||
*/
|
||||
public function __construct(readonly public array $rule)
|
||||
{
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
<?php
|
||||
|
||||
namespace Kiri\Router\Annotate;
|
||||
|
||||
use Kiri\Router\Constrict\RequestMethod;
|
||||
use Kiri\Router\InjectRouteInterface;
|
||||
use Kiri\Router\Router;
|
||||
|
||||
#[\Attribute(\Attribute::TARGET_METHOD)]
|
||||
class Route extends AbstractRequestMethod implements InjectRouteInterface
|
||||
{
|
||||
|
||||
|
||||
/**
|
||||
* @param string $path
|
||||
* @param RequestMethod $method
|
||||
*/
|
||||
public function __construct(readonly public string $path, readonly public RequestMethod $method)
|
||||
{
|
||||
parent::__construct($this->path);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param object $class
|
||||
* @param string $method
|
||||
* @return void
|
||||
* @throws \ReflectionException
|
||||
*/
|
||||
public function dispatch(object $class, string $method): void
|
||||
{
|
||||
// TODO: Implement dispatch() method.
|
||||
Router::addRoute($this->method, $this->path, [$class, $method]);
|
||||
|
||||
$this->registerMiddleware($class, $method);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user