/examples/thrift/packages/moodle_message/moodle_message.php
https://bitbucket.org/hhteam/moodle_thrift_tools · PHP · 364 lines · 327 code · 30 blank · 7 comment · 42 complexity · a15b7b9209045b709db64ee01a37ee31 MD5 · raw file
- <?php
- namespace moodle_message;
- /**
- * Autogenerated by Thrift Compiler (0.9.0-dev)
- *
- * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING
- * @generated
- */
- use Thrift\Base\TBase;
- use Thrift\Type\TType;
- use Thrift\Type\TMessageType;
- use Thrift\Exception\TException;
- use Thrift\Exception\TProtocolException;
- use Thrift\Protocol\TProtocol;
- use Thrift\Exception\TApplicationException;
- interface moodle_messageIf {
- public function send_instantmessages($messages);
- }
- class moodle_messageClient implements \moodle_message\moodle_messageIf {
- protected $input_ = null;
- protected $output_ = null;
- protected $seqid_ = 0;
- public function __construct($input, $output=null) {
- $this->input_ = $input;
- $this->output_ = $output ? $output : $input;
- }
- public function send_instantmessages($messages)
- {
- $this->send_send_instantmessages($messages);
- return $this->recv_send_instantmessages();
- }
- public function send_send_instantmessages($messages)
- {
- $args = new \moodle_message\moodle_message_send_instantmessages_args();
- $args->messages = $messages;
- $bin_accel = ($this->output_ instanceof TProtocol::$TBINARYPROTOCOLACCELERATED) && function_exists('thrift_protocol_write_binary');
- if ($bin_accel)
- {
- thrift_protocol_write_binary($this->output_, 'send_instantmessages', TMessageType::CALL, $args, $this->seqid_, $this->output_->isStrictWrite());
- }
- else
- {
- $this->output_->writeMessageBegin('send_instantmessages', TMessageType::CALL, $this->seqid_);
- $args->write($this->output_);
- $this->output_->writeMessageEnd();
- $this->output_->getTransport()->flush();
- }
- }
- public function recv_send_instantmessages()
- {
- $bin_accel = ($this->input_ instanceof TProtocol::$TBINARYPROTOCOLACCELERATED) && function_exists('thrift_protocol_read_binary');
- if ($bin_accel) $result = thrift_protocol_read_binary($this->input_, '\moodle_message\moodle_message_send_instantmessages_result', $this->input_->isStrictRead());
- else
- {
- $rseqid = 0;
- $fname = null;
- $mtype = 0;
- $this->input_->readMessageBegin($fname, $mtype, $rseqid);
- if ($mtype == TMessageType::EXCEPTION) {
- $x = new TApplicationException();
- $x->read($this->input_);
- $this->input_->readMessageEnd();
- throw $x;
- }
- $result = new \moodle_message\moodle_message_send_instantmessages_result();
- $result->read($this->input_);
- $this->input_->readMessageEnd();
- }
- if ($result->success !== null) {
- return $result->success;
- }
- if ($result->error !== null) {
- throw $result->error;
- }
- throw new \Exception("send_instantmessages failed: unknown result");
- }
- }
- // HELPER FUNCTIONS AND STRUCTURES
- class moodle_message_send_instantmessages_args {
- static $_TSPEC;
- public $messages = null;
- public function __construct($vals=null) {
- if (!isset(self::$_TSPEC)) {
- self::$_TSPEC = array(
- 1 => array(
- 'var' => 'messages',
- 'type' => TType::LST,
- 'etype' => TType::STRUCT,
- 'elem' => array(
- 'type' => TType::STRUCT,
- 'class' => '\moodle_message\SendInstantmessagesArgsStruct',
- ),
- ),
- );
- }
- if (is_array($vals)) {
- if (isset($vals['messages'])) {
- $this->messages = $vals['messages'];
- }
- }
- }
- public function getName() {
- return 'moodle_message_send_instantmessages_args';
- }
- public function read($input)
- {
- $xfer = 0;
- $fname = null;
- $ftype = 0;
- $fid = 0;
- $xfer += $input->readStructBegin($fname);
- while (true)
- {
- $xfer += $input->readFieldBegin($fname, $ftype, $fid);
- if ($ftype == TType::STOP) {
- break;
- }
- switch ($fid)
- {
- case 1:
- if ($ftype == TType::LST) {
- $this->messages = array();
- $_size9 = 0;
- $_etype12 = 0;
- $xfer += $input->readListBegin($_etype12, $_size9);
- for ($_i13 = 0; $_i13 < $_size9; ++$_i13)
- {
- $elem14 = null;
- $elem14 = new \moodle_message\SendInstantmessagesArgsStruct();
- $xfer += $elem14->read($input);
- $this->messages []= $elem14;
- }
- $xfer += $input->readListEnd();
- } else {
- $xfer += $input->skip($ftype);
- }
- break;
- default:
- $xfer += $input->skip($ftype);
- break;
- }
- $xfer += $input->readFieldEnd();
- }
- $xfer += $input->readStructEnd();
- return $xfer;
- }
- public function write($output) {
- $xfer = 0;
- $xfer += $output->writeStructBegin('moodle_message_send_instantmessages_args');
- if ($this->messages !== null) {
- if (!is_array($this->messages)) {
- throw new TProtocolException('Bad type in structure.', TProtocolException::INVALID_DATA);
- }
- $xfer += $output->writeFieldBegin('messages', TType::LST, 1);
- {
- $output->writeListBegin(TType::STRUCT, count($this->messages));
- {
- foreach ($this->messages as $iter15)
- {
- $xfer += $iter15->write($output);
- }
- }
- $output->writeListEnd();
- }
- $xfer += $output->writeFieldEnd();
- }
- $xfer += $output->writeFieldStop();
- $xfer += $output->writeStructEnd();
- return $xfer;
- }
- }
- class moodle_message_send_instantmessages_result {
- static $_TSPEC;
- public $success = null;
- public $error = null;
- public function __construct($vals=null) {
- if (!isset(self::$_TSPEC)) {
- self::$_TSPEC = array(
- 0 => array(
- 'var' => 'success',
- 'type' => TType::LST,
- 'etype' => TType::STRUCT,
- 'elem' => array(
- 'type' => TType::STRUCT,
- 'class' => '\moodle_message\SendInstantmessagesRetStruct',
- ),
- ),
- 1 => array(
- 'var' => 'error',
- 'type' => TType::STRUCT,
- 'class' => '\moodle_message\ApiError',
- ),
- );
- }
- if (is_array($vals)) {
- if (isset($vals['success'])) {
- $this->success = $vals['success'];
- }
- if (isset($vals['error'])) {
- $this->error = $vals['error'];
- }
- }
- }
- public function getName() {
- return 'moodle_message_send_instantmessages_result';
- }
- public function read($input)
- {
- $xfer = 0;
- $fname = null;
- $ftype = 0;
- $fid = 0;
- $xfer += $input->readStructBegin($fname);
- while (true)
- {
- $xfer += $input->readFieldBegin($fname, $ftype, $fid);
- if ($ftype == TType::STOP) {
- break;
- }
- switch ($fid)
- {
- case 0:
- if ($ftype == TType::LST) {
- $this->success = array();
- $_size16 = 0;
- $_etype19 = 0;
- $xfer += $input->readListBegin($_etype19, $_size16);
- for ($_i20 = 0; $_i20 < $_size16; ++$_i20)
- {
- $elem21 = null;
- $elem21 = new \moodle_message\SendInstantmessagesRetStruct();
- $xfer += $elem21->read($input);
- $this->success []= $elem21;
- }
- $xfer += $input->readListEnd();
- } else {
- $xfer += $input->skip($ftype);
- }
- break;
- case 1:
- if ($ftype == TType::STRUCT) {
- $this->error = new \moodle_message\ApiError();
- $xfer += $this->error->read($input);
- } else {
- $xfer += $input->skip($ftype);
- }
- break;
- default:
- $xfer += $input->skip($ftype);
- break;
- }
- $xfer += $input->readFieldEnd();
- }
- $xfer += $input->readStructEnd();
- return $xfer;
- }
- public function write($output) {
- $xfer = 0;
- $xfer += $output->writeStructBegin('moodle_message_send_instantmessages_result');
- if ($this->success !== null) {
- if (!is_array($this->success)) {
- throw new TProtocolException('Bad type in structure.', TProtocolException::INVALID_DATA);
- }
- $xfer += $output->writeFieldBegin('success', TType::LST, 0);
- {
- $output->writeListBegin(TType::STRUCT, count($this->success));
- {
- foreach ($this->success as $iter22)
- {
- $xfer += $iter22->write($output);
- }
- }
- $output->writeListEnd();
- }
- $xfer += $output->writeFieldEnd();
- }
- if ($this->error !== null) {
- $xfer += $output->writeFieldBegin('error', TType::STRUCT, 1);
- $xfer += $this->error->write($output);
- $xfer += $output->writeFieldEnd();
- }
- $xfer += $output->writeFieldStop();
- $xfer += $output->writeStructEnd();
- return $xfer;
- }
- }
- class moodle_messageProcessor {
- protected $handler_ = null;
- public function __construct($handler) {
- $this->handler_ = $handler;
- }
- public function process($input, $output) {
- $rseqid = 0;
- $fname = null;
- $mtype = 0;
- $input->readMessageBegin($fname, $mtype, $rseqid);
- $methodname = 'process_'.$fname;
- if (!method_exists($this, $methodname)) {
- $input->skip(TType::STRUCT);
- $input->readMessageEnd();
- $x = new TApplicationException('Function '.$fname.' not implemented.', TApplicationException::UNKNOWN_METHOD);
- $output->writeMessageBegin($fname, TMessageType::EXCEPTION, $rseqid);
- $x->write($output);
- $output->writeMessageEnd();
- $output->getTransport()->flush();
- return;
- }
- $this->$methodname($rseqid, $input, $output);
- return true;
- }
- protected function process_send_instantmessages($seqid, $input, $output) {
- $args = new \moodle_message\moodle_message_send_instantmessages_args();
- $args->read($input);
- $input->readMessageEnd();
- $result = new \moodle_message\moodle_message_send_instantmessages_result();
- try {
- $result->success = $this->handler_->send_instantmessages($args->messages);
- } catch (\moodle_message\ApiError $error) {
- $result->error = $error;
- }
- $bin_accel = ($output instanceof TProtocol::$TBINARYPROTOCOLACCELERATED) && function_exists('thrift_protocol_write_binary');
- if ($bin_accel)
- {
- thrift_protocol_write_binary($output, 'send_instantmessages', TMessageType::REPLY, $result, $seqid, $output->isStrictWrite());
- }
- else
- {
- $output->writeMessageBegin('send_instantmessages', TMessageType::REPLY, $seqid);
- $result->write($output);
- $output->writeMessageEnd();
- $output->getTransport()->flush();
- }
- }
- }