mlumish | b892a27 | 2014-12-09 16:28:23 -0800 | [diff] [blame] | 1 | <?php |
mlumish | b892a27 | 2014-12-09 16:28:23 -0800 | [diff] [blame] | 2 | namespace Grpc; |
mlumish | 156e67d | 2015-01-02 14:59:16 -0800 | [diff] [blame] | 3 | require_once realpath(dirname(__FILE__) . '/../autoload.php'); |
mlumish | b892a27 | 2014-12-09 16:28:23 -0800 | [diff] [blame] | 4 | |
| 5 | /** |
| 6 | * Base class for generated client stubs. Stub methods are expected to call |
| 7 | * _simpleRequest or _streamRequest and return the result. |
| 8 | */ |
| 9 | class BaseStub { |
| 10 | |
| 11 | private $channel; |
| 12 | |
murgatroid99 | f21eb25 | 2015-01-30 13:47:41 -0800 | [diff] [blame^] | 13 | public function __construct($hostname, $opts) { |
| 14 | $this->channel = new Channel($hostname, $opts); |
mlumish | b892a27 | 2014-12-09 16:28:23 -0800 | [diff] [blame] | 15 | } |
| 16 | |
| 17 | /** |
| 18 | * Close the communication channel associated with this stub |
| 19 | */ |
| 20 | public function close() { |
| 21 | $channel->close(); |
| 22 | } |
| 23 | |
| 24 | /* This class is intended to be subclassed by generated code, so all functions |
| 25 | begin with "_" to avoid name collisions. */ |
| 26 | |
| 27 | /** |
| 28 | * Call a remote method that takes a single argument and has a single output |
| 29 | * |
| 30 | * @param string $method The name of the method to call |
| 31 | * @param $argument The argument to the method |
| 32 | * @param callable $deserialize A function that deserializes the response |
| 33 | * @param array $metadata A metadata map to send to the server |
| 34 | * @return SimpleSurfaceActiveCall The active call object |
| 35 | */ |
| 36 | protected function _simpleRequest($method, |
| 37 | $argument, |
| 38 | callable $deserialize, |
| 39 | $metadata = array()) { |
| 40 | return new SimpleSurfaceActiveCall($this->channel, |
| 41 | $method, |
| 42 | $deserialize, |
| 43 | $argument, |
| 44 | $metadata); |
| 45 | } |
| 46 | |
| 47 | /** |
| 48 | * Call a remote method that takes a stream of arguments and has a single |
| 49 | * output |
| 50 | * |
| 51 | * @param string $method The name of the method to call |
| 52 | * @param $arguments An array or Traversable of arguments to stream to the |
| 53 | * server |
| 54 | * @param callable $deserialize A function that deserializes the response |
| 55 | * @param array $metadata A metadata map to send to the server |
| 56 | * @return ClientStreamingSurfaceActiveCall The active call object |
| 57 | */ |
| 58 | protected function _clientStreamRequest($method, |
| 59 | $arguments, |
| 60 | callable $deserialize, |
| 61 | $metadata = array()) { |
| 62 | return new ClientStreamingSurfaceActiveCall($this->channel, |
| 63 | $method, |
| 64 | $deserialize, |
| 65 | $arguments, |
| 66 | $metadata); |
| 67 | } |
| 68 | |
| 69 | /** |
| 70 | * Call a remote method that takes a single argument and returns a stream of |
| 71 | * responses |
| 72 | * |
| 73 | * @param string $method The name of the method to call |
| 74 | * @param $argument The argument to the method |
| 75 | * @param callable $deserialize A function that deserializes the responses |
| 76 | * @param array $metadata A metadata map to send to the server |
| 77 | * @return ServerStreamingSurfaceActiveCall The active call object |
| 78 | */ |
| 79 | protected function _serverStreamRequest($method, |
| 80 | $argument, |
| 81 | callable $deserialize, |
| 82 | $metadata = array()) { |
| 83 | return new ServerStreamingSurfaceActiveCall($this->channel, |
| 84 | $method, |
| 85 | $deserialize, |
| 86 | $argument, |
| 87 | $metadata); |
| 88 | } |
| 89 | |
| 90 | /** |
| 91 | * Call a remote method with messages streaming in both directions |
| 92 | * |
| 93 | * @param string $method The name of the method to call |
| 94 | * @param callable $deserialize A function that deserializes the responses |
| 95 | * @param array $metadata A metadata map to send to the server |
| 96 | * @return BidiStreamingSurfaceActiveCall The active call object |
| 97 | */ |
| 98 | protected function _bidiRequest($method, |
| 99 | callable $deserialize, |
| 100 | $metadata = array()) { |
| 101 | return new BidiStreamingSurfaceActiveCall($this->channel, |
| 102 | $method, |
| 103 | $deserialize, |
| 104 | $metadata); |
| 105 | } |
| 106 | } |