改名
This commit is contained in:
@@ -1,57 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
|
|
||||||
namespace Annotation\Route;
|
|
||||||
|
|
||||||
|
|
||||||
use Annotation\Attribute;
|
|
||||||
use Exception;
|
|
||||||
use HttpServer\Http\Request;
|
|
||||||
use HttpServer\Route\Router;
|
|
||||||
use JetBrains\PhpStorm\Pure;
|
|
||||||
use Rpc\Actuator;
|
|
||||||
use Kiri\Kiri;
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Class RpcProducer
|
|
||||||
* @package Annotation\Route
|
|
||||||
*/
|
|
||||||
#[\Attribute(\Attribute::TARGET_METHOD)] class RpcProducer extends Attribute
|
|
||||||
{
|
|
||||||
|
|
||||||
const PROTOCOL_JSON = 'json';
|
|
||||||
const PROTOCOL_SERIALIZE = 'serialize';
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Route constructor.
|
|
||||||
* @param string $cmd
|
|
||||||
* @param string $protocol
|
|
||||||
* @param int $port
|
|
||||||
*/
|
|
||||||
#[Pure] public function __construct(public string $cmd, public string $protocol = self::PROTOCOL_SERIALIZE, public int $port = 443)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param mixed $class
|
|
||||||
* @param mixed|null $method
|
|
||||||
* @return Router
|
|
||||||
* @throws Exception
|
|
||||||
*/
|
|
||||||
public function execute(mixed $class, mixed $method = null): Router
|
|
||||||
{
|
|
||||||
// TODO: Implement setHandler() method.
|
|
||||||
$router = Kiri::app()->getRouter();
|
|
||||||
$cmd = $this->cmd;
|
|
||||||
$callback = function (Actuator $actuator) use ($cmd, $class, $method) {
|
|
||||||
$actuator->addListener($cmd, $class::class . '@' . $method);
|
|
||||||
};
|
|
||||||
$router->addRpcService($this->port, $callback);
|
|
||||||
return $router;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,55 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
|
|
||||||
namespace Annotation\Rpc;
|
|
||||||
|
|
||||||
|
|
||||||
use Annotation\Attribute;
|
|
||||||
use Exception;
|
|
||||||
use Kiri\Kiri;
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Class RpcClient
|
|
||||||
* @package Annotation\Rpc
|
|
||||||
*/
|
|
||||||
#[\Attribute(\Attribute::TARGET_CLASS)] class RpcClient extends Attribute
|
|
||||||
{
|
|
||||||
|
|
||||||
private array $config;
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* RpcClient constructor.
|
|
||||||
* @param string $cmd
|
|
||||||
* @param int $port
|
|
||||||
* @param int $timeout
|
|
||||||
* @param int $mode
|
|
||||||
*/
|
|
||||||
public function __construct(
|
|
||||||
public string $cmd,
|
|
||||||
public int $port,
|
|
||||||
public int $timeout,
|
|
||||||
public int $mode
|
|
||||||
)
|
|
||||||
{
|
|
||||||
$this->config = ['port' => $port, 'mode' => $mode, 'timeout' => $timeout];
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param mixed $class
|
|
||||||
* @param mixed $method
|
|
||||||
* @return bool
|
|
||||||
* @throws Exception
|
|
||||||
*/
|
|
||||||
public function execute(mixed $class, mixed $method = ''): bool
|
|
||||||
{
|
|
||||||
$rpc = Kiri::app()->getRpc();
|
|
||||||
$rpc->addProducer($this->cmd, [$class, $method], $this->config);
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user