Skip to content
Closed
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
5 changes: 4 additions & 1 deletion src/AgentHeader.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
<?php

declare(strict_types=1);

/*
* Copyright 2016 Google LLC
* All rights reserved.
Expand Down Expand Up @@ -124,7 +127,7 @@ public static function readGapicVersionFromFile(string $callingClass)
$versionFile = substr(
$callingClassFile,
0,
strrpos($callingClassFile, DIRECTORY_SEPARATOR . 'src' . DIRECTORY_SEPARATOR)
strrpos($callingClassFile, DIRECTORY_SEPARATOR . 'src' . DIRECTORY_SEPARATOR) ?: 0
) . DIRECTORY_SEPARATOR . 'VERSION';

return Version::readVersionFile($versionFile);
Expand Down
3 changes: 3 additions & 0 deletions src/ApiException.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
<?php

declare(strict_types=1);

/*
* Copyright 2016 Google LLC
* All rights reserved.
Expand Down
3 changes: 3 additions & 0 deletions src/ApiStatus.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
<?php

declare(strict_types=1);

/*
* Copyright 2017 Google LLC
* All rights reserved.
Expand Down
3 changes: 3 additions & 0 deletions src/ArrayTrait.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
<?php

declare(strict_types=1);

/*
* Copyright 2018 Google LLC
* All rights reserved.
Expand Down
3 changes: 3 additions & 0 deletions src/BidiStream.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
<?php

declare(strict_types=1);

/*
* Copyright 2016 Google LLC
* All rights reserved.
Expand Down
3 changes: 3 additions & 0 deletions src/Call.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
<?php

declare(strict_types=1);

/*
* Copyright 2018 Google LLC
* All rights reserved.
Expand Down
3 changes: 3 additions & 0 deletions src/ClientStream.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
<?php

declare(strict_types=1);

/*
* Copyright 2016 Google LLC
* All rights reserved.
Expand Down
3 changes: 3 additions & 0 deletions src/CredentialsWrapper.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
<?php

declare(strict_types=1);

/*
* Copyright 2018 Google LLC
* All rights reserved.
Expand Down
3 changes: 3 additions & 0 deletions src/FixedSizeCollection.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
<?php

declare(strict_types=1);

/*
* Copyright 2016 Google LLC
* All rights reserved.
Expand Down
3 changes: 3 additions & 0 deletions src/GPBLabel.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
<?php

declare(strict_types=1);

/*
* Copyright 2017 Google LLC
* All rights reserved.
Expand Down
3 changes: 3 additions & 0 deletions src/GPBType.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
<?php

declare(strict_types=1);

/*
* Copyright 2017 Google LLC
* All rights reserved.
Expand Down
77 changes: 40 additions & 37 deletions src/GapicClientTrait.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
<?php

declare(strict_types=1);

/*
* Copyright 2018 Google LLC
* All rights reserved.
Expand Down Expand Up @@ -473,7 +476,7 @@ private function validateCallConfig(string $methodName)
/**
* @param string $methodName
* @param Message $request
* @param array $optionalArgs {
* @param array $callOptions {
* Call Options
*
* @type array $headers [optional] key-value array containing headers
Expand All @@ -489,7 +492,7 @@ private function validateCallConfig(string $methodName)
private function startAsyncCall(
string $methodName,
Message $request,
array $optionalArgs = []
array $callOptions = []
) {
// Convert method name to the UpperCamelCase of RPC names from lowerCamelCase of GAPIC method names
// in order to find the method in the descriptor config.
Expand All @@ -502,7 +505,7 @@ private function startAsyncCall(
case Call::PAGINATED_CALL:
return $this->getPagedListResponseAsync(
$methodName,
$optionalArgs,
$callOptions,
$methodDescriptors['responseType'],
$request,
$methodDescriptors['interfaceOverride'] ?? $this->serviceName
Expand All @@ -514,13 +517,13 @@ private function startAsyncCall(
"'$methodName' is not supported for async execution.");
}

return $this->startApiCall($methodName, $request, $optionalArgs);
return $this->startApiCall($methodName, $request, $callOptions);
}

/**
* @param string $methodName
* @param Message $request
* @param array $optionalArgs {
* @param array $callOptions {
* Call Options
*
* @type array $headers [optional] key-value array containing headers
Expand All @@ -537,7 +540,7 @@ private function startAsyncCall(
private function startApiCall(
string $methodName,
?Message $request = null,
array $optionalArgs = []
array $callOptions = []
) {
$methodDescriptors = $this->validateCallConfig($methodName);
$callType = $methodDescriptors['callType'];
Expand All @@ -546,7 +549,7 @@ private function startApiCall(
// which take precedence.
$headerParams = $methodDescriptors['headerParams'] ?? [];
$requestHeaders = $this->buildRequestParamsHeader($headerParams, $request);
$optionalArgs['headers'] = array_merge($requestHeaders, $optionalArgs['headers'] ?? []);
$callOptions['headers'] = array_merge($requestHeaders, $callOptions['headers'] ?? []);

// Default the interface name, if not set, to the client's protobuf service name.
$interfaceName = $methodDescriptors['interfaceOverride'] ?? $this->serviceName;
Expand All @@ -555,7 +558,7 @@ private function startApiCall(
if ($callType == Call::LONGRUNNING_CALL) {
return $this->startOperationsCall(
$methodName,
$optionalArgs,
$callOptions,
$request,
$this->getOperationsClient(),
$interfaceName,
Expand All @@ -569,17 +572,17 @@ private function startApiCall(
$decodeType = $methodDescriptors['responseType'];

if ($callType == Call::PAGINATED_CALL) {
return $this->getPagedListResponse($methodName, $optionalArgs, $decodeType, $request, $interfaceName);
return $this->getPagedListResponse($methodName, $callOptions, $decodeType, $request, $interfaceName);
}

// Unary, and all Streaming types handled by startCall.
return $this->startCall($methodName, $decodeType, $optionalArgs, $request, $callType, $interfaceName);
return $this->startCall($methodName, $decodeType, $callOptions, $request, $callType, $interfaceName);
}

/**
* @param string $methodName
* @param string $decodeType
* @param array $optionalArgs {
* @param array $callOptions {
* Call Options
*
* @type array $headers [optional] key-value array containing headers
Expand All @@ -597,14 +600,14 @@ private function startApiCall(
private function startCall(
string $methodName,
string $decodeType,
array $optionalArgs = [],
array $callOptions = [],
?Message $request = null,
int $callType = Call::UNARY_CALL,
?string $interfaceName = null
) {
$optionalArgs = $this->configureCallOptions($optionalArgs);
$callOptions = $this->configureCallOptions($callOptions);
$callStack = $this->createCallStack(
$this->configureCallConstructionOptions($methodName, $optionalArgs)
$this->configureCallConstructionOptions($methodName, $callOptions)
);

$descriptor = $this->descriptors[$methodName]['grpcStreaming'] ?? null;
Expand All @@ -627,7 +630,7 @@ private function startCall(
break;
}

return $callStack($call, $optionalArgs + array_filter([
return $callStack($call, $callOptions + array_filter([
'audience' => self::getDefaultAudience()
]));
}
Expand Down Expand Up @@ -689,7 +692,7 @@ private function createCallStack(array $callConstructionOptions)

/**
* @param string $methodName
* @param array $optionalArgs {
* @param array $callOptions {
* Optional arguments
*
* @type RetrySettings|array $retrySettings [optional] A retry settings
Expand All @@ -698,17 +701,17 @@ private function createCallStack(array $callConstructionOptions)
*
* @return array
*/
private function configureCallConstructionOptions(string $methodName, array $optionalArgs)
private function configureCallConstructionOptions(string $methodName, array $callOptions)
{
$retrySettings = $this->retrySettings[$methodName];
$autoPopulatedFields = $this->descriptors[$methodName]['autoPopulatedFields'] ?? [];
// Allow for retry settings to be changed at call time
if (isset($optionalArgs['retrySettings'])) {
if ($optionalArgs['retrySettings'] instanceof RetrySettings) {
$retrySettings = $optionalArgs['retrySettings'];
if (isset($callOptions['retrySettings'])) {
if ($callOptions['retrySettings'] instanceof RetrySettings) {
$retrySettings = $callOptions['retrySettings'];
} else {
$retrySettings = $retrySettings->with(
$optionalArgs['retrySettings']
$callOptions['retrySettings']
);
}
}
Expand All @@ -721,18 +724,18 @@ private function configureCallConstructionOptions(string $methodName, array $opt
/**
* @return array
*/
private function configureCallOptions(array $optionalArgs): array
private function configureCallOptions(array $callOptions): array
{
if ($this->isBackwardsCompatibilityMode()) {
return $optionalArgs;
return $callOptions;
}
// cast to CallOptions for new surfaces only
return (new CallOptions($optionalArgs))->toArray();
return (new CallOptions($callOptions))->toArray();
}

/**
* @param string $methodName
* @param array $optionalArgs {
* @param array $callOptions {
* Call Options
*
* @type array $headers [optional] key-value array containing headers
Expand All @@ -749,15 +752,15 @@ private function configureCallOptions(array $optionalArgs): array
*/
private function startOperationsCall(
string $methodName,
array $optionalArgs,
array $callOptions,
Message $request,
$client,
?string $interfaceName = null,
?string $operationClass = null
) {
$optionalArgs = $this->configureCallOptions($optionalArgs);
$callOptions = $this->configureCallOptions($callOptions);
$callStack = $this->createCallStack(
$this->configureCallConstructionOptions($methodName, $optionalArgs)
$this->configureCallConstructionOptions($methodName, $callOptions)
);
$descriptor = $this->descriptors[$methodName]['longRunning'];
$metadataReturnType = null;
Expand Down Expand Up @@ -788,15 +791,15 @@ private function startOperationsCall(
);

$this->modifyUnaryCallable($callStack);
return $callStack($call, $optionalArgs + array_filter([
return $callStack($call, $callOptions + array_filter([
'metadataReturnType' => $metadataReturnType,
'audience' => self::getDefaultAudience()
]));
}

/**
* @param string $methodName
* @param array $optionalArgs
* @param array $callOptions
* @param string $decodeType
* @param Message $request
* @param string $interfaceName
Expand All @@ -805,14 +808,14 @@ private function startOperationsCall(
*/
private function getPagedListResponse(
string $methodName,
array $optionalArgs,
array $callOptions,
string $decodeType,
Message $request,
?string $interfaceName = null
) {
return $this->getPagedListResponseAsync(
$methodName,
$optionalArgs,
$callOptions,
$decodeType,
$request,
$interfaceName
Expand All @@ -821,7 +824,7 @@ private function getPagedListResponse(

/**
* @param string $methodName
* @param array $optionalArgs
* @param array $callOptions
* @param string $decodeType
* @param Message $request
* @param string $interfaceName
Expand All @@ -830,14 +833,14 @@ private function getPagedListResponse(
*/
private function getPagedListResponseAsync(
string $methodName,
array $optionalArgs,
array $callOptions,
string $decodeType,
Message $request,
?string $interfaceName = null
) {
$optionalArgs = $this->configureCallOptions($optionalArgs);
$callOptions = $this->configureCallOptions($callOptions);
$callStack = $this->createCallStack(
$this->configureCallConstructionOptions($methodName, $optionalArgs)
$this->configureCallConstructionOptions($methodName, $callOptions)
);
$descriptor = new PageStreamingDescriptor(
$this->descriptors[$methodName]['pageStreaming']
Expand All @@ -853,7 +856,7 @@ private function getPagedListResponseAsync(
);

$this->modifyUnaryCallable($callStack);
return $callStack($call, $optionalArgs + array_filter([
return $callStack($call, $callOptions + array_filter([
'audience' => self::getDefaultAudience()
]));
}
Expand Down
3 changes: 3 additions & 0 deletions src/GrpcSupportTrait.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
<?php

declare(strict_types=1);

/*
* Copyright 2018 Google LLC
* All rights reserved.
Expand Down
3 changes: 3 additions & 0 deletions src/Middleware/CredentialsWrapperMiddleware.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
<?php

declare(strict_types=1);

/*
* Copyright 2018 Google LLC
* All rights reserved.
Expand Down
3 changes: 3 additions & 0 deletions src/Middleware/FixedHeaderMiddleware.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
<?php

declare(strict_types=1);

/*
* Copyright 2018 Google LLC
* All rights reserved.
Expand Down
3 changes: 3 additions & 0 deletions src/Middleware/OperationsMiddleware.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
<?php

declare(strict_types=1);

/*
* Copyright 2018 Google LLC
* All rights reserved.
Expand Down
Loading
Loading