Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change ResourceInvokerInterace name #6

Merged
merged 1 commit into from
Mar 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
6 changes: 3 additions & 3 deletions client/php_client/main.php
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
<?php

use BEARSunday\Thrift\ResourceInvoker;
use BEARSunday\Thrift\ResourceInvoke;
use ResourceService\ResourceResponse;

require dirname(__DIR__, 2) . '/vendor/autoload.php';

(function(string $host, string $port, string $method, string $uri): void {
$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);
printf("Response Headers: %s\n", json_encode($response->headers));
Expand Down
2 changes: 1 addition & 1 deletion src/ImportSchemeCollectionProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions src/ResourceInvoker.php → src/ResourceInvoke.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

use ResourceService\ResourceResponse;

interface ResourceInvokerInterface
interface ResourceInvokeInterface
{
/**
* Invokes a resource with the given method, path, and optional query string.
Expand All @@ -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;
}
2 changes: 1 addition & 1 deletion src/ThriftAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
final class ThriftAdapter implements AdapterInterface
{
public function __construct(
private ResourceInvokerInterface $invoker,
private ResourceInvokeInterface $invoker,
) {
}

Expand Down
4 changes: 2 additions & 2 deletions src/ThriftResourceObject.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand All @@ -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);
}
Expand Down
Loading