PluginProbe
Media Cloud Sync / 1.4.2
Media Cloud Sync v1.4.2
1.4.2 1.4.1 1.4.0 1.3.12 1.3.11 1.3.10 trunk 1.0.0 1.0.1 1.0.2 1.0.3 1.1.0 1.1.1 1.2.0 1.2.10 1.2.11 1.2.12 1.2.13 1.2.2 1.2.3 1.2.4 1.2.5 1.2.6 1.2.7 1.2.8 All 36 releases
← All changes | includes/sdk/google/google/gax/src/GapicClientTrait.php +125 -64 1.2.0 → 1.4.2 View file →
@@ -29,28 +29,30 @@
29 29 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30 30 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31 31 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 32 */
33 -namespace Dudlewebs\WPMCS\Google\ApiCore;
33 +namespace Dudlewebs\WPMCS\GCP\Google\ApiCore;
34 34
35 -use Dudlewebs\WPMCS\Google\ApiCore\LongRunning\OperationsClient;
36 -use Dudlewebs\WPMCS\Google\ApiCore\Middleware\CredentialsWrapperMiddleware;
37 -use Dudlewebs\WPMCS\Google\ApiCore\Middleware\FixedHeaderMiddleware;
38 -use Dudlewebs\WPMCS\Google\ApiCore\Middleware\OperationsMiddleware;
39 -use Dudlewebs\WPMCS\Google\ApiCore\Middleware\OptionsFilterMiddleware;
40 -use Dudlewebs\WPMCS\Google\ApiCore\Middleware\PagedMiddleware;
41 -use Dudlewebs\WPMCS\Google\ApiCore\Middleware\RetryMiddleware;
42 -use Dudlewebs\WPMCS\Google\ApiCore\Options\CallOptions;
43 -use Dudlewebs\WPMCS\Google\ApiCore\Options\ClientOptions;
44 -use Dudlewebs\WPMCS\Google\ApiCore\Options\TransportOptions;
45 -use Dudlewebs\WPMCS\Google\ApiCore\Transport\GrpcFallbackTransport;
46 -use Dudlewebs\WPMCS\Google\ApiCore\Transport\GrpcTransport;
47 -use Dudlewebs\WPMCS\Google\ApiCore\Transport\RestTransport;
48 -use Dudlewebs\WPMCS\Google\ApiCore\Transport\TransportInterface;
49 -use Dudlewebs\WPMCS\Google\Auth\FetchAuthTokenInterface;
50 -use Dudlewebs\WPMCS\Google\LongRunning\Operation;
51 -use Dudlewebs\WPMCS\Google\Protobuf\Internal\Message;
52 -use Dudlewebs\WPMCS\GuzzleHttp\Promise\PromiseInterface;
35 +use Dudlewebs\WPMCS\GCP\Google\ApiCore\LongRunning\OperationsClient;
36 +use Dudlewebs\WPMCS\GCP\Google\ApiCore\Middleware\CredentialsWrapperMiddleware;
37 +use Dudlewebs\WPMCS\GCP\Google\ApiCore\Middleware\FixedHeaderMiddleware;
38 +use Dudlewebs\WPMCS\GCP\Google\ApiCore\Middleware\OperationsMiddleware;
39 +use Dudlewebs\WPMCS\GCP\Google\ApiCore\Middleware\OptionsFilterMiddleware;
40 +use Dudlewebs\WPMCS\GCP\Google\ApiCore\Middleware\PagedMiddleware;
41 +use Dudlewebs\WPMCS\GCP\Google\ApiCore\Middleware\RequestAutoPopulationMiddleware;
42 +use Dudlewebs\WPMCS\GCP\Google\ApiCore\Middleware\RetryMiddleware;
43 +use Dudlewebs\WPMCS\GCP\Google\ApiCore\Middleware\TransportCallMiddleware;
44 +use Dudlewebs\WPMCS\GCP\Google\ApiCore\Options\CallOptions;
45 +use Dudlewebs\WPMCS\GCP\Google\ApiCore\Options\ClientOptions;
46 +use Dudlewebs\WPMCS\GCP\Google\ApiCore\Options\TransportOptions;
47 +use Dudlewebs\WPMCS\GCP\Google\ApiCore\Transport\GrpcFallbackTransport;
48 +use Dudlewebs\WPMCS\GCP\Google\ApiCore\Transport\GrpcTransport;
49 +use Dudlewebs\WPMCS\GCP\Google\ApiCore\Transport\RestTransport;
50 +use Dudlewebs\WPMCS\GCP\Google\ApiCore\Transport\TransportInterface;
51 +use Dudlewebs\WPMCS\GCP\Google\Auth\FetchAuthTokenInterface;
52 +use Dudlewebs\WPMCS\GCP\Google\LongRunning\Operation;
53 +use Dudlewebs\WPMCS\GCP\Google\Protobuf\Internal\Message;
54 +use Dudlewebs\WPMCS\GCP\GuzzleHttp\Promise\PromiseInterface;
53 55 /**
54 56 * Common functions used to work with various clients.
55 57 *
56 58 * @internal
@@ -62,14 +64,16 @@
62 64 ValidationTrait::validate as traitValidate;
63 65 }
64 66 use GrpcSupportTrait;
65 67 private ?TransportInterface $transport = null;
66 - private ?CredentialsWrapper $credentialsWrapper = null;
68 + private ?HeaderCredentialsInterface $credentialsWrapper = null;
67 69 /** @var RetrySettings[] $retrySettings */
68 70 private array $retrySettings = [];
69 71 private string $serviceName = '';
70 72 private array $agentHeader = [];
71 73 private array $descriptors = [];
74 + /** @var array<callable> $prependMiddlewareCallables */
75 + private array $prependMiddlewareCallables = [];
72 76 /** @var array<callable> $middlewareCallables */
73 77 private array $middlewareCallables = [];
74 78 private array $transportCallMethods = [Call::UNARY_CALL => 'startUnaryCall', Call::BIDI_STREAMING_CALL => 'startBidiStreamingCall', Call::CLIENT_STREAMING_CALL => 'startClientStreamingCall', Call::SERVER_STREAMING_CALL => 'startServerStreamingCall'];
75 79 private bool $backwardsCompatibilityMode;
@@ -103,13 +107,48 @@
103 107 * of {@see MiddlewareInterface} when invoked with a
104 108 * MiddlewareInterface instance as its first argument.
105 109 * @return void
106 110 */
107 - public function addMiddleware(callable $middlewareCallable): void
111 + public function addMiddleware(callable $middlewareCallable) : void
108 112 {
109 113 $this->middlewareCallables[] = $middlewareCallable;
110 114 }
111 115 /**
116 + * Prepend a middleware to the call stack by providing a callable which will be
117 + * invoked at the end of each call, and will return an instance of
118 + * {@see MiddlewareInterface} when invoked.
119 + *
120 + * The callable must have the following method signature:
121 + *
122 + * callable(MiddlewareInterface): MiddlewareInterface
123 + *
124 + * An implementation may look something like this:
125 + * ```
126 + * $client->prependMiddleware(function (MiddlewareInterface $handler) {
127 + * return new class ($handler) implements MiddlewareInterface {
128 + * public function __construct(private MiddlewareInterface $handler) {
129 + * }
130 + *
131 + * public function __invoke(Call $call, array $options) {
132 + * // modify call and options (pre-request)
133 + * $response = ($this->handler)($call, $options);
134 + * // modify the response (post-request)
135 + * return $response;
136 + * }
137 + * };
138 + * });
139 + * ```
140 + *
141 + * @param callable $middlewareCallable A callable which returns an instance
142 + * of {@see MiddlewareInterface} when invoked with a
143 + * MiddlewareInterface instance as its first argument.
144 + * @return void
145 + */
146 + public function prependMiddleware(callable $middlewareCallable) : void
147 + {
148 + $this->prependMiddlewareCallables[] = $middlewareCallable;
149 + }
150 + /**
112 151 * Initiates an orderly shutdown in which preexisting calls continue but new
113 152 * calls are immediately cancelled.
114 153 *
115 154 * @experimental
@@ -208,15 +247,20 @@
208 247 // serviceAddress is now deprecated and acts as an alias for apiEndpoint
209 248 if (isset($options['serviceAddress'])) {
210 249 $options['apiEndpoint'] = $this->pluck('serviceAddress', $options, \false);
211 250 }
212 - $this->validateNotNull($options, ['apiEndpoint', 'serviceName', 'descriptorsConfigPath', 'clientConfig', 'disableRetries', 'credentialsConfig', 'transportConfig']);
213 - $this->traitValidate($options, ['credentials', 'transport', 'gapicVersion', 'libName', 'libVersion']);
251 + self::validateNotNull($options, ['apiEndpoint', 'serviceName', 'descriptorsConfigPath', 'clientConfig', 'disableRetries', 'credentialsConfig', 'transportConfig']);
252 + self::traitValidate($options, ['credentials', 'transport', 'gapicVersion', 'libName', 'libVersion']);
253 + // "hasEmulator" is not a supported Client Option, but is used
254 + // internally to determine if the client is running in emulator mode.
255 + // Therefore, we need to remove it from the $options array before
256 + // creating the ClientOptions.
257 + $hasEmulator = $this->pluck('hasEmulator', $options, \false) ?? \false;
214 258 if ($this->isBackwardsCompatibilityMode()) {
215 - if (is_string($options['clientConfig'])) {
259 + if (\is_string($options['clientConfig'])) {
216 260 // perform validation for V1 surfaces which is done in the
217 261 // ClientOptions class for v2 surfaces.
218 - $options['clientConfig'] = json_decode(file_get_contents($options['clientConfig']), \true);
262 + $options['clientConfig'] = \json_decode(\file_get_contents($options['clientConfig']), \true);
219 263 self::validateFileExists($options['descriptorsConfigPath']);
220 264 }
221 265 } else {
222 266 // cast to ClientOptions for new surfaces only
@@ -227,22 +271,30 @@
227 271 $headerInfo = ['libName' => $options['libName'], 'libVersion' => $options['libVersion'], 'gapicVersion' => $options['gapicVersion']];
228 272 // Edge case: If the client has the gRPC extension installed, but is
229 273 // a REST-only library, then the grpcVersion header should not be set.
230 274 if ($this->transport instanceof GrpcTransport) {
231 - $headerInfo['grpcVersion'] = phpversion('grpc');
275 + $headerInfo['grpcVersion'] = \phpversion('grpc');
232 276 } elseif ($this->transport instanceof RestTransport || $this->transport instanceof GrpcFallbackTransport) {
233 277 $headerInfo['restVersion'] = Version::getApiCoreVersion();
234 278 }
235 279 $this->agentHeader = AgentHeader::buildAgentHeader($headerInfo);
236 280 // Set "client_library_name" depending on client library surface being used
237 - $userAgentHeader = sprintf('gcloud-php-%s/%s', $this->isBackwardsCompatibilityMode() ? 'legacy' : 'new', $options['gapicVersion']);
281 + $userAgentHeader = \sprintf('gcloud-php-%s/%s', $this->isBackwardsCompatibilityMode() ? 'legacy' : 'new', $options['gapicVersion']);
238 282 $this->agentHeader['User-Agent'] = [$userAgentHeader];
239 283 self::validateFileExists($options['descriptorsConfigPath']);
240 - $descriptors = require $options['descriptorsConfigPath'];
284 + $descriptors = (require $options['descriptorsConfigPath']);
241 285 $this->descriptors = $descriptors['interfaces'][$this->serviceName];
242 - $this->credentialsWrapper = $this->createCredentialsWrapper($options['credentials'], $options['credentialsConfig'], $options['universeDomain']);
286 + if (isset($options['apiKey'], $options['credentials'])) {
287 + throw new ValidationException('API Keys and Credentials are mutually exclusive authentication methods and cannot be used together.');
288 + }
289 + // Set the credentialsWrapper
290 + if (isset($options['apiKey'])) {
291 + $this->credentialsWrapper = new ApiKeyHeaderCredentials($options['apiKey'], $options['credentialsConfig']['quotaProject'] ?? null);
292 + } else {
293 + $this->credentialsWrapper = $this->createCredentialsWrapper($options['credentials'], $options['credentialsConfig'], $options['universeDomain']);
294 + }
243 295 $transport = $options['transport'] ?: self::defaultTransport();
244 - $this->transport = $transport instanceof TransportInterface ? $transport : $this->createTransport($options['apiEndpoint'], $transport, $options['transportConfig'], $options['clientCertSource']);
296 + $this->transport = $transport instanceof TransportInterface ? $transport : $this->createTransport($options['apiEndpoint'], $transport, $options['transportConfig'], $options['clientCertSource'], $hasEmulator);
245 297 }
246 298 /**
247 299 * @param string $apiEndpoint
248 300 * @param string $transport
@@ -247,22 +299,23 @@
247 299 * @param string $apiEndpoint
248 300 * @param string $transport
249 301 * @param TransportOptions|array $transportConfig
250 302 * @param callable $clientCertSource
303 + * @param bool $hasEmulator
251 304 * @return TransportInterface
252 305 * @throws ValidationException
253 306 */
254 - private function createTransport(string $apiEndpoint, $transport, $transportConfig, callable $clientCertSource = null)
307 + private function createTransport(string $apiEndpoint, $transport, $transportConfig, ?callable $clientCertSource = null, bool $hasEmulator = \false)
255 308 {
256 - if (!is_string($transport)) {
257 - throw new ValidationException("'transport' must be a string, instead got:" . print_r($transport, \true));
309 + if (!\is_string($transport)) {
310 + throw new ValidationException("'transport' must be a string, instead got:" . \print_r($transport, \true));
258 311 }
259 312 $supportedTransports = self::supportedTransports();
260 - if (!in_array($transport, $supportedTransports)) {
261 - throw new ValidationException(sprintf('Unexpected transport option "%s". Supported transports: %s', $transport, implode(', ', $supportedTransports)));
313 + if (!\in_array($transport, $supportedTransports)) {
314 + throw new ValidationException(\sprintf('Unexpected transport option "%s". Supported transports: %s', $transport, \implode(', ', $supportedTransports)));
262 315 }
263 316 $configForSpecifiedTransport = $transportConfig[$transport] ?? [];
264 - if (is_array($configForSpecifiedTransport)) {
317 + if (\is_array($configForSpecifiedTransport)) {
265 318 $configForSpecifiedTransport['clientCertSource'] = $clientCertSource;
266 319 } else {
267 320 $configForSpecifiedTransport->setClientCertSource($clientCertSource);
268 321 $configForSpecifiedTransport = $configForSpecifiedTransport->toArray();
@@ -283,8 +336,9 @@
283 336 if (!isset($configForSpecifiedTransport['restClientConfigPath'])) {
284 337 throw new ValidationException("The 'restClientConfigPath' config is required for 'rest' transport.");
285 338 }
286 339 $restConfigPath = $configForSpecifiedTransport['restClientConfigPath'];
340 + $configForSpecifiedTransport['hasEmulator'] = $hasEmulator;
287 341 return RestTransport::build($apiEndpoint, $restConfigPath, $configForSpecifiedTransport);
288 342 default:
289 343 throw new ValidationException("Unexpected 'transport' option: {$transport}. " . "Supported values: ['grpc', 'rest', 'grpc-fallback']");
290 344 }
@@ -328,9 +382,9 @@
328 382 if (!isset($methodDescriptors['longRunning'])) {
329 383 throw new ValidationException("Requested method '{$methodName}' does not have a longRunning config " . 'in descriptor configuration.');
330 384 }
331 385 // @TODO: check if the client implements `OperationsClientInterface` instead
332 - if (!method_exists($this, 'getOperationsClient')) {
386 + if (!\method_exists($this, 'getOperationsClient')) {
333 387 throw new ValidationException('Client missing required getOperationsClient ' . "for longrunning call '{$methodName}'");
334 388 }
335 389 } elseif ($callType == Call::PAGINATED_CALL) {
336 390 if (!isset($methodDescriptors['pageStreaming'])) {
@@ -365,9 +419,9 @@
365 419 private function startAsyncCall(string $methodName, Message $request, array $optionalArgs = [])
366 420 {
367 421 // Convert method name to the UpperCamelCase of RPC names from lowerCamelCase of GAPIC method names
368 422 // in order to find the method in the descriptor config.
369 - $methodName = ucfirst($methodName);
423 + $methodName = \ucfirst($methodName);
370 424 $methodDescriptors = $this->validateCallConfig($methodName);
371 425 $callType = $methodDescriptors['callType'];
372 426 switch ($callType) {
373 427 case Call::PAGINATED_CALL:
@@ -395,9 +449,9 @@
395 449 * @experimental
396 450 *
397 451 * @return PromiseInterface|PagedListResponse|BidiStream|ClientStream|ServerStream
398 452 */
399 - private function startApiCall(string $methodName, Message $request = null, array $optionalArgs = [])
453 + private function startApiCall(string $methodName, ?Message $request = null, array $optionalArgs = [])
400 454 {
401 455 $methodDescriptors = $this->validateCallConfig($methodName);
402 456 $callType = $methodDescriptors['callType'];
403 457 // Prepare request-based headers, merge with user-provided headers,
@@ -403,9 +457,9 @@
403 457 // Prepare request-based headers, merge with user-provided headers,
404 458 // which take precedence.
405 459 $headerParams = $methodDescriptors['headerParams'] ?? [];
406 460 $requestHeaders = $this->buildRequestParamsHeader($headerParams, $request);
407 - $optionalArgs['headers'] = array_merge($requestHeaders, $optionalArgs['headers'] ?? []);
461 + $optionalArgs['headers'] = \array_merge($requestHeaders, $optionalArgs['headers'] ?? []);
408 462 // Default the interface name, if not set, to the client's protobuf service name.
409 463 $interfaceName = $methodDescriptors['interfaceOverride'] ?? $this->serviceName;
410 464 // Handle call based on call type configured in the method descriptor config.
411 465 if ($callType == Call::LONGRUNNING_CALL) {
@@ -445,9 +499,9 @@
445 499 * @param string $interfaceName
446 500 *
447 501 * @return PromiseInterface|BidiStream|ClientStream|ServerStream
448 502 */
449 - private function startCall(string $methodName, string $decodeType, array $optionalArgs = [], Message $request = null, int $callType = Call::UNARY_CALL, string $interfaceName = null)
503 + private function startCall(string $methodName, string $decodeType, array $optionalArgs = [], ?Message $request = null, int $callType = Call::UNARY_CALL, ?string $interfaceName = null)
450 504 {
451 505 $optionalArgs = $this->configureCallOptions($optionalArgs);
452 506 $callStack = $this->createCallStack($this->configureCallConstructionOptions($methodName, $optionalArgs));
453 507 $descriptor = $this->descriptors[$methodName]['grpcStreaming'] ?? null;
@@ -461,9 +515,9 @@
461 515 case Call::SERVER_STREAMING_CALL:
462 516 $this->modifyStreamingCallable($callStack);
463 517 break;
464 518 }
465 - return $callStack($call, $optionalArgs + array_filter(['audience' => self::getDefaultAudience()]));
519 + return $callStack($call, $optionalArgs + \array_filter(['audience' => self::getDefaultAudience()]));
466 520 }
467 521 /**
468 522 * @param array $callConstructionOptions {
469 523 * Call Construction Options
@@ -469,8 +523,10 @@
469 523 * Call Construction Options
470 524 *
471 525 * @type RetrySettings $retrySettings [optional] A retry settings override
472 526 * For the call.
527 + * @type array<string, string> $autoPopulationSettings Settings for
528 + * auto population of particular request fields if unset.
473 529 * }
474 530 *
475 531 * @return callable
476 532 */
@@ -475,20 +531,24 @@
475 531 * @return callable
476 532 */
477 533 private function createCallStack(array $callConstructionOptions)
478 534 {
479 - $quotaProject = $this->credentialsWrapper->getQuotaProject();
480 535 $fixedHeaders = $this->agentHeader;
481 - if ($quotaProject) {
536 + if ($quotaProject = $this->credentialsWrapper->getQuotaProject()) {
482 537 $fixedHeaders += ['X-Goog-User-Project' => [$quotaProject]];
483 538 }
484 - $callStack = function (Call $call, array $options) {
485 - $startCallMethod = $this->transportCallMethods[$call->getCallType()];
486 - return $this->transport->{$startCallMethod}($call, $options);
487 - };
539 + if (isset($this->apiVersion)) {
540 + $fixedHeaders += ['X-Goog-Api-Version' => [$this->apiVersion]];
541 + }
542 + $callStack = new TransportCallMiddleware($this->transport, $this->transportCallMethods);
543 + foreach ($this->prependMiddlewareCallables as $fn) {
544 + /** @var MiddlewareInterface $callStack */
545 + $callStack = $fn($callStack);
546 + }
488 547 $callStack = new CredentialsWrapperMiddleware($callStack, $this->credentialsWrapper);
489 548 $callStack = new FixedHeaderMiddleware($callStack, $fixedHeaders, \true);
490 549 $callStack = new RetryMiddleware($callStack, $callConstructionOptions['retrySettings']);
550 + $callStack = new RequestAutoPopulationMiddleware($callStack, $callConstructionOptions['autoPopulationSettings']);
491 551 $callStack = new OptionsFilterMiddleware($callStack, ['headers', 'timeoutMillis', 'transportOptions', 'metadataCallback', 'audience', 'metadataReturnType']);
492 552 foreach (\array_reverse($this->middlewareCallables) as $fn) {
493 553 /** @var MiddlewareInterface $callStack */
494 554 $callStack = $fn($callStack);
@@ -508,8 +568,9 @@
508 568 */
509 569 private function configureCallConstructionOptions(string $methodName, array $optionalArgs)
510 570 {
511 571 $retrySettings = $this->retrySettings[$methodName];
572 + $autoPopulatedFields = $this->descriptors[$methodName]['autoPopulatedFields'] ?? [];
512 573 // Allow for retry settings to be changed at call time
513 574 if (isset($optionalArgs['retrySettings'])) {
514 575 if ($optionalArgs['retrySettings'] instanceof RetrySettings) {
515 576 $retrySettings = $optionalArgs['retrySettings'];
@@ -516,14 +577,14 @@
516 577 } else {
517 578 $retrySettings = $retrySettings->with($optionalArgs['retrySettings']);
518 579 }
519 580 }
520 - return ['retrySettings' => $retrySettings];
581 + return ['retrySettings' => $retrySettings, 'autoPopulationSettings' => $autoPopulatedFields];
521 582 }
522 583 /**
523 584 * @return array
524 585 */
525 - private function configureCallOptions(array $optionalArgs): array
586 + private function configureCallOptions(array $optionalArgs) : array
526 587 {
527 588 if ($this->isBackwardsCompatibilityMode()) {
528 589 return $optionalArgs;
529 590 }
@@ -546,9 +607,9 @@
546 607 * operation response class of {@see \Google\LongRunning\Operation}.
547 608 *
548 609 * @return PromiseInterface
549 610 */
550 - private function startOperationsCall(string $methodName, array $optionalArgs, Message $request, $client, string $interfaceName = null, string $operationClass = null)
611 + private function startOperationsCall(string $methodName, array $optionalArgs, Message $request, $client, ?string $interfaceName = null, ?string $operationClass = null)
551 612 {
552 613 $optionalArgs = $this->configureCallOptions($optionalArgs);
553 614 $callStack = $this->createCallStack($this->configureCallConstructionOptions($methodName, $optionalArgs));
554 615 $descriptor = $this->descriptors[$methodName]['longRunning'];
@@ -568,9 +629,9 @@
568 629 }
569 630 $callStack = new OperationsMiddleware($callStack, $client, $descriptor);
570 631 $call = new Call($this->buildMethod($interfaceName, $methodName), $operationClass ?: Operation::class, $request, [], Call::UNARY_CALL);
571 632 $this->modifyUnaryCallable($callStack);
572 - return $callStack($call, $optionalArgs + array_filter(['metadataReturnType' => $metadataReturnType, 'audience' => self::getDefaultAudience()]));
633 + return $callStack($call, $optionalArgs + \array_filter(['metadataReturnType' => $metadataReturnType, 'audience' => self::getDefaultAudience()]));
573 634 }
574 635 /**
575 636 * @param string $methodName
576 637 * @param array $optionalArgs
@@ -579,9 +640,9 @@
579 640 * @param string $interfaceName
580 641 *
581 642 * @return PagedListResponse
582 643 */
583 - private function getPagedListResponse(string $methodName, array $optionalArgs, string $decodeType, Message $request, string $interfaceName = null)
644 + private function getPagedListResponse(string $methodName, array $optionalArgs, string $decodeType, Message $request, ?string $interfaceName = null)
584 645 {
585 646 return $this->getPagedListResponseAsync($methodName, $optionalArgs, $decodeType, $request, $interfaceName)->wait();
586 647 }
587 648 /**
@@ -592,9 +653,9 @@
592 653 * @param string $interfaceName
593 654 *
594 655 * @return PromiseInterface
595 656 */
596 - private function getPagedListResponseAsync(string $methodName, array $optionalArgs, string $decodeType, Message $request, string $interfaceName = null)
657 + private function getPagedListResponseAsync(string $methodName, array $optionalArgs, string $decodeType, Message $request, ?string $interfaceName = null)
597 658 {
598 659 $optionalArgs = $this->configureCallOptions($optionalArgs);
599 660 $callStack = $this->createCallStack($this->configureCallConstructionOptions($methodName, $optionalArgs));
600 661 $descriptor = new PageStreamingDescriptor($this->descriptors[$methodName]['pageStreaming']);
@@ -600,9 +661,9 @@
600 661 $descriptor = new PageStreamingDescriptor($this->descriptors[$methodName]['pageStreaming']);
601 662 $callStack = new PagedMiddleware($callStack, $descriptor);
602 663 $call = new Call($this->buildMethod($interfaceName, $methodName), $decodeType, $request, [], Call::UNARY_CALL);
603 664 $this->modifyUnaryCallable($callStack);
604 - return $callStack($call, $optionalArgs + array_filter(['audience' => self::getDefaultAudience()]));
665 + return $callStack($call, $optionalArgs + \array_filter(['audience' => self::getDefaultAudience()]));
605 666 }
606 667 /**
607 668 * @param string $interfaceName
608 669 * @param string $methodName
@@ -608,11 +669,11 @@
608 669 * @param string $methodName
609 670 *
610 671 * @return string
611 672 */
612 - private function buildMethod(string $interfaceName = null, string $methodName = null)
673 + private function buildMethod(?string $interfaceName = null, ?string $methodName = null)
613 674 {
614 - return sprintf('%s/%s', $interfaceName ?: $this->serviceName, $methodName);
675 + return \sprintf('%s/%s', $interfaceName ?: $this->serviceName, $methodName);
615 676 }
616 677 /**
617 678 * @param array $headerParams
618 679 * @param Message|null $request
@@ -618,9 +679,9 @@
618 679 * @param Message|null $request
619 680 *
620 681 * @return array
621 682 */
622 - private function buildRequestParamsHeader(array $headerParams, Message $request = null)
683 + private function buildRequestParamsHeader(array $headerParams, ?Message $request = null)
623 684 {
624 685 $headers = [];
625 686 // No request message means no request-based headers.
626 687 if (!$request) {
@@ -633,9 +694,9 @@
633 694 $value = $msg->{$accessor}();
634 695 // In case the field in question is nested in another message,
635 696 // skip the header param when the nested message field is unset.
636 697 $msg = $value;
637 - if (is_null($msg)) {
698 + if (\is_null($msg)) {
638 699 break;
639 700 }
640 701 }
641 702 $keyName = $headerParam['keyName'];
@@ -642,12 +703,12 @@
642 703 // If there are value pattern matchers configured and the target
643 704 // field was set, evaluate the matchers in the order that they were
644 705 // annotated in with last one matching wins.
645 706 $original = $value;
646 - $matchers = isset($headerParam['matchers']) && !is_null($value) ? $headerParam['matchers'] : [];
707 + $matchers = isset($headerParam['matchers']) && !\is_null($value) ? $headerParam['matchers'] : [];
647 708 foreach ($matchers as $matcher) {
648 709 $matches = [];
649 - if (preg_match($matcher, $original, $matches)) {
710 + if (\preg_match($matcher, $original, $matches)) {
650 711 $value = $matches[$keyName];
651 712 }
652 713 }
653 714 // If there are no matches or the target field was unset, skip this
@@ -664,9 +725,9 @@
664 725 * The SERVICE_ADDRESS constant is set by GAPIC clients
665 726 */
666 727 private static function getDefaultAudience()
667 728 {
668 - if (!defined('self::SERVICE_ADDRESS')) {
729 + if (!\defined('self::SERVICE_ADDRESS')) {
669 730 return null;
670 731 }
671 732 return 'https://' . self::SERVICE_ADDRESS . '/';
672 733 // @phpstan-ignore-line
@@ -693,9 +754,9 @@
693 754 }
694 755 /**
695 756 * @internal
696 757 */
697 - private function isBackwardsCompatibilityMode(): bool
758 + private function isBackwardsCompatibilityMode() : bool
698 759 {
699 - return $this->backwardsCompatibilityMode ?? $this->backwardsCompatibilityMode = substr(__CLASS__, -11) === 'GapicClient';
760 + return $this->backwardsCompatibilityMode ?? ($this->backwardsCompatibilityMode = \substr(__CLASS__, -11) === 'GapicClient');
700 761 }
701 762 }