| 1 |
<?php |
| 2 |
|
| 3 |
/* |
| 4 |
* |
| 5 |
* Copyright 2018 gRPC authors. |
| 6 |
* |
| 7 |
* Licensed under the Apache License, Version 2.0 (the "License"); |
| 8 |
* you may not use this file except in compliance with the License. |
| 9 |
* You may obtain a copy of the License at |
| 10 |
* |
| 11 |
* http://www.apache.org/licenses/LICENSE-2.0 |
| 12 |
* |
| 13 |
* Unless required by applicable law or agreed to in writing, software |
| 14 |
* distributed under the License is distributed on an "AS IS" BASIS, |
| 15 |
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 16 |
* See the License for the specific language governing permissions and |
| 17 |
* limitations under the License. |
| 18 |
* |
| 19 |
*/ |
| 20 |
namespace Dudlewebs\WPMCS\Grpc\Gcp; |
| 21 |
|
| 22 |
/** |
| 23 |
* Represents an active call that sends a single message and then gets a |
| 24 |
* single response. |
| 25 |
*/ |
| 26 |
class GCPUnaryCall extends GcpBaseCall |
| 27 |
{ |
| 28 |
protected function createRealCall($channel) |
| 29 |
{ |
| 30 |
$this->real_call = new \Dudlewebs\WPMCS\Grpc\UnaryCall($channel, $this->method, $this->deserialize, $this->options); |
| 31 |
$this->has_real_call = \true; |
| 32 |
return $this->real_call; |
| 33 |
} |
| 34 |
/** |
| 35 |
* Pick a channel and start the call. |
| 36 |
* |
| 37 |
* @param mixed $data The data to send |
| 38 |
* @param array $metadata Metadata to send with the call, if applicable |
| 39 |
* (optional) |
| 40 |
* @param array $options An array of options, possible keys: |
| 41 |
* 'flags' => a number (optional) |
| 42 |
*/ |
| 43 |
public function start($argument, $metadata, $options) |
| 44 |
{ |
| 45 |
$channel_ref = $this->_rpcPreProcess($argument); |
| 46 |
$real_channel = $channel_ref->getRealChannel($this->gcp_channel->credentials); |
| 47 |
$this->createRealCall($real_channel); |
| 48 |
$this->real_call->start($argument, $metadata, $options); |
| 49 |
} |
| 50 |
/** |
| 51 |
* Wait for the server to respond with data and a status. |
| 52 |
* |
| 53 |
* @return array [response data, status] |
| 54 |
*/ |
| 55 |
public function wait() |
| 56 |
{ |
| 57 |
list($response, $status) = $this->real_call->wait(); |
| 58 |
$this->_rpcPostProcess($status, $response); |
| 59 |
return [$response, $status]; |
| 60 |
} |
| 61 |
/** |
| 62 |
* @return mixed The metadata sent by the server |
| 63 |
*/ |
| 64 |
public function getMetadata() |
| 65 |
{ |
| 66 |
return $this->real_call->getMetadata(); |
| 67 |
} |
| 68 |
} |
| 69 |
|