Files
kiri-core/kiri-annotation/Route/Route.php
T

42 lines
875 B
PHP
Raw Normal View History

2020-12-14 19:03:05 +08:00
<?php
2022-01-08 18:49:08 +08:00
namespace Kiri\Annotation\Route;
2020-12-14 19:03:05 +08:00
2022-01-08 18:49:08 +08:00
use Kiri\Annotation\Attribute;
2021-09-18 11:28:56 +08:00
use Http\Handler\Router;
use Kiri\Kiri;
2020-12-14 19:03:05 +08:00
2021-09-16 14:40:25 +08:00
#[\Attribute(\Attribute::TARGET_METHOD | \Attribute::IS_REPEATABLE)] class Route extends Attribute
2020-12-14 19:03:05 +08:00
{
2021-09-16 14:40:25 +08:00
/**
* Route constructor.
* @param string $uri
* @param string $method
* @param string $version
*/
public function __construct(public string $uri, public string $method, public string $version = 'v.1.0')
{
2021-09-18 10:38:38 +08:00
$this->uri = '/' . ltrim($this->uri, '/');
$this->method = strtoupper($this->method);
2021-09-16 14:40:25 +08:00
}
2021-08-29 04:06:49 +08:00
2021-09-07 11:44:12 +08:00
/**
* @param mixed $class
* @param mixed|null $method
2021-09-18 10:40:57 +08:00
* @return bool
2021-09-18 10:38:38 +08:00
* @throws \ReflectionException
2021-09-07 11:44:12 +08:00
*/
2021-09-18 10:40:57 +08:00
public function execute(mixed $class, mixed $method = null): bool
2021-09-16 14:40:25 +08:00
{
2021-09-18 11:28:56 +08:00
$di = Kiri::getDi()->get(Router::class);
2021-09-18 17:07:52 +08:00
$di->addRoute($this->method, $this->uri, $class . '@' . $method);
2021-09-18 10:38:38 +08:00
return parent::execute($class, $method);
2021-09-16 14:40:25 +08:00
}
2020-12-14 19:03:05 +08:00
}