diff --git a/src/Annotation/JsonRpc.php b/src/Annotation/JsonRpc.php index 1c15003..d6f5e0e 100644 --- a/src/Annotation/JsonRpc.php +++ b/src/Annotation/JsonRpc.php @@ -2,7 +2,11 @@ namespace Kiri\Rpc\Annotation; -#[\Attribute(\Attribute::TARGET_CLASS)] class JsonRpc +use Annotation\Attribute; +use Http\Handler\Router; +use Kiri\Kiri; + +#[\Attribute(\Attribute::TARGET_CLASS)] class JsonRpc extends Attribute { @@ -10,10 +14,21 @@ namespace Kiri\Rpc\Annotation; * @param string $method * @param string $version */ - public function __construct(public string $method, public string $version = '2.0') + public function __construct(public string $method, public string $version = '2.0', public string $protocol = 'json') { } + /** + * @param mixed $class + * @param mixed|string $method + * @return mixed + */ + public function execute(mixed $class, mixed $method = ''): mixed + { + return parent::execute($class, $method); // TODO: Change the autogenerated stub + } + + } diff --git a/src/Annotation/JsonRpcMethod.php b/src/Annotation/JsonRpcMethod.php new file mode 100644 index 0000000..aa90dd7 --- /dev/null +++ b/src/Annotation/JsonRpcMethod.php @@ -0,0 +1,44 @@ +getReflectMethod($class, $method); + $parent = $reflect->getDeclaringClass()->getAttributes(JsonRpc::class); + + if (empty($parent)) { + return parent::execute($class, $method); + } + /** @var JsonRpc $attribute */ + $attribute = $parent[0]->newInstance(); + Router::addService($attribute->service, function () use ($class, $method) { + Router::jsonp($this->method, [di($class), $method]); + }, $attribute->version); + return parent::execute($class, $method); // TODO: Change the autogenerated stub + } + + +} diff --git a/src/OnRpcConsumerInterface.php b/src/OnRpcConsumerInterface.php index 1141b1e..019b3bf 100644 --- a/src/OnRpcConsumerInterface.php +++ b/src/OnRpcConsumerInterface.php @@ -5,4 +5,7 @@ namespace Kiri\Rpc; interface OnRpcConsumerInterface { + + public function execute(); + } diff --git a/src/RpcManager.php b/src/RpcManager.php new file mode 100644 index 0000000..de957ca --- /dev/null +++ b/src/RpcManager.php @@ -0,0 +1,20 @@ +request->int('a') + $this->request->int('b'); } + + }