예제 #1
0
 function inputFilter($data, $context)
 {
     if ($data !== "" && $data[0] === '{') {
         $context->userdata->format = "jsonrpc";
         $request = json_decode($data);
         if (isset($request->id)) {
             $context->userdata->id = $request->id;
         } else {
             $context->userdata->id = null;
         }
         if (isset($request->version)) {
             $context->userdata->version = $request->version;
         } else {
             if (isset($request->jsonrpc)) {
                 $context->userdata->version = $request->jsonrpc;
             } else {
                 $context->userdata->version = "1.0";
             }
         }
         $stream = new \Hprose\BytesIO();
         $writer = new \Hprose\Writer($stream, true);
         if (isset($request->method)) {
             $stream->write(\Hprose\Tags::TagCall);
             $writer->writeString($request->method);
             if (isset($request->params)) {
                 $writer->writeArray($request->params);
             }
         }
         $stream->write(\Hprose\Tags::TagEnd);
         $data = $stream->toString();
         unset($stream);
         unset($writer);
     }
     return $data;
 }
예제 #2
0
 function inputFilter($data, $context)
 {
     $response = json_decode($data);
     if (!isset($response->result)) {
         $response->result = null;
     }
     if (!isset($response->error)) {
         $response->error = null;
     }
     $stream = new \Hprose\BytesIO();
     $writer = new \Hprose\Writer($stream, true);
     if ($response->error) {
         $stream->write(\Hprose\Tags::TagError);
         $writer->writeString($response->error->message);
     } else {
         $stream->write(\Hprose\Tags::TagResult);
         $writer->serialize($response->result);
     }
     $stream->write(\Hprose\Tags::TagEnd);
     $data = $stream->toString();
     unset($response);
     unset($writer);
     unset($stream);
     return $data;
 }
예제 #3
0
 function inputFilter($data, $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 \Hprose\BytesIO();
         $writer = new \Hprose\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(\Hprose\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(\Hprose\Tags::TagEnd);
         $data = $stream->toString();
         unset($stream);
         unset($writer);
     }
     return $data;
 }
예제 #4
0
 function inputFilter($data, $context)
 {
     $result = xmlrpc_decode($data, "UTF-8");
     $stream = new \Hprose\BytesIO();
     $writer = new \Hprose\Writer($stream, true);
     if (isset($result['faultString'])) {
         $stream->write(\Hprose\Tags::TagError);
         $writer->writeString($result['faultString']);
     } else {
         $stream->write(\Hprose\Tags::TagResult);
         $writer->serialize($result);
     }
     $stream->write(\Hprose\Tags::TagEnd);
     $data = $stream->toString();
     unset($result);
     unset($writer);
     unset($stream);
     return $data;
 }
예제 #5
0
 function inputFilter($data, $context)
 {
     if ($data !== "" && $data[0] === '<') {
         $context->userdata->format = "xmlrpc";
         $method = null;
         $params = xmlrpc_decode_request($data, $method, "UTF-8");
         $stream = new \Hprose\BytesIO();
         $writer = new \Hprose\Writer($stream, true);
         if (isset($method)) {
             $stream->write(\Hprose\Tags::TagCall);
             $writer->writeString($method);
             if (isset($params)) {
                 $writer->writeArray($params);
             }
         }
         $stream->write(\Hprose\Tags::TagEnd);
         $data = $stream->toString();
         unset($stream);
         unset($writer);
     }
     return $data;
 }