Files
kiri-rpc/src/RpcManager.php
T

47 lines
855 B
PHP
Raw Normal View History

2021-10-28 10:52:09 +08:00
<?php
namespace Kiri\Rpc;
2021-10-28 15:14:21 +08:00
use Kiri\Kiri;
use ReflectionException;
2021-10-28 10:52:09 +08:00
class RpcManager
{
2021-10-28 15:14:21 +08:00
private static array $_rpc = [];
2021-10-28 10:52:09 +08:00
2021-10-28 15:14:21 +08:00
/**
* @param string $name
* @param string $class
* @return bool
* @throws ReflectionException
*/
public static function add(string $name, string $class): bool
2021-10-28 10:52:09 +08:00
{
2021-10-28 15:14:21 +08:00
$methods = Kiri::getDi()->getReflect($class);
$lists = $methods->getMethods(\ReflectionMethod::IS_PUBLIC);
if (!isset(static::$_rpc[$name])) static::$_rpc[$name] = [];
2021-10-28 10:52:09 +08:00
2021-10-28 15:14:21 +08:00
foreach ($lists as $reflection) {
2021-10-28 15:39:34 +08:00
$methodName = $reflection->getName();
2021-10-28 15:14:21 +08:00
2021-10-28 16:19:20 +08:00
static::$_rpc[$name][$methodName] = [[$class, $methodName], null];
2021-10-28 15:14:21 +08:00
}
return true;
2021-10-28 10:52:09 +08:00
}
2021-10-28 15:14:21 +08:00
/**
* @param string $name
* @param string $method
* @return mixed
*/
public static function get(string $name, string $method): array
2021-10-28 10:52:09 +08:00
{
2021-10-28 15:14:21 +08:00
return static::$_rpc[$name][$method] ?? [null, null];
2021-10-28 10:52:09 +08:00
}
}