getLastProtoResponse(); if (is_null($response)) { return null; } $response = $serializer->encodeMessage($response); $result = null; if ($operation->isDone()) { $type = $response['metadata']['typeUrl']; $result = $this->deserializeResult($operation, $type, $serializer, $lroMappers); } $error = $operation->getError(); if (!is_null($error)) { $error = $serializer->encodeMessage($error); } $response['response'] = $result; $response['error'] = $error; return $response; } /** * Fetch an OperationResponse object from a gapic client. * * @param mixed $client A generated client with a `resumeOperation` method. * @param string $name The Operation name. * @param string|null $method The method name. * @return OperationResponse */ private function getOperationByName($client, $name, $method = null) { return $client->resumeOperation($name, $method); } /** * Convert an operation response to an array * * @param OperationResponse|GaxOperationResponse $operation The operation to * serialize. * @param string $type The Operation type. The type should correspond to a * member of $mappers.typeUrl. * @param Serializer|GaxSerializer $serializer The gRPC serializer to use * for the deserialization. * @param array $mappers A list of mappers. * @return array|null */ private function deserializeResult($operation, $type, $serializer, array $mappers) { $mappers = array_filter($mappers, function ($mapper) use($type) { return $mapper['typeUrl'] === $type; }); if (count($mappers) === 0) { throw new \RuntimeException(sprintf('No mapper exists for operation response type %s.', $type)); } $mapper = current($mappers); $message = $mapper['message']; $response = new $message(); $anyResponse = $operation->getLastProtoResponse()->getResponse(); if (is_null($anyResponse)) { return null; } $response->mergeFromString($anyResponse->getValue()); return $serializer->encodeMessage($response); } }