/**
  * The entry point for handling an error.
  *
  * This is the lowest entry point for error reporting,
  * and for that reason it can either take just error info,
  * or a combination of error and exception information.
  *
  * Note that this will still log errors in the error log
  * even when it's disabled with ini. It just does nothing
  * more than that.
  */
 public function reportError($code, $message, $errLine, $errFile, $ex = null)
 {
     if ($ex === null && $code === 1 && strpos($message, "Class ") === 0 && strpos($message, "not found") !== false && $this->classNotFoundException !== null) {
         $ex = $this->classNotFoundException;
         $code = $ex->getCode();
         $message = $ex->getMessage();
         $errLine = $ex->getLine();
         $errFile = $ex->getFile();
         $stackTrace = $ex->getTrace();
     }
     $this->logError($message, $errFile, $errLine, $ex);
     /**
      * It runs if:
      *  - it is globally enabled
      *  - this error handler is enabled
      *  - we believe it is a regular html request, or ajax
      */
     global $_php_error_is_ini_enabled;
     if ($_php_error_is_ini_enabled && $this->isOn() && ($this->isAjax || !$this->htmlOnly || !ErrorHandler::isNonPHPRequest())) {
         $root = $this->applicationRoot;
         list($ex, $stackTrace, $code, $errFile, $errLine) = $this->getStackTrace($ex, $code, $errFile, $errLine);
         list($message, $srcErrFile, $srcErrLine, $altInfo) = $this->improveErrorMessage($ex, $code, $message, $errLine, $errFile, $root, $stackTrace);
         $errFile = $srcErrFile;
         $errLine = $srcErrLine;
         list($fileLinesSets, $numFileLines) = $this->generateFileLineSets($srcErrFile, $srcErrLine, $stackTrace);
         list($type, $errFile) = $this->getFolderType($root, $errFile);
         $errFileType = ErrorHandler::folderTypeToCSS($type);
         $stackTrace = $this->parseStackTrace($code, $message, $errLine, $errFile, $stackTrace, $root, $altInfo);
         $fileLines = $this->readCodeFile($srcErrFile, $srcErrLine);
         // load the session, if it's there
         if (isset($_COOKIE[session_name()]) && empty($_SESSION)) {
             session_start();
         }
         $request = ErrorHandler::getRequestHeaders();
         $response = ErrorHandler::getResponseHeaders();
         $dump = $this->generateDumpHTML(array('post' => isset($_POST) ? $_POST : array(), 'get' => isset($_GET) ? $_GET : array(), 'session' => isset($_SESSION) ? $_SESSION : array(), 'cookies' => isset($_COOKIE) ? $_COOKIE : array()), $request, $response, $_SERVER);
         $this->displayError($message, $srcErrLine, $errFile, $errFileType, $stackTrace, $fileLinesSets, $numFileLines, $dump);
         // exit in order to end processing
         $this->turnOff();
         exit(0);
     }
 }
예제 #2
0
 /**
  * The entry point for handling an error.
  * 
  * This is the lowest entry point for error reporting,
  * and for that reason it can either take just error info,
  * or a combination of error and exception information.
  * 
  * Note that this will still log errors in the error log
  * even when it's disabled with ini. It just does nothing
  * more than that.
  */
 public function reportError($code, $message, $errLine, $errFile, $ex = null)
 {
     if ($ex === null && $code === 1 && strpos($message, "Class ") === 0 && strpos($message, "not found") !== false && $this->classNotFoundException !== null) {
         $ex = $this->classNotFoundException;
         $code = $ex->getCode();
         $message = $ex->getMessage();
         $errLine = $ex->getLine();
         $errFile = $ex->getFile();
         $stackTrace = $ex->getTrace();
     }
     $this->logError($message, $errFile, $errLine, $ex);
     if ($this->triggerCallback($code, $message, $errLine, $errFile, $ex)) {
         // exit in order to end processing
         $this->turnOff();
         exit(0);
     }
     /**
      * It runs if:
      *  - it is globally enabled
      *  - this error handler is enabled
      */
     global $_php_error_is_ini_enabled;
     if ($_php_error_is_ini_enabled && $this->isOn()) {
         if (!self::isCLI()) {
             /* Every broken page should have status 500 */
             header('HTTP/1.1 500 Internal Server Error');
         }
         $outputSoFar = $this->discardBuffer(true);
         /**
          * Error is displayed if:
          *  - display_errors is 1
          *  - we believe it is a regular html request, or ajax
          */
         if ($this->isDisplayingErrors() && ($this->isAjax || !$this->htmlOnly || !ErrorHandler::isNonPHPRequest())) {
             $root = $this->applicationRoot;
             list($ex, $stackTrace, $code, $errFile, $errLine) = $this->getStackTrace($ex, $code, $errFile, $errLine);
             list($message, $srcErrFile, $srcErrLine, $altInfo) = $this->improveErrorMessage($ex, $code, $message, $errLine, $errFile, $root, $stackTrace);
             $errFile = $srcErrFile;
             $errLine = $srcErrLine;
             if (self::isCLI()) {
                 // it is not needed, since PHP will print out to stderr. maybe later...
                 //$this->displayCLIError($message, $errFile, $errLine, $stackTrace);
                 exit($code);
             }
             list($fileLinesSets, $numFileLines) = $this->generateFileLineSets($srcErrFile, $srcErrLine, $stackTrace);
             list($type, $errFile) = $this->getFolderType($root, $errFile);
             $errFileType = ErrorHandler::folderTypeToCSS($type);
             $stackTrace = $this->parseStackTrace($code, $message, $errLine, $errFile, $stackTrace, $root, $altInfo);
             $fileLines = $this->readCodeFile($srcErrFile, $srcErrLine);
             // load the session, if it's there
             if (isset($_COOKIE[session_name()]) && session_id() !== '' && !isset($_SESSION)) {
                 if (session_id() === '') {
                     session_start();
                 }
             }
             $request = ErrorHandler::getRequestHeaders();
             $response = ErrorHandler::getResponseHeaders();
             $dump = $this->generateDumpHTML(array('post' => isset($_POST) ? $_POST : array(), 'get' => isset($_GET) ? $_GET : array(), 'session' => isset($_SESSION) ? $_SESSION : array(), 'cookies' => isset($_COOKIE) ? $_COOKIE : array()), $request, $response, $_SERVER);
             $this->displayError($message, $srcErrLine, $errFile, $errFileType, $stackTrace, $fileLinesSets, $numFileLines, $dump, $outputSoFar);
         } elseif ($this->errorPage && !$this->isDisplayingErrors() && !$this->isAjax && (!$this->htmlOnly || !ErrorHandler::isNonPHPRequest())) {
             if ($this->errorPage[0] !== '/' && $this->errorPage[1] !== ':') {
                 $this->errorPage = $this->applicationRoot . '/' . $this->errorPage;
             }
             if (file_exists($this->errorPage)) {
                 if (in_array(substr($this->errorPage, -4), array('.php', '.phtml', '.inc'))) {
                     include $this->errorPage;
                 } else {
                     readfile($this->errorPage);
                 }
             } else {
                 echo '!';
             }
         }
         // exit in order to end processing
         $this->turnOff();
         exit($code);
     }
 }
예제 #3
0
 /**
  * The entry point for handling an error.
  * 
  * This is the lowest entry point for error reporting,
  * and for that reason it can either take just error info,
  * or a combination of error and exception information.
  * 
  * Note that this will still log errors in the error log
  * even when it's disabled with ini. It just does nothing
  * more than that.
  */
 public function reportError($code, $message, $errLine, $errFile, $ex = null)
 {
     if ($ex === null && $code === 1 && strpos($message, "Class ") === 0 && strpos($message, "not found") !== false && $this->classNotFoundException !== null) {
         $ex = $this->classNotFoundException;
         $code = $ex->getCode();
         $message = $ex->getMessage();
         $errLine = $ex->getLine();
         $errFile = $ex->getFile();
         $stackTrace = $ex->getTrace();
     }
     $this->logError($message, $errFile, $errLine, $ex);
     global $_php_error_is_ini_enabled;
     if ($_php_error_is_ini_enabled) {
         $root = $this->applicationRoot;
         list($ex, $stackTrace, $code, $errFile, $errLine) = $this->getStackTrace($ex, $code, $errFile, $errLine);
         list($message, $srcErrFile, $srcErrLine, $altInfo) = $this->improveErrorMessage($ex, $code, $message, $errLine, $errFile, $root, $stackTrace);
         $errFile = $srcErrFile;
         $errLine = $srcErrLine;
         list($fileLinesSets, $numFileLines) = $this->generateFileLineSets($srcErrFile, $srcErrLine, $stackTrace);
         list($type, $errFile) = $this->getFolderType($root, $errFile);
         $errFileType = ErrorHandler::folderTypeToCSS($type);
         $stackTrace = $this->parseStackTrace($code, $message, $errLine, $errFile, $stackTrace, $root, $altInfo);
         $fileLines = $this->readCodeFile($srcErrFile, $srcErrLine);
         // load the session, if it's there
         if (isset($_COOKIE[session_name()]) && empty($_SESSION)) {
             session_start();
         }
         $request = ErrorHandler::getRequestHeaders();
         $response = ErrorHandler::getResponseHeaders();
         /*$dump = $this->generateDumpHTML(
                                     array(
                                             'post'    => ( isset($_POST)    ? $_POST    : array() ),
                                             'get'     => ( isset($_GET)     ? $_GET     : array() ),
                                             'session' => ( isset($_SESSION) ? $_SESSION : array() ),
                                             'cookies' => ( isset($_COOKIE)  ? $_COOKIE  : array() )
                                     ),
         
                                     $request,
                                     $response,
         
                                     $_SERVER
                             );*/
         $dump = array();
         $dump[] = !empty($_GET) ? dump($_GET, 'GET', 'yellow') : '';
         $dump[] = !empty($_POST) ? dump($_POST, 'POST', 'red') : '';
         $dump[] = !empty($_SESSION) ? dump($_SESSION, 'SESSION', 'orange') : '';
         $dump[] = !empty($_COOKIE) ? dump($_COOKIE, 'COOKIE', 'brown') : '';
         $dump[] = !empty($request) ? dump($request, 'REQUEST', 'green') : '';
         $dump[] = !empty($response) ? dump($response, 'RESPONSE', 'grey') : '';
         $dump[] = !empty($_SERVER) ? dump($_SERVER, 'SERVER', 'lilac') : '';
         $dump = implode("\n", $dump);
         $this->displayError($message, $srcErrLine, $errFile, $errFileType, $stackTrace, $fileLinesSets, $numFileLines, $dump);
         // exit in order to end processing
         $this->turnOff();
         exit(0);
     }
 }