ApiService.php 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317
  1. <?php
  2. namespace DeverApi;
  3. /**
  4. * Autogenerated by Thrift Compiler (0.10.0)
  5. *
  6. * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING
  7. * @generated
  8. */
  9. use Thrift\Base\TBase;
  10. use Thrift\Type\TType;
  11. use Thrift\Type\TMessageType;
  12. use Thrift\Exception\TException;
  13. use Thrift\Exception\TProtocolException;
  14. use Thrift\Protocol\TProtocol;
  15. use Thrift\Protocol\TBinaryProtocolAccelerated;
  16. use Thrift\Exception\TApplicationException;
  17. interface ApiServiceIf {
  18. /**
  19. * @param string $api
  20. * @param string $param
  21. * @return string
  22. */
  23. public function get($api, $param);
  24. }
  25. class ApiServiceClient implements \DeverApi\ApiServiceIf {
  26. protected $input_ = null;
  27. protected $output_ = null;
  28. protected $seqid_ = 0;
  29. public function __construct($input, $output=null) {
  30. $this->input_ = $input;
  31. $this->output_ = $output ? $output : $input;
  32. }
  33. public function get($api, $param)
  34. {
  35. $this->send_get($api, $param);
  36. return $this->recv_get();
  37. }
  38. public function send_get($api, $param)
  39. {
  40. $args = new \DeverApi\ApiService_get_args();
  41. $args->api = $api;
  42. $args->param = $param;
  43. $bin_accel = ($this->output_ instanceof TBinaryProtocolAccelerated) && function_exists('thrift_protocol_write_binary');
  44. if ($bin_accel)
  45. {
  46. thrift_protocol_write_binary($this->output_, 'get', TMessageType::CALL, $args, $this->seqid_, $this->output_->isStrictWrite());
  47. }
  48. else
  49. {
  50. $this->output_->writeMessageBegin('get', TMessageType::CALL, $this->seqid_);
  51. $args->write($this->output_);
  52. $this->output_->writeMessageEnd();
  53. $this->output_->getTransport()->flush();
  54. }
  55. }
  56. public function recv_get()
  57. {
  58. $bin_accel = ($this->input_ instanceof TBinaryProtocolAccelerated) && function_exists('thrift_protocol_read_binary');
  59. if ($bin_accel) $result = thrift_protocol_read_binary($this->input_, '\DeverApi\ApiService_get_result', $this->input_->isStrictRead());
  60. else
  61. {
  62. $rseqid = 0;
  63. $fname = null;
  64. $mtype = 0;
  65. $this->input_->readMessageBegin($fname, $mtype, $rseqid);
  66. if ($mtype == TMessageType::EXCEPTION) {
  67. $x = new TApplicationException();
  68. $x->read($this->input_);
  69. $this->input_->readMessageEnd();
  70. throw $x;
  71. }
  72. $result = new \DeverApi\ApiService_get_result();
  73. $result->read($this->input_);
  74. $this->input_->readMessageEnd();
  75. }
  76. if ($result->success !== null) {
  77. return $result->success;
  78. }
  79. throw new \Exception("get failed: unknown result");
  80. }
  81. }
  82. // HELPER FUNCTIONS AND STRUCTURES
  83. class ApiService_get_args {
  84. static $_TSPEC;
  85. /**
  86. * @var string
  87. */
  88. public $api = null;
  89. /**
  90. * @var string
  91. */
  92. public $param = null;
  93. public function __construct($vals=null) {
  94. if (!isset(self::$_TSPEC)) {
  95. self::$_TSPEC = array(
  96. 1 => array(
  97. 'var' => 'api',
  98. 'type' => TType::STRING,
  99. ),
  100. 2 => array(
  101. 'var' => 'param',
  102. 'type' => TType::STRING,
  103. ),
  104. );
  105. }
  106. if (is_array($vals)) {
  107. if (isset($vals['api'])) {
  108. $this->api = $vals['api'];
  109. }
  110. if (isset($vals['param'])) {
  111. $this->param = $vals['param'];
  112. }
  113. }
  114. }
  115. public function getName() {
  116. return 'ApiService_get_args';
  117. }
  118. public function read($input)
  119. {
  120. $xfer = 0;
  121. $fname = null;
  122. $ftype = 0;
  123. $fid = 0;
  124. $xfer += $input->readStructBegin($fname);
  125. while (true)
  126. {
  127. $xfer += $input->readFieldBegin($fname, $ftype, $fid);
  128. if ($ftype == TType::STOP) {
  129. break;
  130. }
  131. switch ($fid)
  132. {
  133. case 1:
  134. if ($ftype == TType::STRING) {
  135. $xfer += $input->readString($this->api);
  136. } else {
  137. $xfer += $input->skip($ftype);
  138. }
  139. break;
  140. case 2:
  141. if ($ftype == TType::STRING) {
  142. $xfer += $input->readString($this->param);
  143. } else {
  144. $xfer += $input->skip($ftype);
  145. }
  146. break;
  147. default:
  148. $xfer += $input->skip($ftype);
  149. break;
  150. }
  151. $xfer += $input->readFieldEnd();
  152. }
  153. $xfer += $input->readStructEnd();
  154. return $xfer;
  155. }
  156. public function write($output) {
  157. $xfer = 0;
  158. $xfer += $output->writeStructBegin('ApiService_get_args');
  159. if ($this->api !== null) {
  160. $xfer += $output->writeFieldBegin('api', TType::STRING, 1);
  161. $xfer += $output->writeString($this->api);
  162. $xfer += $output->writeFieldEnd();
  163. }
  164. if ($this->param !== null) {
  165. $xfer += $output->writeFieldBegin('param', TType::STRING, 2);
  166. $xfer += $output->writeString($this->param);
  167. $xfer += $output->writeFieldEnd();
  168. }
  169. $xfer += $output->writeFieldStop();
  170. $xfer += $output->writeStructEnd();
  171. return $xfer;
  172. }
  173. }
  174. class ApiService_get_result {
  175. static $_TSPEC;
  176. /**
  177. * @var string
  178. */
  179. public $success = null;
  180. public function __construct($vals=null) {
  181. if (!isset(self::$_TSPEC)) {
  182. self::$_TSPEC = array(
  183. 0 => array(
  184. 'var' => 'success',
  185. 'type' => TType::STRING,
  186. ),
  187. );
  188. }
  189. if (is_array($vals)) {
  190. if (isset($vals['success'])) {
  191. $this->success = $vals['success'];
  192. }
  193. }
  194. }
  195. public function getName() {
  196. return 'ApiService_get_result';
  197. }
  198. public function read($input)
  199. {
  200. $xfer = 0;
  201. $fname = null;
  202. $ftype = 0;
  203. $fid = 0;
  204. $xfer += $input->readStructBegin($fname);
  205. while (true)
  206. {
  207. $xfer += $input->readFieldBegin($fname, $ftype, $fid);
  208. if ($ftype == TType::STOP) {
  209. break;
  210. }
  211. switch ($fid)
  212. {
  213. case 0:
  214. if ($ftype == TType::STRING) {
  215. $xfer += $input->readString($this->success);
  216. } else {
  217. $xfer += $input->skip($ftype);
  218. }
  219. break;
  220. default:
  221. $xfer += $input->skip($ftype);
  222. break;
  223. }
  224. $xfer += $input->readFieldEnd();
  225. }
  226. $xfer += $input->readStructEnd();
  227. return $xfer;
  228. }
  229. public function write($output) {
  230. $xfer = 0;
  231. $xfer += $output->writeStructBegin('ApiService_get_result');
  232. if ($this->success !== null) {
  233. $xfer += $output->writeFieldBegin('success', TType::STRING, 0);
  234. $xfer += $output->writeString($this->success);
  235. $xfer += $output->writeFieldEnd();
  236. }
  237. $xfer += $output->writeFieldStop();
  238. $xfer += $output->writeStructEnd();
  239. return $xfer;
  240. }
  241. }
  242. class ApiServiceProcessor {
  243. protected $handler_ = null;
  244. public function __construct($handler) {
  245. $this->handler_ = $handler;
  246. }
  247. public function process($input, $output) {
  248. $rseqid = 0;
  249. $fname = null;
  250. $mtype = 0;
  251. $input->readMessageBegin($fname, $mtype, $rseqid);
  252. $methodname = 'process_'.$fname;
  253. if (!method_exists($this, $methodname)) {
  254. $input->skip(TType::STRUCT);
  255. $input->readMessageEnd();
  256. $x = new TApplicationException('Function '.$fname.' not implemented.', TApplicationException::UNKNOWN_METHOD);
  257. $output->writeMessageBegin($fname, TMessageType::EXCEPTION, $rseqid);
  258. $x->write($output);
  259. $output->writeMessageEnd();
  260. $output->getTransport()->flush();
  261. return;
  262. }
  263. $this->$methodname($rseqid, $input, $output);
  264. return true;
  265. }
  266. protected function process_get($seqid, $input, $output) {
  267. $args = new \DeverApi\ApiService_get_args();
  268. $args->read($input);
  269. $input->readMessageEnd();
  270. $result = new \DeverApi\ApiService_get_result();
  271. $result->success = $this->handler_->get($args->api, $args->param);
  272. $bin_accel = ($output instanceof TBinaryProtocolAccelerated) && function_exists('thrift_protocol_write_binary');
  273. if ($bin_accel)
  274. {
  275. thrift_protocol_write_binary($output, 'get', TMessageType::REPLY, $result, $seqid, $output->isStrictWrite());
  276. }
  277. else
  278. {
  279. $output->writeMessageBegin('get', TMessageType::REPLY, $seqid);
  280. $result->write($output);
  281. $output->writeMessageEnd();
  282. $output->getTransport()->flush();
  283. }
  284. }
  285. }