Files
kiri-core/Annotation/Route/RpcProducer.php
T

55 lines
961 B
PHP
Raw Normal View History

2021-03-23 15:21:12 +08:00
<?php
namespace Annotation\Route;
use Annotation\Attribute;
use Exception;
use HttpServer\Http\Request;
use HttpServer\Route\Router;
use JetBrains\PhpStorm\Pure;
use Snowflake\Exception\ConfigException;
use Snowflake\Snowflake;
2021-03-30 11:25:44 +08:00
/**
* Class RpcProducer
* @package Annotation\Route
*/
2021-03-24 11:26:46 +08:00
#[\Attribute(\Attribute::TARGET_METHOD)] class RpcProducer extends Attribute
2021-03-23 15:21:12 +08:00
{
private string $uri = '';
/**
* Route constructor.
* @param string $cmd
* @param int $port
*/
#[Pure] public function __construct(public string $cmd, public int $port)
{
2021-03-23 18:09:15 +08:00
$this->uri = 'rpc/p' . $this->port . '/' . ltrim($this->cmd, '/');
2021-03-23 15:21:12 +08:00
}
/**
* @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;
}
}