Skip to content

Commit

Permalink
feat!: Spanner V2
Browse files Browse the repository at this point in the history
  • Loading branch information
bshaffer committed Nov 12, 2024
1 parent ca2ba78 commit 1f6b5e4
Show file tree
Hide file tree
Showing 267 changed files with 8,122 additions and 13,038 deletions.
4 changes: 2 additions & 2 deletions Core/src/ApiHelperTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -261,8 +261,8 @@ private function splitOptionalArgs(array $input, array $extraAllowedKeys = []) :
$callOptionFields = array_keys((new CallOptions([]))->toArray());
$keys = array_merge($callOptionFields, $extraAllowedKeys);

$optionalArgs = $this->pluckArray($keys, $input);
$callOptions = $this->pluckArray($keys, $input);

return [$input, $optionalArgs];
return [$input, $callOptions];
}
}
2 changes: 1 addition & 1 deletion Core/src/Iam/Iam.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
*
* use Google\Cloud\Spanner\SpannerClient;
*
* $spanner = new SpannerClient();
* $spanner = new SpannerClient(['projectId' => 'my-project']);
* $instance = $spanner->instance('my-new-instance');
*
* $iam = $instance->iam();
Expand Down
17 changes: 10 additions & 7 deletions Core/src/RequestHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,11 @@ class RequestHandler
*/
private Serializer $serializer;

private array $clients;
private array $clients = [];

/**
* @param Serializer $serializer
* @param array $clientClasses
* @param array<string|object> $clientClasses
* @param array $clientConfig
*/
public function __construct(
Expand All @@ -76,11 +76,14 @@ public function __construct(
);
}
//@codeCoverageIgnoreEnd

// Initialize the client classes and store them in memory
$this->clients = [];
foreach ($clientClasses as $className) {
$this->clients[$className] = new $className($clientConfig);
foreach ($clientClasses as $client) {
if (is_object($client)) {
$this->clients[get_class($client)] = $client;
} else {
$this->clients[$client] = new $client($clientConfig);
}
}
}

Expand Down Expand Up @@ -135,7 +138,7 @@ public function sendRequest(
* @param $clientClass The client class whose object we need.
* @return mixed
*/
private function getClientObject(string $clientClass)
public function getClientObject(string $clientClass)
{
return $this->clients[$clientClass] ?? null;
}
Expand Down
5 changes: 3 additions & 2 deletions Core/src/RequestProcessorTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
use \Google\Protobuf\Internal\Message;
use Google\Rpc\RetryInfo;
use Google\Rpc\BadRequest;
use GuzzleHttp\Promise\PromiseInterface;

/**
* @internal
Expand All @@ -45,7 +46,7 @@ trait RequestProcessorTrait
* Serializes a gRPC response.
*
* @param mixed $response
* @return \Generator|OperationResponse|array|null
* @return \Generator|OperationResponse|array|PromiseInterface|null
*/
private function handleResponse($response)
{
Expand All @@ -57,7 +58,7 @@ private function handleResponse($response)
return $this->serializer->encodeMessage($response);
}

if ($response instanceof OperationResponse) {
if ($response instanceof OperationResponse || $response instanceof PromiseInterface) {
return $response;
}

Expand Down
2 changes: 1 addition & 1 deletion Core/src/ServiceBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ public function pubsub(array $config = [])
*
* Example:
* ```
* $spanner = $cloud->spanner();
* $spanner = $cloud->spanner(['projectId' => 'my-project']);
* ```
*
* @param array $config [optional] {
Expand Down
2 changes: 1 addition & 1 deletion Core/tests/Snippet/Iam/IamManagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class IamManagerTest extends SnippetTestCase
private $policyData;
private $resource;

private $requestHandler;
private $spannerClient;
private $serializer;
private $iam;

Expand Down
3 changes: 2 additions & 1 deletion Core/tests/Snippet/Iam/IamTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

use Google\Cloud\Core\Testing\Snippet\SnippetTestCase;
use Google\Cloud\Core\Iam\Iam;
use Google\Cloud\Core\Iam\IamManager;
use Google\Cloud\Core\Iam\IamConnectionInterface;
use Google\Cloud\Core\Testing\TestHelpers;
use Google\Cloud\Spanner\SpannerClient;
Expand Down Expand Up @@ -55,7 +56,7 @@ public function testClass()
]);
$res = $snippet->invoke('iam');

$this->assertInstanceOf(Iam::class, $res->returnVal());
$this->assertInstanceOf(IamManager::class, $res->returnVal());
}

public function testPolicy()
Expand Down
Loading

0 comments on commit 1f6b5e4

Please sign in to comment.