Files
kiri-core/Rpc/Actuator.php
T
2021-07-19 19:04:13 +08:00

46 lines
694 B
PHP

<?php
namespace Rpc;
use Exception;
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);
}
}