This commit is contained in:
2021-03-23 15:21:12 +08:00
parent d2db326ecf
commit 98681a0dfa
2 changed files with 52 additions and 51 deletions
-51
View File
@@ -1,51 +0,0 @@
<?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;
}
}
+52
View File
@@ -0,0 +1,52 @@
<?php
namespace Annotation\Route;
use Annotation\Attribute;
use Exception;
use HttpServer\Http\Request;
use HttpServer\Route\Router;
use JetBrains\PhpStorm\Pure;
use ReflectionException;
use Snowflake\Exception\ComponentException;
use Snowflake\Exception\ConfigException;
use Snowflake\Exception\NotFindClassException;
use Snowflake\Snowflake;
#[\Attribute(\Attribute::TARGET_METHOD)] class RpcService extends Attribute
{
private string $uri = '';
/**
* Route constructor.
* @param string $cmd
* @param int $port
*/
#[Pure] public function __construct(public string $cmd, public int $port)
{
$this->uri = 'rpc/' . $this->port . '/' . ltrim($this->cmd, '/');
}
/**
* @param array $handler
* @return Router
* @throws ConfigException
* @throws Exception
*/
public function execute(array $handler): Router
{
// TODO: Implement setHandler() method.
$router = Snowflake::app()->getRouter();
$router->addRoute($this->uri, $handler, Request::HTTP_CMD);
return $router;
}
}