Files
kiri-rpc/src/Annotation/JsonRpc.php
T

37 lines
650 B
PHP
Raw Normal View History

2021-10-26 18:58:09 +08:00
<?php
namespace Kiri\Rpc\Annotation;
2021-10-28 10:52:09 +08:00
use Annotation\Attribute;
2021-10-28 15:14:21 +08:00
use Kiri\Rpc\RpcManager;
use ReflectionException;
2021-10-28 10:52:09 +08:00
#[\Attribute(\Attribute::TARGET_CLASS)] class JsonRpc extends Attribute
2021-10-26 18:58:09 +08:00
{
/**
* @param string $method
* @param string $version
2021-10-28 15:14:21 +08:00
* @param string $protocol
2021-10-26 18:58:09 +08:00
*/
2021-10-28 10:52:09 +08:00
public function __construct(public string $method, public string $version = '2.0', public string $protocol = 'json')
2021-10-26 18:58:09 +08:00
{
}
2021-10-28 10:52:09 +08:00
/**
* @param mixed $class
* @param mixed|string $method
* @return mixed
2021-10-28 15:14:21 +08:00
* @throws ReflectionException
2021-10-28 10:52:09 +08:00
*/
2021-10-28 15:14:21 +08:00
public function execute(mixed $class, mixed $method = ''): bool
2021-10-28 10:52:09 +08:00
{
2021-10-28 15:14:21 +08:00
return RpcManager::add($this->method, $class);
2021-10-28 10:52:09 +08:00
}
2021-10-26 18:58:09 +08:00
}