Files
kiri-core/Rpc/Actuator.php
T

46 lines
694 B
PHP
Raw Normal View History

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