Exemplo n.º 1
0
 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;
 }
Exemplo n.º 2
0
 private function doFunctionList()
 {
     $functions = array_values($this->funcNames);
     $this->output->write(HproseTags::TagFunctions . hprose_serialize_list($functions, true) . HproseTags::TagEnd);
     $this->responseEnd();
 }