コード例 #1
0
ファイル: HproseClient.php プロジェクト: ljhcj/IRISCC
 public function invoke($functionName, &$arguments = array(), $byRef = false, $resultMode = HproseResultMode::Normal, $simple = NULL)
 {
     if ($simple === NULL) {
         $simple = $this->simple;
     }
     $stream = new HproseStringStream(HproseTags::TagCall);
     //$hproseWriter = new HproseWriter($stream, $simple);
     // $hproseWriter->writeString($functionName);
     $stream->write(hprose_serialize_string($functionName));
     if (count($arguments) > 0 || $byRef) {
         // $hproseWriter->reset();
         // $hproseWriter->writeList($arguments);
         $stream->write(hprose_serialize_list($arguments, $simple));
         if ($byRef) {
             // $hproseWriter->writeBoolean(true);
             $stream->write(hprose_serialize_bool(true));
         }
     }
     $stream->write(HproseTags::TagEnd);
     $request = $stream->toString();
     $count = count($this->filters);
     for ($i = 0; $i < $count; $i++) {
         $request = $this->filters[$i]->outputFilter($request, $this);
     }
     $stream->close();
     $response = $this->sendAndReceive($request);
     for ($i = $count - 1; $i >= 0; $i--) {
         $response = $this->filters[$i]->inputFilter($response, $this);
     }
     if ($resultMode == HproseResultMode::RawWithEndTag) {
         return $response;
     }
     if ($resultMode == HproseResultMode::Raw) {
         return substr($response, 0, -1);
     }
     $stream = new HproseStringStream($response);
     $hproseReader = new HproseRawReader($stream);
     $result = NULL;
     while (($tag = $stream->getc()) !== HproseTags::TagEnd) {
         switch ($tag) {
             case HproseTags::TagResult:
                 if ($resultMode == HproseResultMode::Serialized) {
                     $result = $hproseReader->readRaw()->toString();
                 } else {
                     // $hproseReader->reset();
                     // $result = &$hproseReader->unserialize();
                     $result =& hprose_unserialize_with_stream($stream);
                 }
                 break;
             case HproseTags::TagArgument:
                 // $hproseReader->reset();
                 // $args = &$hproseReader->readList();
                 $args =& hprose_unserialize_with_stream($stream);
                 for ($i = 0; $i < count($arguments); $i++) {
                     $arguments[$i] =& $args[$i];
                 }
                 break;
             case HproseTags::TagError:
                 // $hproseReader->reset();
                 throw new Exception(hprose_unserialize_with_stream($stream));
                 break;
             default:
                 throw new Exception("Wrong Response: \r\n" . $response);
                 break;
         }
     }
     return $result;
 }
コード例 #2
0
ファイル: HproseHttpServer.php プロジェクト: ljhcj/IRISCC
 private function doInvoke()
 {
     // $simpleReader = new HproseReader($this->input, true);
     do {
         $functionName = hprose_unserialize_with_stream($this->input, true);
         // $functionName = $simpleReader->readString();
         $aliasName = strtolower($functionName);
         $resultMode = HproseResultMode::Normal;
         if (array_key_exists($aliasName, $this->functions)) {
             $function = $this->functions[$aliasName];
             $resultMode = $this->resultModes[$aliasName];
             $simple = $this->simpleModes[$aliasName];
         } elseif (array_key_exists('*', $this->functions)) {
             $function = $this->functions['*'];
             $resultMode = $this->resultModes['*'];
             $simple = $this->simpleModes['*'];
         } else {
             throw new Exception("Can't find this function " . $functionName . "().");
         }
         if ($simple === NULL) {
             $simple = $this->simple;
         }
         // $writer = new HproseWriter($this->output, $simple);
         $args = array();
         $byref = false;
         // $tag = $simpleReader->checkTags(array(HproseTags::TagList,
         //                                 HproseTags::TagEnd,
         //                                 HproseTags::TagCall));
         $tag = $this->input->getc();
         if ($tag == HproseTags::TagList) {
             // $reader = new HproseReader($this->input);
             // $args = &$reader->readListWithoutTag();
             $args =& hprose_unserialize_list_with_stream($this->input);
             $tag = $this->input->getc();
             // $tag = $reader->checkTags(array(HproseTags::TagTrue,
             //                                 HproseTags::TagEnd,
             //                                 HproseTags::TagCall));
             if ($tag == HproseTags::TagTrue) {
                 $byref = true;
                 $tag = $this->input->getc();
                 // $tag = $reader->checkTags(array(HproseTags::TagEnd,
                 //                                 HproseTags::TagCall));
             }
         }
         if ($tag != HproseTags::TagEnd && $tag != HproseTags::TagCall) {
             throw new Exception($tag);
             //throw new Exception("Wrong Request: \r\n" . $GLOBALS['HTTP_RAW_POST_DATA']);
         }
         if ($this->onBeforeInvoke) {
             call_user_func($this->onBeforeInvoke, $functionName, $args, $byref);
         }
         if (array_key_exists('*', $this->functions) && $function === $this->functions['*']) {
             $arguments = array($functionName, &$args);
         } elseif ($byref) {
             $arguments = array();
             for ($i = 0; $i < count($args); $i++) {
                 $arguments[$i] =& $args[$i];
             }
         } else {
             $arguments = $args;
         }
         $result = call_user_func_array($function, $arguments);
         if ($this->onAfterInvoke) {
             call_user_func($this->onAfterInvoke, $functionName, $args, $byref, $result);
         }
         // some service functions/methods may echo content, we need clean it
         @ob_clean();
         if ($resultMode == HproseResultMode::RawWithEndTag) {
             $this->output->write($result);
             return;
         } elseif ($resultMode == HproseResultMode::Raw) {
             $this->output->write($result);
         } else {
             $this->output->write(HproseTags::TagResult);
             if ($resultMode == HproseResultMode::Serialized) {
                 $this->output->write($result);
             } else {
                 // $writer->reset();
                 // $writer->serialize($result);
                 $this->output->write(hprose_serialize($result, $simple));
             }
             if ($byref) {
                 $this->output->write(HproseTags::TagArgument . hprose_serialize_list($args, $simple));
                 // $writer->reset();
                 // $writer->writeList($args);
             }
         }
     } while ($tag == HproseTags::TagCall);
     $this->output->write(HproseTags::TagEnd);
     $this->responseEnd();
 }