Files
kiri-core/Rpc/Actuator.php
T
as2252258@163.com 12d547c1a2 modify
2021-07-11 03:57:25 +08:00

45 lines
681 B
PHP

<?php
namespace Rpc;
use HttpServer\Route\Router;
use Snowflake\Snowflake;
/**
* Class Actuator
* @package Rpc
*/
class Actuator
{
private Router $router;
/**
* Actuator constructor.
* @param int $port
* @throws \Exception
*/
public function __construct(public int $port)
{
$this->router = Snowflake::getApp('router');
}
/**
* @param string $path
* @param string|callable $callback
* @throws \Exception
*/
public function addListener(string $path, string|callable $callback): void
{
$this->router->addRoute('rpc/p' . $this->port . '/' . ltrim($path, '/'), $callback);
}
}