Google\Cloud\GrpcRequestWrapper::send PHP Méthode

send() public méthode

Deliver the request.
public send ( callable $request, array $args, array $options = [] ) : array
$request callable The request to execute.
$args array The arguments for the request.
$options array [optional] { Request options. @type int $retries Number of retries for a failed request. **Defaults to** `3`. @type array $grpcOptions gRPC specific configuration options. }
Résultat array
    public function send(callable $request, array $args, array $options = [])
    {
        $retries = isset($options['retries']) ? $options['retries'] : $this->retries;
        $grpcOptions = isset($options['grpcOptions']) ? $options['grpcOptions'] : $this->grpcOptions;
        $backoff = new ExponentialBackoff($retries, function (\Exception $ex) {
            $statusCode = $ex->getCode();
            if (in_array($statusCode, $this->grpcRetryCodes)) {
                return true;
            }
            return false;
        });
        if (!isset($grpcOptions['retrySettings'])) {
            $grpcOptions['retrySettings'] = new RetrySettings(null, null);
        }
        $optionalArgs =& $args[count($args) - 1];
        $optionalArgs += $grpcOptions;
        try {
            return $this->handleResponse($backoff->execute($request, $args));
        } catch (\Exception $ex) {
            throw $this->convertToGoogleException($ex);
        }
    }

Usage Example

 /**
  * @dataProvider exceptionProvider
  */
 public function testCastsToProperException($code, $expectedException)
 {
     $requestWrapper = new GrpcRequestWrapper();
     try {
         $requestWrapper->send(function () use($code) {
             throw new ApiException('message', $code);
         }, [[]], ['retries' => 0]);
     } catch (\Exception $ex) {
         $this->assertInstanceOf($expectedException, $ex);
     }
 }