Ejemplo n.º 1
0
 function outputFilter($data, $context)
 {
     if (isset($context->userdata->format) && $context->userdata->format === "xmlrpc") {
         $result = null;
         if ($data !== "") {
             $stream = new \Hprose\BytesIO($data);
             $reader = new \Hprose\Reader($stream);
             while (($tag = $stream->getc()) !== \Hprose\Tags::TagEnd) {
                 $reader->reset();
                 switch ($tag) {
                     case \Hprose\Tags::TagResult:
                         $result = $reader->unserialize();
                         break;
                     case \Hprose\Tags::TagError:
                         $lasterror = error_get_last();
                         $result = array("faultCode" => $lasterror["type"], "faultString" => $reader->unserialize());
                         break;
                     case \Hprose\Tags::TagFunctions:
                         $result = $reader->unserialize();
                         break;
                     default:
                         return xmlrpc_encode($result);
                         break;
                 }
             }
         }
         $data = xmlrpc_encode($result);
     }
     return $data;
 }
Ejemplo n.º 2
0
 function outputFilter($data, $context)
 {
     $request = new \stdClass();
     if ($this->version === "1.1") {
         $request->version = "1.1";
     } else {
         if ($this->version === "2.0") {
             $request->jsonrpc = "2.0";
         }
     }
     $stream = new \Hprose\BytesIO($data);
     $reader = new \Hprose\Reader($stream);
     $tag = $stream->getc();
     if ($tag === \Hprose\Tags::TagCall) {
         $request->method = $reader->readString();
         $tag = $stream->getc();
         if ($tag == \Hprose\Tags::TagList) {
             $reader->reset();
             $request->params = $reader->readListWithoutTag();
         }
     } else {
         throw new \Exception("Error Processing Request", 1);
     }
     unset($reader);
     unset($stream);
     $request->id = self::$id++;
     return json_encode($request);
 }
Ejemplo n.º 3
0
 function outputFilter($data, $context)
 {
     $method = null;
     $params = array();
     $stream = new \Hprose\BytesIO($data);
     $reader = new \Hprose\Reader($stream);
     $tag = $stream->getc();
     if ($tag === \Hprose\Tags::TagCall) {
         $method = $reader->readString();
         $tag = $stream->getc();
         if ($tag == \Hprose\Tags::TagList) {
             $reader->reset();
             $params = $reader->readListWithoutTag();
         }
     } else {
         throw new \Exception("Error Processing Request", 1);
     }
     unset($reader);
     unset($stream);
     return xmlrpc_encode_request($method, $params);
 }
Ejemplo n.º 4
0
 function outputFilter($data, $context)
 {
     if (isset($context->userdata->format) && $context->userdata->format === "jsonrpc") {
         $response = new \stdClass();
         $response->id = $context->userdata->id;
         if ($context->userdata->version != "2.0") {
             if ($context->userdata->version == "1.1") {
                 $response->version = "1.1";
             }
             $response->result = null;
             $response->error = null;
         } else {
             $response->jsonrpc = "2.0";
         }
         if ($data !== "") {
             $stream = new \Hprose\BytesIO($data);
             $reader = new \Hprose\Reader($stream);
             while (($tag = $stream->getc()) !== \Hprose\Tags::TagEnd) {
                 $reader->reset();
                 switch ($tag) {
                     case \Hprose\Tags::TagResult:
                         $response->result = $reader->unserialize();
                         break;
                     case \Hprose\Tags::TagError:
                         $lasterror = error_get_last();
                         $response->error = array("code" => $lasterror["type"], "message" => $reader->unserialize());
                         break;
                     case \Hprose\Tags::TagFunctions:
                         $response->result = $reader->unserialize();
                         break;
                     default:
                         return json_encode($response);
                         break;
                 }
             }
         }
         $data = json_encode($response);
     }
     return $data;
 }
Ejemplo n.º 5
0
 function outputFilter($data, $context)
 {
     if (isset($context->userdata->jsonrpc)) {
         $responses = array();
         $stream = new \Hprose\BytesIO($data);
         $reader = new \Hprose\Reader($stream);
         $tag = $stream->getc();
         foreach ($context->userdata->jsonrpc as $jsonrpc) {
             $response = new \stdClass();
             $response->id = $jsonrpc->id;
             $version = $jsonrpc->version;
             if ($version !== '2.0') {
                 if ($version === '1.1') {
                     $response->version = '1.1';
                 }
                 $response->result = null;
                 $response->error = null;
             } else {
                 $response->jsonrpc = '2.0';
             }
             if ($tag !== \Hprose\Tags::TagEnd) {
                 $reader->reset();
                 if ($tag === \Hprose\Tags::TagResult) {
                     $response->result = $reader->unserialize();
                 } else {
                     if ($tag === \Hprose\Tags::TagError) {
                         $lasterror = error_get_last();
                         $response->error = new \stdClass();
                         $response->error->code = $lasterror['type'];
                         $response->error->message = $reader->unserialize();
                     }
                 }
                 $tag = $stream->getc();
             } else {
                 $response->result = null;
             }
             if ($response->id !== null) {
                 $responses[] = $response;
             }
         }
         if (count($context->userdata->jsonrpc) === 1) {
             if (count($responses) === 1) {
                 return json_encode($responses[0]);
             }
             return '';
         }
         return json_encode($responses);
     }
     return $data;
 }