コード例 #1
0
 function inputFilter($data, stdClass $context)
 {
     if ($data !== "" && ($data[0] === '[' || $data[0] === '{')) {
         try {
             $requests = json_decode($data);
         } catch (Exception $e) {
             return $data;
         }
         if ($data[0] === '{') {
             $requests = array($requests);
         } else {
             if (count($requests) === 0) {
                 return $data;
             }
         }
         $stream = new BytesIO();
         $writer = new Writer($stream, true);
         $context->userdata->jsonrpc = array();
         foreach ($requests as $request) {
             $jsonrpc = new stdClass();
             if (isset($request->id)) {
                 $jsonrpc->id = $request->id;
             } else {
                 $jsonrpc->id = null;
             }
             if (isset($request->version)) {
                 $jsonrpc->version = $request->version;
             } else {
                 if (isset($request->jsonrpc)) {
                     $jsonrpc->version = $request->jsonrpc;
                 } else {
                     $jsonrpc->version = '1.0';
                 }
             }
             $context->userdata->jsonrpc[] = $jsonrpc;
             if (isset($request->method)) {
                 $stream->write(Tags::TagCall);
                 $writer->writeString($request->method);
                 if (isset($request->params) && count($request->params) > 0) {
                     $writer->writeArray($request->params);
                 }
             } else {
                 unset($context->userdata->jsonrpc);
                 return $data;
             }
         }
         $stream->write(Tags::TagEnd);
         $data = $stream->toString();
         unset($stream);
         unset($writer);
     }
     return $data;
 }
コード例 #2
0
ファイル: ClientFilter.php プロジェクト: wanggeopens/own-libs
 public function inputFilter($data, stdClass $context)
 {
     $result = xmlrpc_decode($data, "UTF-8");
     $stream = new BytesIO();
     $writer = new Writer($stream, true);
     if (isset($result['faultString'])) {
         $stream->write(Tags::TagError);
         $writer->writeString($result['faultString']);
     } else {
         $stream->write(Tags::TagResult);
         $writer->serialize($result);
     }
     $stream->write(Tags::TagEnd);
     return $stream->toString();
 }
コード例 #3
0
 public function inputFilter($data, stdClass $context)
 {
     if ($data !== "" && $data[0] === '<') {
         $context->userdata->format = "xmlrpc";
         $method = null;
         $params = xmlrpc_decode_request($data, $method, "UTF-8");
         $stream = new BytesIO();
         $writer = new Writer($stream, true);
         if (isset($method)) {
             $stream->write(Tags::TagCall);
             $writer->writeString($method);
             if (isset($params)) {
                 $writer->writeArray($params);
             }
         }
         $stream->write(Tags::TagEnd);
         $data = $stream->toString();
     }
     return $data;
 }
コード例 #4
0
ファイル: ClientFilter.php プロジェクト: wanggeopens/own-libs
 public function inputFilter($data, stdClass $context)
 {
     $response = json_decode($data);
     if (!isset($response->result)) {
         $response->result = null;
     }
     if (!isset($response->error)) {
         $response->error = null;
     }
     $stream = new BytesIO();
     $writer = new Writer($stream, true);
     if ($response->error) {
         $stream->write(Tags::TagError);
         $writer->writeString($response->error->message);
     } else {
         $stream->write(Tags::TagResult);
         $writer->serialize($response->result);
     }
     $stream->write(Tags::TagEnd);
     return $stream->toString();
 }
コード例 #5
0
ファイル: Service.php プロジェクト: hprose/hprose-php
 function sendError($error, stdClass $context)
 {
     if (is_string($error)) {
         $error = new Exception($error);
     }
     try {
         if ($this->onSendError !== null) {
             $onSendError = $this->onSendError;
             $e = call_user_func_array($onSendError, array(&$error, $context));
             if ($e instanceof Exception || $e instanceof Throwable) {
                 $error = $e;
             }
         }
     } catch (Exception $e) {
         $error = $e;
     }
     $stream = new BytesIO();
     $writer = new Writer($stream, true);
     $stream->write(Tags::TagError);
     $writer->writeString($this->debug ? $error->getTraceAsString() : $error->getMessage());
     return $stream;
 }
コード例 #6
0
ファイル: Client.php プロジェクト: wanggeopens/own-libs
 private function encode($name, array $args, stdClass $context)
 {
     $stream = new BytesIO(Tags::TagCall);
     $writer = new Writer($stream, $context->simple);
     $writer->writeString($name);
     if (count($args) > 0 || $context->byref) {
         $writer->reset();
         $writer->writeArray($args);
         if ($context->byref) {
             $writer->writeBoolean(true);
         }
     }
     $stream->write(Tags::TagEnd);
     $request = $stream->toString();
     $stream->close();
     return $request;
 }