Files
kiri-core/Annotation/Route/Route.php
T
2021-03-03 18:35:04 +08:00

53 lines
1001 B
PHP

<?php
namespace Annotation\Route;
use Annotation\Attribute;
use HttpServer\Route\Router;
use ReflectionException;
use Snowflake\Exception\ComponentException;
use Snowflake\Exception\ConfigException;
use Snowflake\Exception\NotFindClassException;
use Snowflake\Snowflake;
#[\Attribute(\Attribute::TARGET_METHOD)] class Route extends Attribute
{
/**
* 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'
)
{
}
/**
* @param array $handler
* @return Router
* @throws ComponentException
* @throws ConfigException
* @throws ReflectionException
* @throws NotFindClassException
*/
public function execute(array $handler): Router
{
// TODO: Implement setHandler() method.
$router = Snowflake::app()->getRouter();
$router->addRoute($this->uri . $this->version, $handler, $this->method);
return $router;
}
}