|
21 | 21 | use Google\ApiCore\CredentialsWrapper; |
22 | 22 | use Google\ApiCore\Middleware\MiddlewareInterface; |
23 | 23 | use Google\Cloud\Core\LongRunning\LongRunningOperation; |
| 24 | +use Google\Cloud\Core\LongRunning\LongRunningClientConnection; |
24 | 25 | use Google\ApiCore\ValidationException; |
25 | 26 | use Google\Auth\FetchAuthTokenInterface; |
26 | 27 | use Google\Cloud\Core\ClientTrait; |
|
39 | 40 | use Google\Cloud\Spanner\Middleware\SpannerMiddleware; |
40 | 41 | use Google\Cloud\Spanner\Session\SessionPoolInterface; |
41 | 42 | use Google\Cloud\Spanner\V1\Client\SpannerClient as GapicSpannerClient; |
| 43 | +use Google\LongRunning\Operation as OperationProto; |
42 | 44 | use Google\Protobuf\Duration; |
43 | 45 | use Psr\Cache\CacheItemPoolInterface; |
44 | 46 | use Psr\Http\StreamInterface; |
@@ -157,7 +159,7 @@ class SpannerClient |
157 | 159 | * Create a Spanner client. Please note that this client requires |
158 | 160 | * [the gRPC extension](https://cloud.google.com/php/grpc). |
159 | 161 | * |
160 | | - * @param array $config [optional] { |
| 162 | + * @param array $options { |
161 | 163 | * Configuration Options. |
162 | 164 | * |
163 | 165 | * @type string $projectId The Google Cloud project ID. |
@@ -206,63 +208,63 @@ class SpannerClient |
206 | 208 | * } |
207 | 209 | * @throws GoogleException If the gRPC extension is not enabled. |
208 | 210 | */ |
209 | | - public function __construct(array $config = []) |
| 211 | + public function __construct(array $options = []) |
210 | 212 | { |
211 | 213 | $emulatorHost = getenv('SPANNER_EMULATOR_HOST'); |
212 | 214 |
|
213 | 215 | $this->requireGrpc(); |
214 | 216 | $scopes = [self::FULL_CONTROL_SCOPE, self::ADMIN_SCOPE]; |
215 | | - $config += [ |
| 217 | + $options += [ |
216 | 218 | 'returnInt64AsObject' => false, |
217 | 219 | 'projectIdRequired' => true, |
218 | 220 | 'hasEmulator' => (bool) $emulatorHost, |
219 | 221 | 'emulatorHost' => $emulatorHost, |
220 | 222 | 'queryOptions' => [] |
221 | 223 | ]; |
222 | 224 |
|
223 | | - $this->returnInt64AsObject = $config['returnInt64AsObject']; |
224 | | - $this->directedReadOptions = $config['directedReadOptions'] ?? []; |
225 | | - $this->routeToLeader = $config['routeToLeader'] ?? true; |
226 | | - $this->defaultQueryOptions = $config['queryOptions']; |
| 225 | + $this->returnInt64AsObject = $options['returnInt64AsObject']; |
| 226 | + $this->directedReadOptions = $options['directedReadOptions'] ?? []; |
| 227 | + $this->routeToLeader = $options['routeToLeader'] ?? true; |
| 228 | + $this->defaultQueryOptions = $options['queryOptions']; |
227 | 229 |
|
228 | 230 | // Configure GAPIC client options |
229 | | - $config = $this->buildClientOptions($config); |
230 | | - if (isset($config['credentialsConfig']['scopes'])) { |
231 | | - $config['credentialsConfig']['scopes'] = array_merge( |
232 | | - $config['credentialsConfig']['scopes'], |
| 231 | + $options = $this->buildClientOptions($options); |
| 232 | + if (isset($options['credentialsConfig']['scopes'])) { |
| 233 | + $options['credentialsConfig']['scopes'] = array_merge( |
| 234 | + $options['credentialsConfig']['scopes'], |
233 | 235 | $scopes |
234 | 236 | ); |
235 | 237 | } else { |
236 | | - $config['credentialsConfig']['scopes'] = $scopes; |
| 238 | + $options['credentialsConfig']['scopes'] = $scopes; |
237 | 239 | } |
238 | 240 |
|
239 | 241 | if ($emulatorHost) { |
240 | 242 | $emulatorConfig = $this->emulatorGapicConfig($emulatorHost); |
241 | | - $config = array_merge( |
242 | | - $config, |
| 243 | + $options = array_merge( |
| 244 | + $options, |
243 | 245 | $emulatorConfig |
244 | 246 | ); |
245 | 247 | } else { |
246 | | - $config['credentials'] = $this->createCredentialsWrapper( |
247 | | - $config['credentials'], |
248 | | - $config['credentialsConfig'], |
249 | | - $config['universeDomain'] |
| 248 | + $options['credentials'] = $this->createCredentialsWrapper( |
| 249 | + $options['credentials'], |
| 250 | + $options['credentialsConfig'], |
| 251 | + $options['universeDomain'] |
250 | 252 | ); |
251 | 253 | } |
252 | | - $this->projectId = $this->detectProjectId($config); |
| 254 | + $this->projectId = $this->detectProjectId($options); |
253 | 255 | $this->serializer = new Serializer(); |
254 | 256 |
|
255 | 257 | // Adds some defaults |
256 | 258 | // gccl needs to be present for handwritten clients |
257 | | - $clientConfig = $config += [ |
| 259 | + $clientOptions = $options += [ |
258 | 260 | 'libName' => 'gccl', |
259 | 261 | 'serializer' => $this->serializer, |
260 | 262 | ]; |
261 | | - $this->spannerClient = $config['gapicSpannerClient'] ?? new GapicSpannerClient($clientConfig); |
262 | | - $this->instanceAdminClient = $config['gapicSpannerInstanceAdminClient'] |
263 | | - ?? new InstanceAdminClient($clientConfig); |
264 | | - $this->databaseAdminClient = $config['gapicSpannerDatabaseAdminClient'] |
265 | | - ?? new DatabaseAdminClient($clientConfig); |
| 263 | + $this->spannerClient = $options['gapicSpannerClient'] ?? new GapicSpannerClient($clientOptions); |
| 264 | + $this->instanceAdminClient = $options['gapicSpannerInstanceAdminClient'] |
| 265 | + ?? new InstanceAdminClient($clientOptions); |
| 266 | + $this->databaseAdminClient = $options['gapicSpannerDatabaseAdminClient'] |
| 267 | + ?? new DatabaseAdminClient($clientOptions); |
266 | 268 |
|
267 | 269 | // Add the SpannerMiddleware, which wraps API Exceptions, and adds |
268 | 270 | // Resource Prefix and LAR headers |
@@ -499,9 +501,9 @@ public function instanceConfigOperations(array $options = []) |
499 | 501 | [$this->instanceAdminClient, 'listInstanceConfigOperations'], |
500 | 502 | $request, |
501 | 503 | $callOptions + ['resource-prefix' => $this->projectName], |
502 | | - function (Operation $operation) { |
| 504 | + function (OperationProto $operation) { |
503 | 505 | return new LongRunningOperation( |
504 | | - new LongRunningGapicConnection($this->databaseAdminClient, $this->serializer), |
| 506 | + new LongRunningClientConnection($this->databaseAdminClient, $this->serializer), |
505 | 507 | $operation->getName(), |
506 | 508 | [ |
507 | 509 | 'type.googleapis.com/google.spanner.admin.instance.v1.ListInstanceConfigMetadata' => |
@@ -566,13 +568,13 @@ public function instance($name, array $instance = []) |
566 | 568 | $this->serializer, |
567 | 569 | $this->projectId, |
568 | 570 | $name, |
569 | | - $this->returnInt64AsObject, |
570 | | - $instance, |
571 | 571 | [ |
572 | 572 | 'directedReadOptions' => $this->directedReadOptions, |
573 | 573 | 'routeToLeader' => $this->routeToLeader, |
574 | | - 'defaultQueryOptions' => $this->defaultQueryOptions |
575 | | - ] |
| 574 | + 'defaultQueryOptions' => $this->defaultQueryOptions, |
| 575 | + 'returnInt64AsObject' => $this->returnInt64AsObject, |
| 576 | + ], |
| 577 | + $instance, |
576 | 578 | ); |
577 | 579 | } |
578 | 580 |
|
|
0 commit comments