This commit is contained in:
as2252258@163.com
2021-03-23 02:41:24 +08:00
parent e8b0f8da81
commit ba5501adae
2 changed files with 52 additions and 0 deletions
+51
View File
@@ -0,0 +1,51 @@
<?php
namespace Annotation\Route;
use Annotation\Attribute;
use HttpServer\Http\Request;
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 Cmd extends Attribute
{
/**
* Route constructor.
* @param string $uri
* @param string $method
* @param string $version
*/
public function __construct(
public string $cmd,
)
{
}
/**
* @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->cmd, $handler, Request::HTTP_CMD);
return $router;
}
}