public function handleError($type, $code, $message, $file, $line, $trace)
 {
     $errorLog = new jLogErrorMessage($type, $code, $message, $file, $line, $trace);
     $errorLog->setFormat(jApp::config()->error_handling['messageLogFormat']);
     jLog::log($errorLog, $type);
     $this->allErrorMessages[] = $errorLog;
     if ($type != 'error') {
         return;
     }
     $this->errorMessage = $errorLog;
     while (ob_get_level() && @ob_end_clean()) {
     }
     if ($this->response) {
         $resp = $this->response;
     } else {
         require_once JELIX_LIB_CORE_PATH . 'response/jResponseCmdline.class.php';
         $resp = $this->response = new jResponseCmdline();
     }
     $resp->outputErrors();
     jSession::end();
     exit(1);
 }
Ejemplo n.º 2
0
 /**
  * main method : launch the execution of the action.
  *
  * This method should be called in a entry point.
  *
  * @param  jRequest  $request the request object. It is required if a descendant of jCoordinator did not called setRequest before
  */
 public function process($request = null)
 {
     jLog::log("process: start");
     try {
         if ($request) {
             $this->setRequest($request);
         }
         jSession::start();
         $ctrl = $this->getController($this->action);
     } catch (jException $e) {
         $config = jApp::config();
         if ($config->urlengine['notfoundAct'] == '') {
             throw $e;
         }
         if (!jSession::isStarted()) {
             jSession::start();
         }
         try {
             jLog::log("Exception: get notfoundact ctrl (" . $config->urlengine['notfoundAct'] . ")");
             $this->action = new jSelectorAct($config->urlengine['notfoundAct']);
             $ctrl = $this->getController($this->action);
         } catch (jException $e2) {
             throw $e;
         }
     }
     jApp::pushCurrentModule($this->moduleName);
     if (count($this->plugins)) {
         $pluginparams = array();
         if (isset($ctrl->pluginParams['*'])) {
             $pluginparams = $ctrl->pluginParams['*'];
         }
         if (isset($ctrl->pluginParams[$this->action->method])) {
             $pluginparams = array_merge($pluginparams, $ctrl->pluginParams[$this->action->method]);
         }
         jLog::dump($pluginparams, "process: plugin params");
         foreach ($this->plugins as $name => $obj) {
             jLog::log("process: beforeAction on plugin {$name}");
             $result = $this->plugins[$name]->beforeAction($pluginparams);
             if ($result) {
                 $this->action = $result;
                 jApp::popCurrentModule();
                 jApp::pushCurrentModule($result->module);
                 jLog::log("process: beforeAction said to do internal redirect to " . $result->module . "~" . $result->resource);
                 $this->moduleName = $result->module;
                 $this->actionName = $result->resource;
                 $ctrl = $this->getController($this->action);
                 break;
             }
         }
     }
     jLog::log('process: call action');
     $this->response = $ctrl->{$this->action->method}();
     if ($this->response == null) {
         throw new jException('jelix~errors.response.missing', $this->action->toString());
     }
     jLog::log('process: response: ' . get_class($this->response));
     if (get_class($this->response) == 'jResponseRedirect') {
         jLog::log('process: redirection to ' . $this->response->action);
     } else {
         if (get_class($this->response) == 'jResponseRedirectUrl') {
             jLog::log('process: redirection to ' . $this->response->url);
         }
     }
     foreach ($this->plugins as $name => $obj) {
         jLog::log('process: beforeOutput on plugin ' . $name);
         $this->plugins[$name]->beforeOutput();
     }
     jLog::log('process: call response output');
     $this->response->output();
     foreach ($this->plugins as $name => $obj) {
         jLog::log('process: afterProcess on plugin ' . $name);
         $this->plugins[$name]->afterProcess();
     }
     jApp::popCurrentModule();
     jSession::end();
     jLog::log('process: end');
 }
Ejemplo n.º 3
0
 /**
  * Handle an error event. Called by error handler and exception handler.
  * @param string  $type    error type : 'error', 'warning', 'notice'
  * @param integer $code    error code
  * @param string  $message error message
  * @param string  $file    the file name where the error appear
  * @param integer $line    the line number where the error appear
  * @param array   $trace   the stack trace
  * @since 1.1
  */
 public function handleError($type, $code, $message, $file, $line, $trace)
 {
     global $gJConfig;
     $errorLog = new jLogErrorMessage($type, $code, $message, $file, $line, $trace);
     if ($this->request) {
         // we have config, so we can process "normally"
         $errorLog->setFormat($gJConfig->error_handling['messageLogFormat']);
         jLog::log($errorLog, $type);
         // if non fatal error, it is finished
         if ($type != 'error') {
             return;
         }
         $this->errorMessage = $errorLog;
         while (ob_get_level()) {
             ob_end_clean();
         }
         $resp = $this->request->getErrorResponse($this->response);
         $resp->outputErrors();
         jSession::end();
     } elseif ($type != 'error') {
         $this->initErrorMessages[] = $errorLog;
         return;
     } else {
         // fatal error appeared during init, let's display an HTML page
         // since we don't know the request, we cannot return a response
         // corresponding to the expected protocol
         while (ob_get_level()) {
             ob_end_clean();
         }
         // log into file
         @error_log($errorLog->getFormatedMessage(), 3, jApp::logPath('errors.log'));
         // if accept text/html
         if (isset($_SERVER['HTTP_ACCEPT']) && strstr($_SERVER['HTTP_ACCEPT'], 'text/html')) {
             if (file_exists(jApp::appPath('responses/error.en_US.php'))) {
                 $file = jApp::appPath('responses/error.en_US.php');
             } else {
                 $file = JELIX_LIB_CORE_PATH . 'response/error.en_US.php';
             }
             $HEADBOTTOM = '';
             $BODYTOP = '';
             $BODYBOTTOM = '';
             $basePath = '';
             header("HTTP/1.1 500 Internal jelix error");
             header('Content-type: text/html');
             include $file;
         } else {
             // output text response
             header("HTTP/1.1 500 Internal jelix error");
             header('Content-type: text/plain');
             echo 'Error during initialization.';
         }
     }
     exit(1);
 }
Ejemplo n.º 4
0
 /**
  * Handle an error event. Called by error handler and exception handler.
  * @param string  $type    error type : 'error', 'warning', 'notice'
  * @param integer $code    error code
  * @param string  $message error message
  * @param string  $file    the file name where the error appear
  * @param integer $line    the line number where the error appear
  * @param array   $trace   the stack trace
  * @since 1.1
  */
 public function handleError($type, $code, $message, $file, $line, $trace)
 {
     $errorLog = new jLogErrorMessage($type, $code, $message, $file, $line, $trace);
     $errorLog->setFormat(jApp::config()->error_handling['messageLogFormat']);
     jLog::log($errorLog, $type);
     // if non fatal error, it is finished, continue the execution of the action
     if ($type != 'error') {
         return;
     }
     $this->errorMessage = $errorLog;
     while (ob_get_level() && @ob_end_clean()) {
     }
     $resp = $this->request->getErrorResponse($this->response);
     $resp->outputErrors();
     jSession::end();
     exit(1);
 }
Ejemplo n.º 5
0
 /**
  * Handle an error event. Called by error handler and exception handler.
  * Responses object should take care of the errorMessages property to display errors.
  * @param string  $toDo    a string which contains keyword indicating what to do with the error
  * @param string  $type    error type : 'error', 'warning', 'notice'
  * @param integer $code    error code
  * @param string  $message error message
  * @param string  $file    the file name where the error appear
  * @param integer $line    the line number where the error appear
  * @param array   $trace   the stack trace
  * @since 1.1
  */
 public function handleError($toDo, $type, $code, $message, $file, $line, $trace)
 {
     global $gJConfig;
     $conf = $gJConfig->error_handling;
     $doEchoByResponse = true;
     if ($this->request == null) {
         $message = 'JELIX PANIC ! Error during initialization !! ' . $message;
         $doEchoByResponse = false;
         $toDo .= ' EXIT';
     } elseif ($this->response == null) {
         $ret = $this->initDefaultResponseOfRequest();
         if (is_string($ret)) {
             $message = 'Double error ! 1)' . $ret . '; 2)' . $message;
             $doEchoByResponse = false;
         }
     }
     // When we are in cmdline we need to fix the remoteAddr
     $remoteAddr = isset($_SERVER['REMOTE_ADDR']) ? $_SERVER['REMOTE_ADDR'] : '127.0.0.1';
     // url params including module and action
     if ($this->request) {
         $url = str_replace('array', 'url', var_export($this->request->params, true));
     } else {
         $url = 'Unknow url';
     }
     // formatting message
     $messageLog = strtr($conf['messageLogFormat'], array('%date%' => date("Y-m-d H:i:s"), '%ip%' => $remoteAddr, '%typeerror%' => $type, '%code%' => $code, '%msg%' => $message, '%url%' => $url, '%file%' => $file, '%line%' => $line, '\\t' => "\t", '\\n' => "\n"));
     if (strpos($toDo, 'TRACE') !== false) {
         $arr = debug_backtrace();
         $messageLog .= "\ttrace:";
         foreach ($arr as $k => $t) {
             $messageLog .= "\n\t{$k}\t" . (isset($t['class']) ? $t['class'] . $t['type'] : '') . $t['function'] . "()\t";
             $messageLog .= (isset($t['file']) ? $t['file'] : '[php]') . ' : ' . (isset($t['line']) ? $t['line'] : '');
         }
         $messageLog .= "\n";
     }
     $echoAsked = false;
     // traitement du message
     if (strpos($toDo, 'ECHOQUIET') !== false) {
         $echoAsked = true;
         if (!$doEchoByResponse) {
             header("HTTP/1.1 500 Internal jelix error");
             header('Content-type: text/plain');
             echo 'JELIX PANIC ! Error during initialization !! ';
         } elseif ($this->addErrorMsg($type, $code, $conf['quietMessage'], '', '')) {
             $toDo .= ' EXIT';
         }
     } elseif (strpos($toDo, 'ECHO') !== false) {
         $echoAsked = true;
         if (!$doEchoByResponse) {
             header("HTTP/1.1 500 Internal jelix error");
             header('Content-type: text/plain');
             echo $messageLog;
         } elseif ($this->addErrorMsg($type, $code, $message, $file, $line)) {
             $toDo .= ' EXIT';
         }
     }
     if (strpos($toDo, 'LOGFILE') !== false) {
         @error_log($messageLog, 3, JELIX_APP_LOG_PATH . $conf['logFile']);
     }
     if (strpos($toDo, 'MAIL') !== false) {
         error_log(wordwrap($messageLog, 70), 1, $conf['email'], $conf['emailHeaders']);
     }
     if (strpos($toDo, 'SYSLOG') !== false) {
         error_log($messageLog, 0);
     }
     if (strpos($toDo, 'EXIT') !== false) {
         if ($doEchoByResponse) {
             if ($this->response) {
                 $this->response->outputErrors();
             } else {
                 if ($echoAsked) {
                     header("HTTP/1.1 500 Internal jelix error");
                     header('Content-type: text/plain');
                     foreach ($this->errorMessages as $msg) {
                         echo $msg . "\n";
                     }
                 }
             }
         }
         jSession::end();
         exit;
     }
 }
Ejemplo n.º 6
0
 /**
  * Handle an error event. Called by error handler and exception handler.
  * @param string  $type    error type : 'error', 'warning', 'notice'
  * @param integer $code    error code
  * @param string  $message error message
  * @param string  $file    the file name where the error appear
  * @param integer $line    the line number where the error appear
  * @param array   $trace   the stack trace
  * @since 1.1
  */
 public function handleError($type, $code, $message, $file, $line, $trace)
 {
     global $gJConfig;
     $errorLog = new jLogErrorMessage($type, $code, $message, $file, $line, $trace);
     if ($this->request) {
         // we have config, so we can process "normally"
         $errorLog->setFormat($gJConfig->error_handling['messageLogFormat']);
         jLog::log($errorLog, $type);
         $this->allErrorMessages[] = $errorLog;
         // if non fatal error, it is finished
         if ($type != 'error') {
             return;
         }
         $this->errorMessage = $errorLog;
         while (ob_get_level()) {
             ob_end_clean();
         }
         if ($this->response) {
             $resp = $this->response;
         } else {
             $resp = $this->response = new jResponseCmdline();
         }
         $resp->outputErrors();
         jSession::end();
     } elseif ($type != 'error') {
         $this->allErrorMessages[] = $errorLog;
         $this->initErrorMessages[] = $errorLog;
         return;
     } else {
         // fatal error appeared during init, let's display a single message
         while (ob_get_level()) {
             ob_end_clean();
         }
         // log into file
         @error_log($errorLog->getFormatedMessage(), 3, jApp::logPath('errors.log'));
         // output text response
         echo 'Error during initialization: ' . $message . ' (' . $file . ' ' . $line . ")\n";
     }
     exit(1);
 }