예제 #1
0
 /**
  * Call the registered user function, including an external file if needed
  * and passing along the specified arguments
  *
  * @param array         $aArgs                The function arguments
  *
  * @return void
  */
 public function call($aArgs = array())
 {
     if ($this->sInclude) {
         ob_start();
         require_once $this->sInclude;
         $sOutput = ob_get_clean();
         if ($sOutput) {
             $sOutput = $this->trans('debug.function.include', array('file' => $this->sInclude, 'output' => $sOutput));
             ResponseManager::getInstance()->debug($sOutput);
         }
     }
     $mFunction = $this->sUserFunction;
     ResponseManager::getInstance()->append(call_user_func_array($mFunction, $aArgs));
 }
예제 #2
0
파일: Xajax.php 프로젝트: lagdo/xajax-core
 /**
  * If this is a xajax request, call the requested PHP function, build the response and send it back to the browser
  *
  * This is the main server side engine for xajax.
  * It handles all the incoming requests, including the firing of events and handling of the response.
  * If your RequestURI is the same as your web page, then this function should be called before ANY
  * headers or HTML is output from your script.
  * 
  * This function may exit after the request is processed, if the 'core.exit_after' option is set to true.
  *
  * @return void
  * 
  * @see <Xajax\Xajax->canProcessRequest>
  */
 public function processRequest()
 {
     if (isset($_SERVER['HTTP_CHALLENGE_RESPONSE'])) {
         $this->challengeResponse = $_SERVER['HTTP_CHALLENGE_RESPONSE'];
     }
     // Check to see if headers have already been sent out, in which case we can't do our job
     if (headers_sent($filename, $linenumber)) {
         echo $this->trans('errors.output.already-sent', array('location' => $filename . ':' . $linenumber)), "\n", $this->trans('errors.output.advice');
         exit;
     }
     //
     if (!$this->canProcessRequest()) {
         return;
     }
     // Use xajax error handler if necessary
     if ($this->getOption('core.error.handle')) {
         $this->setErrorMessage('');
         set_error_handler(array($this, "errorHandler"));
     }
     $bEndRequest = false;
     $mResult = true;
     // handle beforeProcessing event
     if (isset($this->aProcessingEvents[self::PROCESSING_EVENT_BEFORE])) {
         $xResponse = $this->aProcessingEvents[self::PROCESSING_EVENT_BEFORE]->call(array(&$bEndRequest));
         if ($xResponse instanceof Response\Response) {
             $this->xResponseManager->append($xResponse);
         }
     }
     if (!$bEndRequest) {
         $mResult = $this->xPluginManager->processRequest();
     }
     // Clean the processing buffer
     if ($this->getOption('core.process.clean_buffer')) {
         $er = error_reporting(0);
         while (ob_get_level() > 0) {
             ob_end_clean();
         }
         error_reporting($er);
     }
     if ($mResult === true) {
         // handle afterProcessing event
         if (isset($this->aProcessingEvents[self::PROCESSING_EVENT_AFTER])) {
             $bEndRequest = false;
             $xResponse = $this->aProcessingEvents[self::PROCESSING_EVENT_AFTER]->call(array($bEndRequest));
             if ($xResponse instanceof Response\Response) {
                 $this->xResponseManager->append($xResponse);
             }
         }
     } else {
         if (is_string($mResult)) {
             // $mResult contains an error message
             // the request was missing the cooresponding handler function
             // or an error occurred while attempting to execute the
             // handler.  replace the response, if one has been started
             // and send a debug message.
             $this->xResponseManager->clear();
             $this->xResponseManager->append(new Response\Response());
             // handle invalidRequest event
             if (isset($this->aProcessingEvents[self::PROCESSING_EVENT_INVALID])) {
                 $xResponse = $this->aProcessingEvents[self::PROCESSING_EVENT_INVALID]->call($mResult);
                 if ($xResponse instanceof Response\Response) {
                     $this->xResponseManager->append($xResponse);
                 }
             }
             $this->xResponseManager->debug($mResult);
         }
     }
     if ($this->sErrorMessage && $this->getOption('core.error.handle') && $this->hasOption('core.error.log_file')) {
         if (($fH = @fopen($this->getOption('core.error.log_file'), "a")) != null) {
             fwrite($fH, $this->trans('errors.debug.ts-message', array('timestamp' => strftime("%b %e %Y %I:%M:%S %p"), 'message' => $this->sErrorMessage)));
             fclose($fH);
         } else {
             $this->xResponseManager->debug($this->trans('errors.debug.write-log', array('file' => $this->getOption('core.error.log_file'))));
         }
         $this->xResponseManager->debug($this->trans('errors.debug.message', array('message' => $this->sErrorMessage)));
     }
     $this->xResponseManager->send();
     if ($this->getOption('core.error.handle')) {
         restore_error_handler();
     }
     if ($this->getOption('core.process.exit_after')) {
         exit;
     }
 }
예제 #3
0
 /**
  * Call the specified method of the registered callable object using the specified array of arguments
  *
  * @param string        $sMethod            The name of the method to call
  * @param array         $aArgs                The arguments to pass to the method
  *
  * @return void
  */
 public function call($sMethod, $aArgs)
 {
     if (!$this->hasMethod($sMethod)) {
         return;
     }
     $reflectionMethod = $this->reflectionClass->getMethod($sMethod);
     ResponseManager::getInstance()->append($reflectionMethod->invokeArgs($this->callableObject, $aArgs));
 }