mlumish | b892a27 | 2014-12-09 16:28:23 -0800 | [diff] [blame] | 1 | <?php |
Craig Tiller | 2e498aa | 2015-02-16 12:09:31 -0800 | [diff] [blame] | 2 | /* |
| 3 | * |
| 4 | * Copyright 2015, Google Inc. |
| 5 | * All rights reserved. |
| 6 | * |
| 7 | * Redistribution and use in source and binary forms, with or without |
| 8 | * modification, are permitted provided that the following conditions are |
| 9 | * met: |
| 10 | * |
| 11 | * * Redistributions of source code must retain the above copyright |
| 12 | * notice, this list of conditions and the following disclaimer. |
| 13 | * * Redistributions in binary form must reproduce the above |
| 14 | * copyright notice, this list of conditions and the following disclaimer |
| 15 | * in the documentation and/or other materials provided with the |
| 16 | * distribution. |
| 17 | * * Neither the name of Google Inc. nor the names of its |
| 18 | * contributors may be used to endorse or promote products derived from |
| 19 | * this software without specific prior written permission. |
| 20 | * |
| 21 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 22 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 23 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 24 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 25 | * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 26 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 27 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 28 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 29 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 30 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 31 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 32 | * |
| 33 | */ |
mlumish | b892a27 | 2014-12-09 16:28:23 -0800 | [diff] [blame] | 34 | namespace Grpc; |
mlumish | 156e67d | 2015-01-02 14:59:16 -0800 | [diff] [blame] | 35 | require_once realpath(dirname(__FILE__) . '/../autoload.php'); |
mlumish | b892a27 | 2014-12-09 16:28:23 -0800 | [diff] [blame] | 36 | |
| 37 | /** |
| 38 | * Base class for generated client stubs. Stub methods are expected to call |
| 39 | * _simpleRequest or _streamRequest and return the result. |
| 40 | */ |
| 41 | class BaseStub { |
| 42 | |
| 43 | private $channel; |
| 44 | |
murgatroid99 | f21eb25 | 2015-01-30 13:47:41 -0800 | [diff] [blame] | 45 | public function __construct($hostname, $opts) { |
| 46 | $this->channel = new Channel($hostname, $opts); |
mlumish | b892a27 | 2014-12-09 16:28:23 -0800 | [diff] [blame] | 47 | } |
| 48 | |
| 49 | /** |
| 50 | * Close the communication channel associated with this stub |
| 51 | */ |
| 52 | public function close() { |
| 53 | $channel->close(); |
| 54 | } |
| 55 | |
| 56 | /* This class is intended to be subclassed by generated code, so all functions |
| 57 | begin with "_" to avoid name collisions. */ |
| 58 | |
| 59 | /** |
| 60 | * Call a remote method that takes a single argument and has a single output |
| 61 | * |
| 62 | * @param string $method The name of the method to call |
| 63 | * @param $argument The argument to the method |
| 64 | * @param callable $deserialize A function that deserializes the response |
| 65 | * @param array $metadata A metadata map to send to the server |
| 66 | * @return SimpleSurfaceActiveCall The active call object |
| 67 | */ |
murgatroid99 | 14d2ce2 | 2015-01-30 15:36:23 -0800 | [diff] [blame] | 68 | public function _simpleRequest($method, |
| 69 | $argument, |
| 70 | callable $deserialize, |
| 71 | $metadata = array()) { |
murgatroid99 | 9140a06 | 2015-03-26 11:27:58 -0700 | [diff] [blame^] | 72 | $call = new UnaryCall($this->channel, $method, $deserialize); |
| 73 | $call->start($argument, $metadata); |
| 74 | return $call; |
mlumish | b892a27 | 2014-12-09 16:28:23 -0800 | [diff] [blame] | 75 | } |
| 76 | |
| 77 | /** |
| 78 | * Call a remote method that takes a stream of arguments and has a single |
| 79 | * output |
| 80 | * |
| 81 | * @param string $method The name of the method to call |
| 82 | * @param $arguments An array or Traversable of arguments to stream to the |
| 83 | * server |
| 84 | * @param callable $deserialize A function that deserializes the response |
| 85 | * @param array $metadata A metadata map to send to the server |
| 86 | * @return ClientStreamingSurfaceActiveCall The active call object |
| 87 | */ |
murgatroid99 | 14d2ce2 | 2015-01-30 15:36:23 -0800 | [diff] [blame] | 88 | public function _clientStreamRequest($method, |
| 89 | $arguments, |
| 90 | callable $deserialize, |
| 91 | $metadata = array()) { |
murgatroid99 | 9140a06 | 2015-03-26 11:27:58 -0700 | [diff] [blame^] | 92 | $call = new ClientStreamingCall($this->channel, $method, $deserialize); |
| 93 | $call->start($arguments, $metadata); |
| 94 | return $call; |
mlumish | b892a27 | 2014-12-09 16:28:23 -0800 | [diff] [blame] | 95 | } |
| 96 | |
| 97 | /** |
| 98 | * Call a remote method that takes a single argument and returns a stream of |
| 99 | * responses |
| 100 | * |
| 101 | * @param string $method The name of the method to call |
| 102 | * @param $argument The argument to the method |
| 103 | * @param callable $deserialize A function that deserializes the responses |
| 104 | * @param array $metadata A metadata map to send to the server |
| 105 | * @return ServerStreamingSurfaceActiveCall The active call object |
| 106 | */ |
murgatroid99 | 14d2ce2 | 2015-01-30 15:36:23 -0800 | [diff] [blame] | 107 | public function _serverStreamRequest($method, |
| 108 | $argument, |
| 109 | callable $deserialize, |
| 110 | $metadata = array()) { |
murgatroid99 | 9140a06 | 2015-03-26 11:27:58 -0700 | [diff] [blame^] | 111 | $call = new ServerStreamingCall($this->channel, $method, $deserialize); |
| 112 | $call->start($argument, $metadata); |
| 113 | return $call; |
mlumish | b892a27 | 2014-12-09 16:28:23 -0800 | [diff] [blame] | 114 | } |
| 115 | |
| 116 | /** |
| 117 | * Call a remote method with messages streaming in both directions |
| 118 | * |
| 119 | * @param string $method The name of the method to call |
| 120 | * @param callable $deserialize A function that deserializes the responses |
| 121 | * @param array $metadata A metadata map to send to the server |
| 122 | * @return BidiStreamingSurfaceActiveCall The active call object |
| 123 | */ |
murgatroid99 | 14d2ce2 | 2015-01-30 15:36:23 -0800 | [diff] [blame] | 124 | public function _bidiRequest($method, |
| 125 | callable $deserialize, |
| 126 | $metadata = array()) { |
murgatroid99 | 9140a06 | 2015-03-26 11:27:58 -0700 | [diff] [blame^] | 127 | $call = new BidiStreamingCall($this->channel, $method, $deserialize); |
| 128 | $call->start($metadata); |
| 129 | return $call; |
mlumish | b892a27 | 2014-12-09 16:28:23 -0800 | [diff] [blame] | 130 | } |
| 131 | } |