modify
This commit is contained in:
@@ -9,6 +9,7 @@ use Exception;
|
||||
use HttpServer\Http\Request;
|
||||
use HttpServer\Route\Router;
|
||||
use JetBrains\PhpStorm\Pure;
|
||||
use Rpc\Actuator;
|
||||
use Snowflake\Snowflake;
|
||||
|
||||
|
||||
@@ -19,39 +20,38 @@ use Snowflake\Snowflake;
|
||||
#[\Attribute(\Attribute::TARGET_METHOD)] class RpcProducer extends Attribute
|
||||
{
|
||||
|
||||
private string $uri = '';
|
||||
|
||||
const PROTOCOL_JSON = 'json';
|
||||
const PROTOCOL_SERIALIZE = 'serialize';
|
||||
const PROTOCOL_JSON = 'json';
|
||||
const PROTOCOL_SERIALIZE = 'serialize';
|
||||
|
||||
|
||||
/**
|
||||
* Route constructor.
|
||||
* @param string $cmd
|
||||
* @param string $protocol
|
||||
* @param int $port
|
||||
*/
|
||||
#[Pure] public function __construct(public string $cmd, public string $protocol = self::PROTOCOL_SERIALIZE, public int $port = 443)
|
||||
{
|
||||
$this->uri = 'rpc/p' . $this->port . '/' . ltrim($this->cmd, '/');
|
||||
}
|
||||
/**
|
||||
* Route constructor.
|
||||
* @param string $cmd
|
||||
* @param string $protocol
|
||||
* @param int $port
|
||||
*/
|
||||
#[Pure] public function __construct(public string $cmd, public string $protocol = self::PROTOCOL_SERIALIZE, public int $port = 443)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param array $handler
|
||||
* @return Router
|
||||
* @throws Exception
|
||||
*/
|
||||
|
||||
/**
|
||||
* @param array $handler
|
||||
* @return Router
|
||||
* @throws Exception
|
||||
*/
|
||||
public function execute(mixed $class, mixed $method = null): Router
|
||||
{
|
||||
// TODO: Implement setHandler() method.
|
||||
$router = Snowflake::app()->getRouter();
|
||||
|
||||
$router->addRoute($this->uri, [$class, $method], Request::HTTP_CMD)
|
||||
->setDataType($this->protocol);
|
||||
|
||||
return $router;
|
||||
}
|
||||
{
|
||||
// TODO: Implement setHandler() method.
|
||||
$router = Snowflake::app()->getRouter();
|
||||
$cmd = $this->cmd;
|
||||
$callback = function (Actuator $actuator) use ($cmd, $class, $method) {
|
||||
$actuator->addListener($cmd, $class . '@' . $method);
|
||||
};
|
||||
$router->addRpcService($this->port, $callback);
|
||||
return $router;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user