2022-01-09 14:00:32 +08:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace Kiri\Rpc\Annotation;
|
|
|
|
|
|
2022-03-02 16:27:15 +08:00
|
|
|
use Kiri;
|
2022-01-09 14:00:32 +08:00
|
|
|
use Kiri\Abstracts\Config;
|
2022-03-02 16:27:15 +08:00
|
|
|
use Kiri\Annotation\AbstractAttribute;
|
2022-01-09 14:00:32 +08:00
|
|
|
use Kiri\Core\Network;
|
|
|
|
|
use Kiri\Exception\ConfigException;
|
2022-03-02 16:27:15 +08:00
|
|
|
use Kiri\Message\Handler\Router;
|
2022-01-09 14:00:32 +08:00
|
|
|
use Kiri\Rpc\RpcManager;
|
|
|
|
|
use ReflectionException;
|
|
|
|
|
|
2022-02-23 16:32:08 +08:00
|
|
|
#[\Attribute(\Attribute::TARGET_CLASS)] class JsonRpc extends AbstractAttribute
|
2022-01-09 14:00:32 +08:00
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private string $uniqueId = '';
|
2022-05-31 11:11:12 +08:00
|
|
|
|
|
|
|
|
|
2022-01-09 14:00:32 +08:00
|
|
|
/**
|
|
|
|
|
* @param string $service
|
|
|
|
|
*/
|
2022-05-31 11:11:12 +08:00
|
|
|
public function __construct(public string $service)
|
2022-01-09 14:00:32 +08:00
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @param mixed $class
|
|
|
|
|
* @param mixed|string $method
|
|
|
|
|
* @return mixed
|
|
|
|
|
*/
|
|
|
|
|
public function execute(mixed $class, mixed $method = ''): bool
|
|
|
|
|
{
|
2022-03-02 16:27:15 +08:00
|
|
|
$manager = Kiri::getDi()->get(RpcManager::class);
|
|
|
|
|
|
2022-05-31 11:11:12 +08:00
|
|
|
return $manager->add($this->service, $class);
|
2022-01-09 14:00:32 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|