GCPUnaryCall.php 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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. * Represents an active call that sends a single message and then gets a
  22. * single response.
  23. */
  24. class GCPUnaryCall extends GcpBaseCall
  25. {
  26. protected function createRealCall($channel)
  27. {
  28. $this->real_call = new \Grpc\UnaryCall($channel, $this->method, $this->deserialize, $this->options);
  29. $this->has_real_call = true;
  30. return $this->real_call;
  31. }
  32. /**
  33. * Pick a channel and start the call.
  34. *
  35. * @param mixed $data The data to send
  36. * @param array $metadata Metadata to send with the call, if applicable
  37. * (optional)
  38. * @param array $options An array of options, possible keys:
  39. * 'flags' => a number (optional)
  40. */
  41. public function start($argument, $metadata, $options)
  42. {
  43. $channel_ref = $this->_rpcPreProcess($argument);
  44. $real_channel = $channel_ref->getRealChannel($this->gcp_channel->credentials);
  45. $this->createRealCall($real_channel);
  46. $this->real_call->start($argument, $metadata, $options);
  47. }
  48. /**
  49. * Wait for the server to respond with data and a status.
  50. *
  51. * @return array [response data, status]
  52. */
  53. public function wait()
  54. {
  55. list($response, $status) = $this->real_call->wait();
  56. $this->_rpcPostProcess($status, $response);
  57. return [$response, $status];
  58. }
  59. /**
  60. * @return mixed The metadata sent by the server
  61. */
  62. public function getMetadata()
  63. {
  64. return $this->real_call->getMetadata();
  65. }
  66. }