Compare commits
No commits in common. "bf092daec724b32d79f1c355eb462a293e263b1c" and "d6819a29fece6e920e4997ba4000088e257dc548" have entirely different histories.
bf092daec7
...
d6819a29fe
20 changed files with 39 additions and 104 deletions
|
@ -1,37 +0,0 @@
|
|||
<?php
|
||||
// IRpcClient.php
|
||||
// Created: 2024-08-16
|
||||
// Updated: 2024-08-16
|
||||
|
||||
namespace Aiwass\Client;
|
||||
|
||||
/**
|
||||
* Provides a common interface for RPC clients.
|
||||
*/
|
||||
interface IRpcClient {
|
||||
/**
|
||||
* Creates a proxy for this RPC client with a specified namespace.
|
||||
*
|
||||
* @param string $prefix Prefix to apply to the scoped RPC client.
|
||||
* @return IRpcClient A scoped RPC client instance.
|
||||
*/
|
||||
function scopeTo(string $prefix): IRpcClient;
|
||||
|
||||
/**
|
||||
* Makes an RPC query.
|
||||
*
|
||||
* @param string $action Name of the action.
|
||||
* @param array<string, mixed> $params Parameters to query with.
|
||||
* @return mixed Result of the query.
|
||||
*/
|
||||
function query(string $action, array $params): mixed;
|
||||
|
||||
/**
|
||||
* Makes an RPC procedure call.
|
||||
*
|
||||
* @param string $action Name of the action.
|
||||
* @param array<string, mixed> $params Parameters to query with.
|
||||
* @return mixed Result of the procedure call.
|
||||
*/
|
||||
function procedure(string $action, array $params): mixed;
|
||||
}
|
|
@ -1,32 +0,0 @@
|
|||
<?php
|
||||
// RpcClientScoped.php
|
||||
// Created: 2024-08-16
|
||||
// Updated: 2024-08-16
|
||||
|
||||
namespace Aiwass\Client;
|
||||
|
||||
/**
|
||||
* Provides a scoped interface to an underlying RPC client.
|
||||
*/
|
||||
class RpcClientScoped implements IRpcClient {
|
||||
/**
|
||||
* @param IRpcClient $base RPC client instance to use as a base.
|
||||
* @param string $prefix Prefix to apply to action names passed.
|
||||
*/
|
||||
public function __construct(
|
||||
private IRpcClient $base,
|
||||
private string $prefix
|
||||
) {}
|
||||
|
||||
public function scopeTo(string $prefix): IRpcClient {
|
||||
return $this->base->scopeTo($this->prefix . $prefix);
|
||||
}
|
||||
|
||||
public function query(string $action, array $params): mixed {
|
||||
return $this->base->query($this->prefix . $action, $params);
|
||||
}
|
||||
|
||||
public function procedure(string $action, array $params): mixed {
|
||||
return $this->base->procedure($this->prefix . $action, $params);
|
||||
}
|
||||
}
|
|
@ -1,9 +1,9 @@
|
|||
<?php
|
||||
// CurlHttpRequest.php
|
||||
// Created: 2024-08-13
|
||||
// Updated: 2024-08-16
|
||||
// Updated: 2024-08-13
|
||||
|
||||
namespace Aiwass\Client;
|
||||
namespace Aiwass;
|
||||
|
||||
use CurlHandle;
|
||||
use RuntimeException;
|
|
@ -1,9 +1,9 @@
|
|||
<?php
|
||||
// IHttpRequest.php
|
||||
// Created: 2024-08-13
|
||||
// Updated: 2024-08-16
|
||||
// Updated: 2024-08-13
|
||||
|
||||
namespace Aiwass\Client;
|
||||
namespace Aiwass;
|
||||
|
||||
use RuntimeException;
|
||||
use Index\ICloseable;
|
|
@ -3,7 +3,7 @@
|
|||
// Created: 2024-08-15
|
||||
// Updated: 2024-08-16
|
||||
|
||||
namespace Aiwass\Server;
|
||||
namespace Aiwass;
|
||||
|
||||
/**
|
||||
* Provides the interface for IRpcServer::register().
|
|
@ -3,7 +3,7 @@
|
|||
// Created: 2024-08-16
|
||||
// Updated: 2024-08-16
|
||||
|
||||
namespace Aiwass\Server;
|
||||
namespace Aiwass;
|
||||
|
||||
use RuntimeException;
|
||||
use InvalidArgumentException;
|
|
@ -3,7 +3,7 @@
|
|||
// Created: 2024-08-15
|
||||
// Updated: 2024-08-16
|
||||
|
||||
namespace Aiwass\Server;
|
||||
namespace Aiwass;
|
||||
|
||||
use Attribute;
|
||||
use ReflectionAttribute;
|
|
@ -1,9 +1,9 @@
|
|||
<?php
|
||||
// RpcActionHandler.php
|
||||
// Created: 2024-08-15
|
||||
// Updated: 2024-08-16
|
||||
// Updated: 2024-08-15
|
||||
|
||||
namespace Aiwass\Server;
|
||||
namespace Aiwass;
|
||||
|
||||
/**
|
||||
* Provides an abstract class version of IRpcActionHandler that already includes the trait as well,
|
|
@ -3,7 +3,7 @@
|
|||
// Created: 2024-08-15
|
||||
// Updated: 2024-08-16
|
||||
|
||||
namespace Aiwass\Server;
|
||||
namespace Aiwass;
|
||||
|
||||
/**
|
||||
* Provides an implementation of IRpcActionHandler::registerRpcActions that uses the attributes.
|
|
@ -3,7 +3,7 @@
|
|||
// Created: 2024-08-13
|
||||
// Updated: 2024-08-16
|
||||
|
||||
namespace Aiwass\Server;
|
||||
namespace Aiwass;
|
||||
|
||||
use Closure;
|
||||
use InvalidArgumentException;
|
|
@ -1,17 +1,16 @@
|
|||
<?php
|
||||
// RpcClient.php
|
||||
// Created: 2024-08-13
|
||||
// Updated: 2024-08-16
|
||||
// Updated: 2024-08-13
|
||||
|
||||
namespace Aiwass\Client;
|
||||
namespace Aiwass;
|
||||
|
||||
use InvalidArgumentException;
|
||||
use Aiwass\{AiwassMsgPack,IVerificationProvider};
|
||||
|
||||
/**
|
||||
* Implemens an RPC client.
|
||||
*/
|
||||
class RpcClient implements IRpcClient {
|
||||
class RpcClient {
|
||||
/**
|
||||
* @param string $url Base RPC url, up to the /_aiwass part.
|
||||
* @param callable(): IHttpRequest $createRequest Creates a HTTP request.
|
||||
|
@ -26,10 +25,6 @@ class RpcClient implements IRpcClient {
|
|||
throw new InvalidArgumentException('$createRequest must be a callable');
|
||||
}
|
||||
|
||||
public function scopeTo(string $prefix): IRpcClient {
|
||||
return new RpcClientScoped($this, $prefix);
|
||||
}
|
||||
|
||||
/** @param array<string, mixed> $params */
|
||||
private function callAction(bool $isProcedure, string $action, array $params): mixed {
|
||||
$params = http_build_query($params, '', '&', PHP_QUERY_RFC3986);
|
||||
|
@ -43,10 +38,24 @@ class RpcClient implements IRpcClient {
|
|||
return AiwassMsgPack::decode($request->execute());
|
||||
}
|
||||
|
||||
/**
|
||||
* Makes an RPC query.
|
||||
*
|
||||
* @param string $action Name of the action.
|
||||
* @param array<string, mixed> $params Parameters to query with.
|
||||
* @return mixed Result of the query.
|
||||
*/
|
||||
public function query(string $action, array $params): mixed {
|
||||
return $this->callAction(false, $action, $params);
|
||||
}
|
||||
|
||||
/**
|
||||
* Makes an RPC procedure call.
|
||||
*
|
||||
* @param string $action Name of the action.
|
||||
* @param array<string, mixed> $params Parameters to query with.
|
||||
* @return mixed Result of the procedure call.
|
||||
*/
|
||||
public function procedure(string $action, array $params): mixed {
|
||||
return $this->callAction(true, $action, $params);
|
||||
}
|
|
@ -3,7 +3,7 @@
|
|||
// Created: 2024-08-15
|
||||
// Updated: 2024-08-16
|
||||
|
||||
namespace Aiwass\Server;
|
||||
namespace Aiwass;
|
||||
|
||||
use Attribute;
|
||||
/**
|
|
@ -3,7 +3,7 @@
|
|||
// Created: 2024-08-15
|
||||
// Updated: 2024-08-16
|
||||
|
||||
namespace Aiwass\Server;
|
||||
namespace Aiwass;
|
||||
|
||||
use Attribute;
|
||||
/**
|
|
@ -3,11 +3,10 @@
|
|||
// Created: 2024-08-13
|
||||
// Updated: 2024-08-16
|
||||
|
||||
namespace Aiwass\Server;
|
||||
namespace Aiwass;
|
||||
|
||||
use Exception;
|
||||
use RuntimeException;
|
||||
use Aiwass\{AiwassMsgPack,IVerificationProvider};
|
||||
use Index\Http\{HttpResponseBuilder,HttpRequest};
|
||||
use Index\Http\Content\FormContent;
|
||||
use Index\Http\Routing\{HttpGet,HttpPost,RouteHandler};
|
|
@ -3,7 +3,7 @@
|
|||
// Created: 2024-08-13
|
||||
// Updated: 2024-08-16
|
||||
|
||||
namespace Aiwass\Server;
|
||||
namespace Aiwass;
|
||||
|
||||
use InvalidArgumentException;
|
||||
use RuntimeException;
|
|
@ -3,7 +3,7 @@
|
|||
// Created: 2024-08-16
|
||||
// Updated: 2024-08-16
|
||||
|
||||
namespace Aiwass\Server;
|
||||
namespace Aiwass;
|
||||
|
||||
/**
|
||||
* Provides a scoped RPC server implementation.
|
||||
|
@ -11,17 +11,13 @@ namespace Aiwass\Server;
|
|||
class RpcServerScoped implements IRpcServer {
|
||||
use RpcServerTrait;
|
||||
|
||||
/**
|
||||
* @param IRpcServer $base RPC server instance to use as a base.
|
||||
* @param string $prefix Prefix to apply to action names passed.
|
||||
*/
|
||||
public function __construct(
|
||||
private IRpcServer $base,
|
||||
private string $prefix
|
||||
) {}
|
||||
|
||||
public function scopeTo(string $prefix): IRpcServer {
|
||||
return $this->base->scopeTo($this->prefix . $prefix);
|
||||
return new RpcServerScoped($this->base, $this->prefix . $prefix);
|
||||
}
|
||||
|
||||
public function registerAction(bool $isProcedure, string $name, $handler): void {
|
|
@ -3,7 +3,7 @@
|
|||
// Created: 2024-08-16
|
||||
// Updated: 2024-08-16
|
||||
|
||||
namespace Aiwass\Server;
|
||||
namespace Aiwass;
|
||||
|
||||
/**
|
||||
* Provides implementations for IRpcServer methods that are likely going to be identical across implementations.
|
|
@ -8,7 +8,7 @@ declare(strict_types=1);
|
|||
use RuntimeException;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use PHPUnit\Framework\Attributes\{CoversClass,UsesClass};
|
||||
use Aiwass\Server\{RpcAction,RpcActionHandler,RpcProcedure,RpcQuery,RpcServer};
|
||||
use Aiwass\{RpcAction,RpcActionHandler,RpcProcedure,RpcQuery,RpcServer};
|
||||
|
||||
#[CoversClass(RpcAction::class)]
|
||||
#[CoversClass(RpcActionHandler::class)]
|
||||
|
|
|
@ -1,13 +1,13 @@
|
|||
<?php
|
||||
// CurlHttpTest.php
|
||||
// Created: 2024-08-13
|
||||
// Updated: 2024-08-16
|
||||
// Updated: 2024-08-13
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use PHPUnit\Framework\Attributes\CoversClass;
|
||||
use Aiwass\Client\CurlHttpRequest;
|
||||
use Aiwass\CurlHttpRequest;
|
||||
|
||||
#[CoversClass(CurlHttpRequest::class)]
|
||||
final class CurlHttpTest extends TestCase {
|
||||
|
|
|
@ -7,7 +7,7 @@ declare(strict_types=1);
|
|||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use PHPUnit\Framework\Attributes\{CoversClass,UsesClass};
|
||||
use Aiwass\Server\{RpcServer,RpcServerScoped};
|
||||
use Aiwass\{RpcServer,RpcServerScoped};
|
||||
|
||||
#[CoversClass(RpcServerScoped::class)]
|
||||
#[UsesClass(RpcServer::class)]
|
||||
|
|
Loading…
Reference in a new issue