From bd57d80ba1577cc9f521b341479d9ec1c1fb0554 Mon Sep 17 00:00:00 2001 From: Akihito Koriyama Date: Mon, 25 Mar 2024 16:39:27 +0900 Subject: [PATCH] Change interface name --- README.md | 4 ++-- client/php_client/main.php | 6 +++--- src/ImportSchemeCollectionProvider.php | 2 +- src/{ResourceInvoker.php => ResourceInvoke.php} | 4 ++-- ...urceInvokerInterface.php => ResourceInvokeInterface.php} | 4 ++-- src/ThriftAdapter.php | 2 +- src/ThriftResourceObject.php | 4 ++-- 7 files changed, 13 insertions(+), 13 deletions(-) rename src/{ResourceInvoker.php => ResourceInvoke.php} (89%) rename src/{ResourceInvokerInterface.php => ResourceInvokeInterface.php} (78%) diff --git a/README.md b/README.md index 1628ea4..b2215fc 100644 --- a/README.md +++ b/README.md @@ -76,8 +76,8 @@ echo $resource->get('page://sekai/?name=World'); // "greeting": "Hello World" fr $method = 'get'; $uri = '/user?id=1'; -$invoker = new ResourceInvoker($host, $port); -$response = $invoker->resourceInvoke($method, $uri); +$invoke = new ResourceInvoke($host, $port); +$response = $invoke($method, $uri); assert($response instanceof ResourceResponse); printf("Response Code: %s\n", $response->code); diff --git a/client/php_client/main.php b/client/php_client/main.php index 354fd48..d24a308 100644 --- a/client/php_client/main.php +++ b/client/php_client/main.php @@ -1,13 +1,13 @@ resourceInvoke($method, $uri); + $invoke = new ResourceInvoke($host, $port); + $response = $invoke($method, $uri); assert($response instanceof ResourceResponse); printf("Response Code: %s\n", $response->code); printf("Response Headers: %s\n", json_encode($response->headers)); diff --git a/src/ImportSchemeCollectionProvider.php b/src/ImportSchemeCollectionProvider.php index 29f6a88..3e0ee22 100644 --- a/src/ImportSchemeCollectionProvider.php +++ b/src/ImportSchemeCollectionProvider.php @@ -32,7 +32,7 @@ public function get(): SchemeCollectionInterface { foreach ($this->importAppConfig as $app) { $adapter = $app instanceof ImportApp ? new AppAdapter($this->injector, $app->appName) : - new ThriftAdapter(new ResourceInvoker($app->thriftHost, $app->thriftPort)); + new ThriftAdapter(new ResourceInvoke($app->thriftHost, $app->thriftPort)); $this->schemeCollection ->scheme('page')->host($app->host)->toAdapter($adapter) ->scheme('app')->host($app->host)->toAdapter($adapter); diff --git a/src/ResourceInvoker.php b/src/ResourceInvoke.php similarity index 89% rename from src/ResourceInvoker.php rename to src/ResourceInvoke.php index 678a931..9cdba75 100644 --- a/src/ResourceInvoker.php +++ b/src/ResourceInvoke.php @@ -13,7 +13,7 @@ use Thrift\Transport\TSocket; use Throwable; -final class ResourceInvoker implements ResourceInvokerInterface +final class ResourceInvoke implements ResourceInvokeInterface { private ResourceServiceClient $resourceService; private TBufferedTransport $transport; @@ -27,7 +27,7 @@ public function __construct(string $host, int $port) } /** {@inheritdoc } */ - public function resourceInvoke(string $method, string $uri): ResourceResponse + public function __invoke(string $method, string $uri): ResourceResponse { $this->transport->open(); $request = new ResourceRequest( diff --git a/src/ResourceInvokerInterface.php b/src/ResourceInvokeInterface.php similarity index 78% rename from src/ResourceInvokerInterface.php rename to src/ResourceInvokeInterface.php index 76db2bc..d292112 100644 --- a/src/ResourceInvokerInterface.php +++ b/src/ResourceInvokeInterface.php @@ -6,7 +6,7 @@ use ResourceService\ResourceResponse; -interface ResourceInvokerInterface +interface ResourceInvokeInterface { /** * Invokes a resource with the given method, path, and optional query string. @@ -16,5 +16,5 @@ interface ResourceInvokerInterface * * @return ResourceResponse The response from the resource invocation. */ - public function resourceInvoke(string $method, string $uri): ResourceResponse; + public function __invoke(string $method, string $uri): ResourceResponse; } diff --git a/src/ThriftAdapter.php b/src/ThriftAdapter.php index 57009dc..d958451 100644 --- a/src/ThriftAdapter.php +++ b/src/ThriftAdapter.php @@ -11,7 +11,7 @@ final class ThriftAdapter implements AdapterInterface { public function __construct( - private ResourceInvokerInterface $invoker, + private ResourceInvokeInterface $invoker, ) { } diff --git a/src/ThriftResourceObject.php b/src/ThriftResourceObject.php index c71a596..511042b 100644 --- a/src/ThriftResourceObject.php +++ b/src/ThriftResourceObject.php @@ -38,7 +38,7 @@ final class ThriftResourceObject extends ResourceObject private ResponseInterface $response; public function __construct( - private ResourceInvokerInterface $invoker, + private ResourceInvokeInterface $invoke, ) { unset($this->code, $this->headers, $this->body, $this->view); } @@ -49,7 +49,7 @@ public function _invokeRequest(InvokerInterface $invoker, AbstractRequest $reque $uri = $request->resourceObject->uri; $method = strtoupper($uri->method); - $response = $this->invoker->resourceInvoke($method, (string) $uri, http_build_query($uri->query)); + $response = ($this->invoke)($method, (string) $uri); if ($response->code >= 400) { throw new ThriftRemoteExecutionException($response->jsonValue, $response->code); }