call = $serverStreamingCall; if (array_key_exists('resourcesGetMethod', $streamingDescriptor)) { $this->resourcesGetMethod = $streamingDescriptor['resourcesGetMethod']; } $this->logger = $logger; } /** * A generator which yields results from the server until the streaming call * completes. Throws an ApiException if the streaming call failed. * * @throws ApiException * @return \Generator|mixed */ public function readAll() { $resourcesGetMethod = $this->resourcesGetMethod; foreach ($this->call->responses() as $response) { if ($this->logger && $response instanceof Message) { $responseEvent = new RpcLogEvent(); $responseEvent->payload = $response->serializeToJsonString(); $responseEvent->processId = (int) getmypid(); $responseEvent->requestId = crc32((string) spl_object_id($this) . getmypid()); $this->logResponse($responseEvent); } if (!is_null($resourcesGetMethod)) { foreach ($response->$resourcesGetMethod() as $resource) { yield $resource; } } else { yield $response; } } // Errors in the REST transport will be thrown from there and not reach // this handling. Successful REST server-streams will have an OK status. $status = $this->call->getStatus(); if ($this->logger) { $statusEvent = new RpcLogEvent(); $statusEvent->status = $status->code; $statusEvent->processId = (int) getmypid(); $statusEvent->requestId = crc32((string) spl_object_id($this) . getmypid()); $this->logResponse($statusEvent); } if ($status->code !== Code::OK) { throw ApiException::createFromStdClass($status); } } /** * Return the underlying call object. * * @return ServerStreamingCallInterface */ public function getServerStreamingCall() { return $this->call; } }