Example #1
0
 /**
  * PHP error and exception handler
  *
  * @param   integer|object  exception object or error code
  * @param   string          error message
  * @param   string          filename
  * @param   integer         line number
  * @return  void
  */
 public function exception_handler($oException)
 {
     // PHP errors have 5 args, always
     $PHP_ERROR = func_num_args() === 5;
     // Test to see if errors should be displayed
     if ($PHP_ERROR and (error_reporting() & $oException) === 0) {
         return;
     }
     if (!isset(self::$oInstance)) {
         die('Lithium internal error: Cannot initialize framework ( ' . $oException->getMessage() . ' )');
     }
     while (ob_get_level() > 0) {
         // Close open buffers
         ob_end_clean();
     }
     // hide fields of Config that shouldn't be shown
     if (!empty($this->oConfig)) {
         $this->oConfig->hideFieldsForDebug();
     }
     $aParams = array();
     $template = 'lithium_error';
     $aViewData['version'] = LITHIUM_VERSION;
     if ($PHP_ERROR) {
         $code = $oException;
         $type = 'PHP Error';
         $message = IN_PRODUCTION ? 'error.' . E_RECOVERABLE_ERROR : 'core.' . $oException;
         $aParams = func_get_args();
         array_shift($aParams);
     } else {
         $code = $oException->getCode();
         $type = get_class($oException);
         $file = IN_PRODUCTION ? null : preg_replace('!^' . preg_quote(DOCROOT) . '!', '', $oException->getFile());
         $line = $oException->getLine();
         $message = IN_PRODUCTION ? 'error.' . $code : $oException->getMessage();
         if ($oException instanceof Lithium_Exception) {
             // get message from code
             $aParams = $oException->getParams();
             // set template
             $template = $oException->getTemplate();
             // Send headers
             if (!headers_sent()) {
                 $oException->sendHeaders();
             }
         }
     }
     if (strstr($message, 'error.') || !IN_PRODUCTION) {
         $message = $this->getLang($message, $aParams);
     }
     if (!IN_PRODUCTION) {
         $aViewData['aTrace'] = $PHP_ERROR ? array_slice(debug_backtrace(), 1) : $oException->getTrace();
         $aViewData['aTrace'] = $this->getBacktrace($aViewData['aTrace']);
     }
     $aViewData['description'] = is_array($message) ? $message[1] : '';
     $aViewData['message'] = is_array($message) ? $message[0] : $message;
     $aViewData['title'] = 'Error: ' . $aViewData['message'];
     //		if ( class_exists( 'View', false ) ) {
     //			echo View::factory( $template, $aViewData );
     //		} else {
     $sFile = 'View' . DIRECTORY_SEPARATOR . $template . EXT;
     $sIncludeFile = Loader::findFile($sFile);
     if ($sIncludeFile === false) {
         $this->logError('Cannot find view: ' . $sFile);
         echo 'Lithium internal error.';
     } else {
         extract($aViewData);
         require $sIncludeFile;
     }
     //		}
     // Turn off error reporting
     error_reporting(0);
     exit;
 }