private function doInvoke()
 {
     $simpleReader = new HproseSimpleReader($this->input);
     do {
         $functionName = $simpleReader->readString(true);
         $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->resultModes['*'];
         } else {
             throw new HproseException("Can't find this function " . $functionName . "().");
         }
         if ($simple === NULL) {
             $simple = $this->simple;
         }
         $writer = $simple ? new HproseSimpleWriter($this->output) : new HproseWriter($this->output);
         $args = array();
         $byref = false;
         $tag = $simpleReader->checkTags(array(HproseTags::TagList, HproseTags::TagEnd, HproseTags::TagCall));
         if ($tag == HproseTags::TagList) {
             $reader = new HproseReader($this->input);
             $args =& $reader->readList();
             $tag = $reader->checkTags(array(HproseTags::TagTrue, HproseTags::TagEnd, HproseTags::TagCall));
             if ($tag == HproseTags::TagTrue) {
                 $byref = true;
                 $tag = $reader->checkTags(array(HproseTags::TagEnd, HproseTags::TagCall));
             }
         }
         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);
             }
             if ($byref) {
                 $this->output->write(HproseTags::TagArgument);
                 $writer->reset();
                 $writer->writeList($args);
             }
         }
     } while ($tag == HproseTags::TagCall);
     $this->output->write(HproseTags::TagEnd);
     ob_end_flush();
 }
Example #2
0
 public function reset()
 {
     parent::reset();
     $this->ref = array();
 }