This commit is contained in:
2021-09-18 10:38:38 +08:00
parent d0e9f834d4
commit 1f34eb6675
7 changed files with 125 additions and 78 deletions
+7 -8
View File
@@ -5,8 +5,9 @@ namespace Annotation\Route;
use Annotation\Attribute;
use Http\Handler\Abstracts\HandlerManager;
use Http\Handler\Handler;
use Http\Route\Router;
use Kiri\Kiri;
#[\Attribute(\Attribute::TARGET_METHOD | \Attribute::IS_REPEATABLE)] class Route extends Attribute
{
@@ -19,6 +20,8 @@ use Kiri\Kiri;
*/
public function __construct(public string $uri, public string $method, public string $version = 'v.1.0')
{
$this->uri = '/' . ltrim($this->uri, '/');
$this->method = strtoupper($this->method);
}
@@ -26,16 +29,12 @@ use Kiri\Kiri;
* @param mixed $class
* @param mixed|null $method
* @return Router
* @throws \ReflectionException
*/
public function execute(mixed $class, mixed $method = null): Router
{
// TODO: Implement setHandler() method.
$router = Kiri::getDi()->get(Router::class);
if (is_string($class)) {
$class = di($class);
}
$router->addRoute($this->uri, [$class, $method], strtoupper($this->method));
return $router;
HandlerManager::add($this->uri, $this->method, new Handler($this->uri, [$class, $method]));
return parent::execute($class, $method);
}