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
|
<?php
|
||||||
// CurlHttpRequest.php
|
// CurlHttpRequest.php
|
||||||
// Created: 2024-08-13
|
// Created: 2024-08-13
|
||||||
// Updated: 2024-08-16
|
// Updated: 2024-08-13
|
||||||
|
|
||||||
namespace Aiwass\Client;
|
namespace Aiwass;
|
||||||
|
|
||||||
use CurlHandle;
|
use CurlHandle;
|
||||||
use RuntimeException;
|
use RuntimeException;
|
|
@ -1,9 +1,9 @@
|
||||||
<?php
|
<?php
|
||||||
// IHttpRequest.php
|
// IHttpRequest.php
|
||||||
// Created: 2024-08-13
|
// Created: 2024-08-13
|
||||||
// Updated: 2024-08-16
|
// Updated: 2024-08-13
|
||||||
|
|
||||||
namespace Aiwass\Client;
|
namespace Aiwass;
|
||||||
|
|
||||||
use RuntimeException;
|
use RuntimeException;
|
||||||
use Index\ICloseable;
|
use Index\ICloseable;
|
|
@ -3,7 +3,7 @@
|
||||||
// Created: 2024-08-15
|
// Created: 2024-08-15
|
||||||
// Updated: 2024-08-16
|
// Updated: 2024-08-16
|
||||||
|
|
||||||
namespace Aiwass\Server;
|
namespace Aiwass;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Provides the interface for IRpcServer::register().
|
* Provides the interface for IRpcServer::register().
|
|
@ -3,7 +3,7 @@
|
||||||
// Created: 2024-08-16
|
// Created: 2024-08-16
|
||||||
// Updated: 2024-08-16
|
// Updated: 2024-08-16
|
||||||
|
|
||||||
namespace Aiwass\Server;
|
namespace Aiwass;
|
||||||
|
|
||||||
use RuntimeException;
|
use RuntimeException;
|
||||||
use InvalidArgumentException;
|
use InvalidArgumentException;
|
|
@ -3,7 +3,7 @@
|
||||||
// Created: 2024-08-15
|
// Created: 2024-08-15
|
||||||
// Updated: 2024-08-16
|
// Updated: 2024-08-16
|
||||||
|
|
||||||
namespace Aiwass\Server;
|
namespace Aiwass;
|
||||||
|
|
||||||
use Attribute;
|
use Attribute;
|
||||||
use ReflectionAttribute;
|
use ReflectionAttribute;
|
|
@ -1,9 +1,9 @@
|
||||||
<?php
|
<?php
|
||||||
// RpcActionHandler.php
|
// RpcActionHandler.php
|
||||||
// Created: 2024-08-15
|
// 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,
|
* Provides an abstract class version of IRpcActionHandler that already includes the trait as well,
|
|
@ -3,7 +3,7 @@
|
||||||
// Created: 2024-08-15
|
// Created: 2024-08-15
|
||||||
// Updated: 2024-08-16
|
// Updated: 2024-08-16
|
||||||
|
|
||||||
namespace Aiwass\Server;
|
namespace Aiwass;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Provides an implementation of IRpcActionHandler::registerRpcActions that uses the attributes.
|
* Provides an implementation of IRpcActionHandler::registerRpcActions that uses the attributes.
|
|
@ -3,7 +3,7 @@
|
||||||
// Created: 2024-08-13
|
// Created: 2024-08-13
|
||||||
// Updated: 2024-08-16
|
// Updated: 2024-08-16
|
||||||
|
|
||||||
namespace Aiwass\Server;
|
namespace Aiwass;
|
||||||
|
|
||||||
use Closure;
|
use Closure;
|
||||||
use InvalidArgumentException;
|
use InvalidArgumentException;
|
|
@ -1,17 +1,16 @@
|
||||||
<?php
|
<?php
|
||||||
// RpcClient.php
|
// RpcClient.php
|
||||||
// Created: 2024-08-13
|
// Created: 2024-08-13
|
||||||
// Updated: 2024-08-16
|
// Updated: 2024-08-13
|
||||||
|
|
||||||
namespace Aiwass\Client;
|
namespace Aiwass;
|
||||||
|
|
||||||
use InvalidArgumentException;
|
use InvalidArgumentException;
|
||||||
use Aiwass\{AiwassMsgPack,IVerificationProvider};
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Implemens an RPC client.
|
* Implemens an RPC client.
|
||||||
*/
|
*/
|
||||||
class RpcClient implements IRpcClient {
|
class RpcClient {
|
||||||
/**
|
/**
|
||||||
* @param string $url Base RPC url, up to the /_aiwass part.
|
* @param string $url Base RPC url, up to the /_aiwass part.
|
||||||
* @param callable(): IHttpRequest $createRequest Creates a HTTP request.
|
* @param callable(): IHttpRequest $createRequest Creates a HTTP request.
|
||||||
|
@ -26,10 +25,6 @@ class RpcClient implements IRpcClient {
|
||||||
throw new InvalidArgumentException('$createRequest must be a callable');
|
throw new InvalidArgumentException('$createRequest must be a callable');
|
||||||
}
|
}
|
||||||
|
|
||||||
public function scopeTo(string $prefix): IRpcClient {
|
|
||||||
return new RpcClientScoped($this, $prefix);
|
|
||||||
}
|
|
||||||
|
|
||||||
/** @param array<string, mixed> $params */
|
/** @param array<string, mixed> $params */
|
||||||
private function callAction(bool $isProcedure, string $action, array $params): mixed {
|
private function callAction(bool $isProcedure, string $action, array $params): mixed {
|
||||||
$params = http_build_query($params, '', '&', PHP_QUERY_RFC3986);
|
$params = http_build_query($params, '', '&', PHP_QUERY_RFC3986);
|
||||||
|
@ -43,10 +38,24 @@ class RpcClient implements IRpcClient {
|
||||||
return AiwassMsgPack::decode($request->execute());
|
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 {
|
public function query(string $action, array $params): mixed {
|
||||||
return $this->callAction(false, $action, $params);
|
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 {
|
public function procedure(string $action, array $params): mixed {
|
||||||
return $this->callAction(true, $action, $params);
|
return $this->callAction(true, $action, $params);
|
||||||
}
|
}
|
|
@ -3,7 +3,7 @@
|
||||||
// Created: 2024-08-15
|
// Created: 2024-08-15
|
||||||
// Updated: 2024-08-16
|
// Updated: 2024-08-16
|
||||||
|
|
||||||
namespace Aiwass\Server;
|
namespace Aiwass;
|
||||||
|
|
||||||
use Attribute;
|
use Attribute;
|
||||||
/**
|
/**
|
|
@ -3,7 +3,7 @@
|
||||||
// Created: 2024-08-15
|
// Created: 2024-08-15
|
||||||
// Updated: 2024-08-16
|
// Updated: 2024-08-16
|
||||||
|
|
||||||
namespace Aiwass\Server;
|
namespace Aiwass;
|
||||||
|
|
||||||
use Attribute;
|
use Attribute;
|
||||||
/**
|
/**
|
|
@ -3,11 +3,10 @@
|
||||||
// Created: 2024-08-13
|
// Created: 2024-08-13
|
||||||
// Updated: 2024-08-16
|
// Updated: 2024-08-16
|
||||||
|
|
||||||
namespace Aiwass\Server;
|
namespace Aiwass;
|
||||||
|
|
||||||
use Exception;
|
use Exception;
|
||||||
use RuntimeException;
|
use RuntimeException;
|
||||||
use Aiwass\{AiwassMsgPack,IVerificationProvider};
|
|
||||||
use Index\Http\{HttpResponseBuilder,HttpRequest};
|
use Index\Http\{HttpResponseBuilder,HttpRequest};
|
||||||
use Index\Http\Content\FormContent;
|
use Index\Http\Content\FormContent;
|
||||||
use Index\Http\Routing\{HttpGet,HttpPost,RouteHandler};
|
use Index\Http\Routing\{HttpGet,HttpPost,RouteHandler};
|
|
@ -3,7 +3,7 @@
|
||||||
// Created: 2024-08-13
|
// Created: 2024-08-13
|
||||||
// Updated: 2024-08-16
|
// Updated: 2024-08-16
|
||||||
|
|
||||||
namespace Aiwass\Server;
|
namespace Aiwass;
|
||||||
|
|
||||||
use InvalidArgumentException;
|
use InvalidArgumentException;
|
||||||
use RuntimeException;
|
use RuntimeException;
|
|
@ -3,7 +3,7 @@
|
||||||
// Created: 2024-08-16
|
// Created: 2024-08-16
|
||||||
// Updated: 2024-08-16
|
// Updated: 2024-08-16
|
||||||
|
|
||||||
namespace Aiwass\Server;
|
namespace Aiwass;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Provides a scoped RPC server implementation.
|
* Provides a scoped RPC server implementation.
|
||||||
|
@ -11,17 +11,13 @@ namespace Aiwass\Server;
|
||||||
class RpcServerScoped implements IRpcServer {
|
class RpcServerScoped implements IRpcServer {
|
||||||
use RpcServerTrait;
|
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(
|
public function __construct(
|
||||||
private IRpcServer $base,
|
private IRpcServer $base,
|
||||||
private string $prefix
|
private string $prefix
|
||||||
) {}
|
) {}
|
||||||
|
|
||||||
public function scopeTo(string $prefix): IRpcServer {
|
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 {
|
public function registerAction(bool $isProcedure, string $name, $handler): void {
|
|
@ -3,7 +3,7 @@
|
||||||
// Created: 2024-08-16
|
// Created: 2024-08-16
|
||||||
// Updated: 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.
|
* 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 RuntimeException;
|
||||||
use PHPUnit\Framework\TestCase;
|
use PHPUnit\Framework\TestCase;
|
||||||
use PHPUnit\Framework\Attributes\{CoversClass,UsesClass};
|
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(RpcAction::class)]
|
||||||
#[CoversClass(RpcActionHandler::class)]
|
#[CoversClass(RpcActionHandler::class)]
|
||||||
|
|
|
@ -1,13 +1,13 @@
|
||||||
<?php
|
<?php
|
||||||
// CurlHttpTest.php
|
// CurlHttpTest.php
|
||||||
// Created: 2024-08-13
|
// Created: 2024-08-13
|
||||||
// Updated: 2024-08-16
|
// Updated: 2024-08-13
|
||||||
|
|
||||||
declare(strict_types=1);
|
declare(strict_types=1);
|
||||||
|
|
||||||
use PHPUnit\Framework\TestCase;
|
use PHPUnit\Framework\TestCase;
|
||||||
use PHPUnit\Framework\Attributes\CoversClass;
|
use PHPUnit\Framework\Attributes\CoversClass;
|
||||||
use Aiwass\Client\CurlHttpRequest;
|
use Aiwass\CurlHttpRequest;
|
||||||
|
|
||||||
#[CoversClass(CurlHttpRequest::class)]
|
#[CoversClass(CurlHttpRequest::class)]
|
||||||
final class CurlHttpTest extends TestCase {
|
final class CurlHttpTest extends TestCase {
|
||||||
|
|
|
@ -7,7 +7,7 @@ declare(strict_types=1);
|
||||||
|
|
||||||
use PHPUnit\Framework\TestCase;
|
use PHPUnit\Framework\TestCase;
|
||||||
use PHPUnit\Framework\Attributes\{CoversClass,UsesClass};
|
use PHPUnit\Framework\Attributes\{CoversClass,UsesClass};
|
||||||
use Aiwass\Server\{RpcServer,RpcServerScoped};
|
use Aiwass\{RpcServer,RpcServerScoped};
|
||||||
|
|
||||||
#[CoversClass(RpcServerScoped::class)]
|
#[CoversClass(RpcServerScoped::class)]
|
||||||
#[UsesClass(RpcServer::class)]
|
#[UsesClass(RpcServer::class)]
|
||||||
|
|
Loading…
Reference in a new issue