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; }
private function sendError() { if ($this->onSendError) { call_user_func($this->onSendError, $this->error); } @ob_clean(); $this->output->write(HproseTags::TagError . hprose_serialize_string($this->error) . HproseTags::TagEnd); $this->responseEnd(); }