Compare commits
4 commits
bf092daec7
...
de27da54b6
Author | SHA1 | Date | |
---|---|---|---|
de27da54b6 | |||
3bc14cc6a7 | |||
11427d34fc | |||
bed29b7d49 |
7 changed files with 36 additions and 8 deletions
2
VERSION
2
VERSION
|
@ -1 +1 @@
|
|||
0.1.0-dev
|
||||
1.0.0
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
namespace Aiwass\Client;
|
||||
|
||||
use InvalidArgumentException;
|
||||
use Aiwass\{AiwassMsgPack,IVerificationProvider};
|
||||
use Aiwass\{AiwassMsgPack,HmacVerificationProvider,IVerificationProvider};
|
||||
|
||||
/**
|
||||
* Implemens an RPC client.
|
||||
|
@ -14,13 +14,13 @@ use Aiwass\{AiwassMsgPack,IVerificationProvider};
|
|||
class RpcClient implements IRpcClient {
|
||||
/**
|
||||
* @param string $url Base RPC url, up to the /_aiwass part.
|
||||
* @param callable(): IHttpRequest $createRequest Creates a HTTP request.
|
||||
* @param IVerificationProvider $verify A verification provider.
|
||||
* @param callable(): IHttpRequest $createRequest Creates a HTTP request.
|
||||
*/
|
||||
public function __construct(
|
||||
private string $url,
|
||||
private $createRequest,
|
||||
private IVerificationProvider $verify
|
||||
private IVerificationProvider $verify,
|
||||
private $createRequest
|
||||
) {
|
||||
if(!is_callable($createRequest))
|
||||
throw new InvalidArgumentException('$createRequest must be a callable');
|
||||
|
@ -50,4 +50,19 @@ class RpcClient implements IRpcClient {
|
|||
public function procedure(string $action, array $params): mixed {
|
||||
return $this->callAction(true, $action, $params);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates an RPC client with HMAC verification and a suitable HTTP request implementation.
|
||||
*
|
||||
* @param string $url Base RPC url, up to the /_aiwass part.
|
||||
* @param callable(): string $getSecretKey A method that returns the secret key to use.
|
||||
* @return RpcClient An RPC client!
|
||||
*/
|
||||
public static function createHmac(string $url, $getSecretKey): RpcClient {
|
||||
return new RpcClient(
|
||||
$url,
|
||||
new HmacVerificationProvider($getSecretKey),
|
||||
fn() => new CurlHttpRequest,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,6 +6,7 @@
|
|||
namespace Aiwass\Server;
|
||||
|
||||
use Attribute;
|
||||
|
||||
/**
|
||||
* Provides an attribute for marking methods in a class as an RPC Query action.
|
||||
*/
|
||||
|
|
|
@ -6,6 +6,7 @@
|
|||
namespace Aiwass\Server;
|
||||
|
||||
use Attribute;
|
||||
|
||||
/**
|
||||
* Provides an attribute for marking methods in a class as an RPC Query action.
|
||||
*/
|
||||
|
|
|
@ -18,10 +18,11 @@ use Index\Http\Routing\{HttpGet,HttpPost,RouteHandler};
|
|||
class RpcRouteHandler extends RouteHandler {
|
||||
/**
|
||||
* @param IRpcServer $server An RPC server instance.
|
||||
* @param IVerificationProvider $verification A verification provider instance.
|
||||
*/
|
||||
public function __construct(
|
||||
private IVerificationProvider $verification,
|
||||
private IRpcServer $server
|
||||
private IRpcServer $server,
|
||||
private IVerificationProvider $verification
|
||||
) {}
|
||||
|
||||
/**
|
||||
|
|
|
@ -7,6 +7,7 @@ namespace Aiwass\Server;
|
|||
|
||||
use InvalidArgumentException;
|
||||
use RuntimeException;
|
||||
use Aiwass\IVerificationProvider;
|
||||
|
||||
/**
|
||||
* Implements an RPC server.
|
||||
|
@ -17,6 +18,16 @@ class RpcServer implements IRpcServer {
|
|||
/** @var array<string, RpcActionInfo> */
|
||||
private array $actions = [];
|
||||
|
||||
/**
|
||||
* Creates an RPC route handler.
|
||||
*
|
||||
* @param IVerificationProvider $verification A verification provider.
|
||||
* @return RpcRouteHandler RPC route handler.
|
||||
*/
|
||||
public function createRouteHandler(IVerificationProvider $verification): RpcRouteHandler {
|
||||
return new RpcRouteHandler($this, $verification);
|
||||
}
|
||||
|
||||
public function scopeTo(string $prefix): IRpcServer {
|
||||
return new RpcServerScoped($this, $prefix);
|
||||
}
|
||||
|
|
|
@ -5,7 +5,6 @@
|
|||
|
||||
declare(strict_types=1);
|
||||
|
||||
use RuntimeException;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use PHPUnit\Framework\Attributes\{CoversClass,UsesClass};
|
||||
use Aiwass\Server\{RpcAction,RpcActionHandler,RpcProcedure,RpcQuery,RpcServer};
|
||||
|
|
Loading…
Reference in a new issue