Compare commits

..

4 commits

7 changed files with 36 additions and 8 deletions

View file

@ -1 +1 @@
0.1.0-dev
1.0.0

View file

@ -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,
);
}
}

View file

@ -6,6 +6,7 @@
namespace Aiwass\Server;
use Attribute;
/**
* Provides an attribute for marking methods in a class as an RPC Query action.
*/

View file

@ -6,6 +6,7 @@
namespace Aiwass\Server;
use Attribute;
/**
* Provides an attribute for marking methods in a class as an RPC Query action.
*/

View file

@ -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
) {}
/**

View file

@ -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);
}

View file

@ -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};