first commit
This commit is contained in:
@@ -0,0 +1,8 @@
|
||||
<?php
|
||||
|
||||
namespace Kiri\Inject\Route;
|
||||
|
||||
abstract class AbstractRequestMethod
|
||||
{
|
||||
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
<?php
|
||||
|
||||
namespace Kiri\Router\Inject;
|
||||
|
||||
class Aspect
|
||||
{
|
||||
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
<?php
|
||||
|
||||
namespace Kiri\Inject\Route;
|
||||
|
||||
|
||||
use Psr\Http\Message\RequestInterface;
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
use ReflectionException;
|
||||
|
||||
#[\Attribute(\Attribute::TARGET_CLASS)]
|
||||
class Controller
|
||||
{
|
||||
|
||||
|
||||
readonly public ?RequestInterface $request;
|
||||
|
||||
|
||||
|
||||
readonly public ResponseInterface $response;
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
$this->request = \Kiri::getDi()->get(RequestInterface::class);
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param object $class
|
||||
* @return void
|
||||
* @throws ReflectionException
|
||||
*/
|
||||
public function dispatch(object $class): void
|
||||
{
|
||||
// TODO: Implement dispatch() method.
|
||||
$reflectionClass = \Kiri::getDi()->getReflect($class::class);
|
||||
|
||||
$scheduler = \Kiri::getDi()->get(ControllerInterpreter::class);
|
||||
|
||||
foreach ($reflectionClass->getMethods() as $reflectionMethod) {
|
||||
$scheduler->addRouteByObject($class, $reflectionMethod, $reflectionClass);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
namespace Kiri\Inject\Route;
|
||||
|
||||
use Kiri\Annotation\Route\RequestMethod;
|
||||
use Kiri\Message\Handler\Router;
|
||||
|
||||
#[\Attribute(\Attribute::TARGET_METHOD | \Attribute::IS_REPEATABLE)]
|
||||
class Delete extends AbstractRequestMethod implements InjectRouteInterface
|
||||
{
|
||||
|
||||
|
||||
/**
|
||||
* @param string $path
|
||||
* @param array $params
|
||||
*/
|
||||
public function __construct(public string $path, public array $params = [])
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param object $class
|
||||
* @param string $method
|
||||
* @return void
|
||||
*/
|
||||
public function dispatch(object $class, string $method): void
|
||||
{
|
||||
// TODO: Implement dispatch() method.
|
||||
Router::addRoute(RequestMethod::REQUEST_DELETE, $this->path, [$class, $method]);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
<?php
|
||||
|
||||
namespace Kiri\Inject\Route;
|
||||
|
||||
|
||||
#[\Attribute(\Attribute::TARGET_METHOD)]
|
||||
class Filter
|
||||
{
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
namespace Kiri\Inject\Route;
|
||||
|
||||
use Kiri\Annotation\Route\RequestMethod;
|
||||
use Kiri\Message\Handler\Router;
|
||||
|
||||
#[\Attribute(\Attribute::TARGET_METHOD | \Attribute::IS_REPEATABLE)]
|
||||
class Get extends AbstractRequestMethod implements InjectRouteInterface
|
||||
{
|
||||
|
||||
|
||||
/**
|
||||
* @param string $path
|
||||
* @param array $params
|
||||
*/
|
||||
public function __construct(public string $path, public array $params = [])
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param object $class
|
||||
* @param string $method
|
||||
* @return void
|
||||
*/
|
||||
public function dispatch(object $class, string $method): void
|
||||
{
|
||||
// TODO: Implement dispatch() method.
|
||||
Router::addRoute(RequestMethod::REQUEST_GET, $this->path, [$class, $method]);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
namespace Kiri\Inject\Route;
|
||||
|
||||
use Kiri\Annotation\Route\RequestMethod;
|
||||
use Kiri\Message\Handler\Router;
|
||||
|
||||
#[\Attribute(\Attribute::TARGET_METHOD | \Attribute::IS_REPEATABLE)]
|
||||
class Head extends AbstractRequestMethod implements InjectRouteInterface
|
||||
{
|
||||
|
||||
|
||||
/**
|
||||
* @param string $path
|
||||
* @param array $params
|
||||
*/
|
||||
public function __construct(public string $path, public array $params = [])
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param object $class
|
||||
* @param string $method
|
||||
* @return void
|
||||
*/
|
||||
public function dispatch(object $class, string $method): void
|
||||
{
|
||||
// TODO: Implement dispatch() method.
|
||||
Router::addRoute(RequestMethod::REQUEST_HEAD, $this->path, [$class, $method]);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
<?php
|
||||
|
||||
namespace Kiri\Inject\Route;
|
||||
|
||||
|
||||
#[\Attribute(\Attribute::TARGET_METHOD)]
|
||||
class Interceptor
|
||||
{
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
namespace Kiri\Inject\Route;
|
||||
|
||||
use Kiri\Inject\InjectPropertyInterface;
|
||||
use Kiri\Message\Handler\Abstracts\MiddlewareManager;
|
||||
|
||||
#[\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
|
||||
{
|
||||
// TODO: Implement dispatch() method.
|
||||
MiddlewareManager::add($class::class, $property, $this->middleware);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
namespace Kiri\Inject\Route;
|
||||
|
||||
use Kiri\Annotation\Route\RequestMethod;
|
||||
use Kiri\Message\Handler\Router;
|
||||
|
||||
#[\Attribute(\Attribute::TARGET_METHOD | \Attribute::IS_REPEATABLE)]
|
||||
class Options extends AbstractRequestMethod implements InjectRouteInterface
|
||||
{
|
||||
|
||||
|
||||
/**
|
||||
* @param string $path
|
||||
* @param array $params
|
||||
*/
|
||||
public function __construct(public string $path, public array $params = [])
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param object $class
|
||||
* @param string $method
|
||||
* @return void
|
||||
*/
|
||||
public function dispatch(object $class, string $method): void
|
||||
{
|
||||
// TODO: Implement dispatch() method.
|
||||
Router::addRoute(RequestMethod::REQUEST_OPTIONS, $this->path, [$class, $method]);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
<?php
|
||||
|
||||
namespace Kiri\Router\Inject;
|
||||
|
||||
class Other
|
||||
{
|
||||
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
namespace Kiri\Inject\Route;
|
||||
|
||||
use Kiri\Annotation\Route\RequestMethod;
|
||||
use Kiri\Message\Handler\Router;
|
||||
|
||||
#[\Attribute(\Attribute::TARGET_METHOD | \Attribute::IS_REPEATABLE)]
|
||||
class Post extends AbstractRequestMethod implements InjectRouteInterface
|
||||
{
|
||||
|
||||
|
||||
/**
|
||||
* @param string $path
|
||||
* @param array $params
|
||||
*/
|
||||
public function __construct(public string $path, public array $params = [])
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param object $class
|
||||
* @param string $method
|
||||
* @return void
|
||||
*/
|
||||
public function dispatch(object $class, string $method): void
|
||||
{
|
||||
// TODO: Implement dispatch() method.
|
||||
Router::addRoute(RequestMethod::REQUEST_POST, $this->path, [$class, $method]);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
namespace Kiri\Inject\Route;
|
||||
|
||||
use Kiri\Annotation\Route\RequestMethod;
|
||||
use Kiri\Message\Handler\Router;
|
||||
|
||||
#[\Attribute(\Attribute::TARGET_METHOD | \Attribute::IS_REPEATABLE)]
|
||||
class Put extends AbstractRequestMethod implements InjectRouteInterface
|
||||
{
|
||||
|
||||
|
||||
/**
|
||||
* @param string $path
|
||||
* @param array $params
|
||||
*/
|
||||
public function __construct(public string $path, public array $params = [])
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param object $class
|
||||
* @param string $method
|
||||
* @return void
|
||||
*/
|
||||
public function dispatch(object $class, string $method): void
|
||||
{
|
||||
// TODO: Implement dispatch() method.
|
||||
Router::addRoute(RequestMethod::REQUEST_PUT, $this->path, [$class, $method]);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
<?php
|
||||
|
||||
namespace Kiri\Inject\Route;
|
||||
|
||||
|
||||
#[\Attribute(\Attribute::TARGET_PARAMETER)]
|
||||
class QueryData
|
||||
{
|
||||
|
||||
/**
|
||||
* @param array $rule
|
||||
*/
|
||||
public function __construct(readonly public array $rule)
|
||||
{
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user