googleanalytics
/
lib
/
analytics-admin
/
vendor
/
google
/
grpc-gcp
/
src
/
GCPServerStreamCall.php
generated
3 years ago
ChannelRef.php
3 years ago
Config.php
3 years ago
CreatedByDeserializeCheck.php
3 years ago
GCPBidiStreamingCall.php
3 years ago
GCPCallInvoker.php
3 years ago
GCPClientStreamCall.php
3 years ago
GCPServerStreamCall.php
3 years ago
GCPUnaryCall.php
3 years ago
GcpBaseCall.php
3 years ago
GcpExtensionChannel.php
3 years ago
grpc_gcp.proto
3 years ago
GCPServerStreamCall.php
90 lines
| 1 | <?php |
| 2 | /* |
| 3 | * |
| 4 | * Copyright 2018 gRPC authors. |
| 5 | * |
| 6 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 7 | * you may not use this file except in compliance with the License. |
| 8 | * You may obtain a copy of the License at |
| 9 | * |
| 10 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | * |
| 12 | * Unless required by applicable law or agreed to in writing, software |
| 13 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 15 | * See the License for the specific language governing permissions and |
| 16 | * limitations under the License. |
| 17 | * |
| 18 | */ |
| 19 | namespace Grpc\Gcp; |
| 20 | |
| 21 | /** |
| 22 | * Represents an active call that sends a single message and then gets a |
| 23 | * stream of responses. |
| 24 | */ |
| 25 | class GCPServerStreamCall extends GcpBaseCall |
| 26 | { |
| 27 | private $response = null; |
| 28 | |
| 29 | protected function createRealCall($channel) |
| 30 | { |
| 31 | $this->real_call = new \Grpc\ServerStreamingCall($channel, $this->method, $this->deserialize, $this->options); |
| 32 | $this->has_real_call = true; |
| 33 | return $this->real_call; |
| 34 | } |
| 35 | |
| 36 | /** |
| 37 | * Pick a channel and start the call. |
| 38 | * |
| 39 | * @param mixed $data The data to send |
| 40 | * @param array $metadata Metadata to send with the call, if applicable |
| 41 | * (optional) |
| 42 | * @param array $options An array of options, possible keys: |
| 43 | * 'flags' => a number (optional) |
| 44 | */ |
| 45 | public function start($argument, $metadata, $options) |
| 46 | { |
| 47 | $channel_ref = $this->_rpcPreProcess($argument); |
| 48 | $this->createRealCall($channel_ref->getRealChannel( |
| 49 | $this->gcp_channel->credentials)); |
| 50 | $this->real_call->start($argument, $metadata, $options); |
| 51 | } |
| 52 | |
| 53 | /** |
| 54 | * @return mixed An iterator of response values |
| 55 | */ |
| 56 | public function responses() |
| 57 | { |
| 58 | $response = $this->real_call->responses(); |
| 59 | // Since the last response is empty for the server streaming RPC, |
| 60 | // the second last one is the last RPC response with payload. |
| 61 | // Use this one for searching the affinity key. |
| 62 | // The same as BidiStreaming. |
| 63 | if ($response) { |
| 64 | $this->response = $response; |
| 65 | } |
| 66 | return $response; |
| 67 | } |
| 68 | |
| 69 | /** |
| 70 | * Wait for the server to send the status, and return it. |
| 71 | * |
| 72 | * @return \stdClass The status object, with integer $code, string |
| 73 | * $details, and array $metadata members |
| 74 | */ |
| 75 | public function getStatus() |
| 76 | { |
| 77 | $status = $this->real_call->getStatus(); |
| 78 | $this->_rpcPostProcess($status, $this->response); |
| 79 | return $status; |
| 80 | } |
| 81 | |
| 82 | /** |
| 83 | * @return mixed The metadata sent by the server |
| 84 | */ |
| 85 | public function getMetadata() |
| 86 | { |
| 87 | return $this->real_call->getMetadata(); |
| 88 | } |
| 89 | } |
| 90 |