Index: t3lib/core_autoload.php =================================================================== --- t3lib/core_autoload.php (revision 6024) +++ t3lib/core_autoload.php (working copy) @@ -101,6 +101,15 @@ 't3lib_cache_frontend_stringfrontend' => PATH_t3lib . 'cache/frontend/class.t3lib_cache_frontend_stringfrontend.php', 't3lib_cache_frontend_variablefrontend' => PATH_t3lib . 'cache/frontend/class.t3lib_cache_frontend_variablefrontend.php', 't3lib_cache_frontend_frontend' => PATH_t3lib . 'cache/frontend/interfaces/interface.t3lib_cache_frontend_frontend.php', + 't3lib_error_abstractexceptionhandler' => PATH_t3lib . 'error/class.t3lib_error_abstractexceptionhandler.php', + 't3lib_error_debugexceptionhandler' => PATH_t3lib . 'error/class.t3lib_error_debugexceptionhandler.php', + 't3lib_error_error' => PATH_t3lib . 'error/class.t3lib_error_error.php', + 't3lib_error_errorhandler' => PATH_t3lib . 'error/class.t3lib_error_errorhandler.php', + 't3lib_error_exception' => PATH_t3lib . 'error/class.t3lib_error_exception.php', + 't3lib_error_errorhandlerinterface' => PATH_t3lib . 'error/interface.t3lib_error_errorhandlerinterface.php', + 't3lib_error_exceptionhandlerinterface' => PATH_t3lib . 'error/interface.t3lib_error_exceptionhandlerinterface.php', + 't3lib_error_productionexceptionhandler' => PATH_t3lib . 'error/class.t3lib_error_productionexceptionhandler.php', + 't3lib_error_warning' => PATH_t3lib . 'error/class.t3lib_error_warning.php', 't3lib_browselinkshook' => PATH_t3lib . 'interfaces/interface.t3lib_browselinkshook.php', 't3lib_localrecordlistgettablehook' => PATH_t3lib . 'interfaces/interface.t3lib_localrecordlistgettablehook.php', 't3lib_singleton' => PATH_t3lib . 'interfaces/interface.t3lib_singleton.php', Index: typo3/sysext/cms/tslib/index_ts.php =================================================================== --- typo3/sysext/cms/tslib/index_ts.php (revision 6024) +++ typo3/sysext/cms/tslib/index_ts.php (working copy) @@ -127,6 +127,18 @@ $TT->pull(); +// ********************* +// Error & Exception handling +// ********************* +if ($TYPO3_CONF_VARS['SYS']['displayErrors'] != 0) { + $TT->push('Register Exceptionhandler', ''); + $errorHandler = t3lib_div::makeInstance($TYPO3_CONF_VARS['SYS']['errorHandler']); + $errorHandler->setExceptionalErrors($TYPO3_CONF_VARS['SYS']['exceptionalErrors']); + $exceptionHandler = t3lib_div::makeInstance($TYPO3_CONF_VARS['SYS']['exceptionHandler']); + $TT->pull(); +} + + $TYPO3_DB = t3lib_div::makeInstance('t3lib_DB'); $TYPO3_DB->debugOutput = $TYPO3_CONF_VARS['SYS']['sqlDebug']; Index: typo3/init.php =================================================================== --- typo3/init.php (revision 6024) +++ typo3/init.php (working copy) @@ -184,6 +184,16 @@ t3lib_autoloader::registerAutoloader(); +// ********************* +// Error & Exception handling +// ********************* +if ($TYPO3_CONF_VARS['SYS']['displayErrors'] != 0) { + $errorHandler = t3lib_div::makeInstance($TYPO3_CONF_VARS['SYS']['errorHandler']); + $errorHandler->setExceptionalErrors($TYPO3_CONF_VARS['SYS']['exceptionalErrors']); + $exceptionHandler = t3lib_div::makeInstance($TYPO3_CONF_VARS['SYS']['exceptionHandler']); +} + + /** @var TYPO3_DB t3lib_db */ $TYPO3_DB = t3lib_div::makeInstance('t3lib_DB'); $TYPO3_DB->debugOutput = $TYPO3_CONF_VARS['SYS']['sqlDebug']; Index: t3lib/error/class.t3lib_error_abstractexceptionhandler.php =================================================================== --- t3lib/error/class.t3lib_error_abstractexceptionhandler.php (revision 0) +++ t3lib/error/class.t3lib_error_abstractexceptionhandler.php (revision 0) @@ -0,0 +1,62 @@ + +* All rights reserved +* +* This script is part of the TYPO3 project. The TYPO3 project is +* free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation; either version 2 of the License, or +* (at your option) any later version. +* +* The GNU General Public License can be found at +* http://www.gnu.org/copyleft/gpl.html. +* +* This script is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* This copyright notice MUST APPEAR in all copies of the script! +***************************************************************/ + + + +/** + * An abstract exception handler + * + * This file is a backport from FLOW3 + * + * @package TYPO3 + * @subpackage t3lib_error + * @version $Id: AbstractExceptionHandler.php 3189 2009-09-16 13:36:22Z k-fish $ + */ +abstract class t3lib_error_AbstractExceptionHandler implements t3lib_error_ExceptionHandlerInterface, t3lib_Singleton { + + /** + * Handles the given exception + * + * @param Exception $exception The exception object + * @return void + */ + public function handleException(Exception $exception) { + $exceptionCodeNumber = ($exception->getCode() > 0) ? ' #' . $exception->getCode() : ''; + $backTrace = $exception->getTrace(); + $className = isset($backTrace[0]['class']) ? $backTrace[0]['class'] : '?'; + $methodName = isset($backTrace[0]['function']) ? $backTrace[0]['function'] : '?'; + $line = isset($backTrace['line']) ? ' in line ' . $backTrace['line'] : ''; + $message = 'Uncaught exception' . $exceptionCodeNumber . '. ' . $exception->getMessage() . $line . '.'; + + $explodedClassName = explode('\\', $className); + $packageKey = (isset($explodedClassName[1])) ? $explodedClassName[1] : NULL; + } + +} + +if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['t3lib/error/class.t3lib_error_abstractexceptionhandler.php']) { + include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['t3lib/error/class.t3lib_error_abstractexceptionhandler.php']); +} + +?> \ No newline at end of file Index: t3lib/error/class.t3lib_error_debugexceptionhandler.php =================================================================== --- t3lib/error/class.t3lib_error_debugexceptionhandler.php (revision 0) +++ t3lib/error/class.t3lib_error_debugexceptionhandler.php (revision 0) @@ -0,0 +1,238 @@ + +* All rights reserved +* +* This script is part of the TYPO3 project. The TYPO3 project is +* free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation; either version 2 of the License, or +* (at your option) any later version. +* +* The GNU General Public License can be found at +* http://www.gnu.org/copyleft/gpl.html. +* +* This script is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* This copyright notice MUST APPEAR in all copies of the script! +***************************************************************/ + + + +/** + * A basic but solid exception handler which catches everything which + * falls through the other exception handlers and provides useful debugging + * information. + * + * This file is a backport from FLOW3 + * + * @package TYPO3 + * @subpackage t3lib_error + * @version $Id: DebugExceptionHandler.php 3195 2009-09-17 11:27:14Z k-fish $ + */ +class t3lib_error_DebugExceptionHandler extends t3lib_error_AbstractExceptionHandler { + + /** + * Constructs this exception handler - registers itself as the default exception handler. + * + * @author Robert Lemke + */ + public function __construct() { + @set_exception_handler(array($this, 'handleException')); + } + + /** + * Displays the given exception + * + * @param Exception $exception The exception object + * @return void + * @author Robert Lemke + */ + public function handleException(Exception $exception) { + parent::handleException($exception); + + switch (PHP_SAPI) { + case 'cli' : + $this->echoExceptionCLI($exception); + break; + default : + $this->echoExceptionWeb($exception); + } + } + + /** + * Formats and echoes the exception as XHTML. + * + * @param Exception $exception The exception object + * @return void + * @author Robert Lemke + */ + protected function echoExceptionWeb(Exception $exception) { + if (!headers_sent()) { + header("HTTP/1.1 500 Internal Server Error"); + } + + $pathPosition = strpos($exception->getFile(), 'Packages/'); + $filePathAndName = ($pathPosition === FALSE) ? substr($exception->getFile(), $pathPosition) : $exception->getFile(); + + $exceptionCodeNumber = ($exception->getCode() > 0) ? '#' . $exception->getCode() . ': ' : ''; + $moreInformationLink = ($exceptionCodeNumber != '') ? '(More information)' : ''; + $backtraceCode = $this->getBacktraceCode($exception->getTrace()); + + echo ' + + + TYPO3 Exception + + + +
+
Uncaught TYPO3 Exception
+
+ ' . $exceptionCodeNumber . $exception->getMessage() . ' ' . $moreInformationLink . '
+
+ ' . get_class($exception) . ' thrown in file
+ ' . $filePathAndName . ' in line + ' . $exception->getLine() . '.
+
+ ' . $backtraceCode . ' +
+ '; + echo ' +
+ '; + } + + /** + * Formats and echoes the exception for the command line + * + * @param Exception $exception The exception object + * @return void + * @author Robert Lemke + */ + protected function echoExceptionCLI(Exception $exception) { + $pathPosition = strpos($exception->getFile(), 'Packages/'); + $filePathAndName = ($pathPosition === FALSE) ? substr($exception->getFile(), $pathPosition) : $exception->getFile(); + + $exceptionCodeNumber = ($exception->getCode() > 0) ? '#' . $exception->getCode() . ': ' : ''; + + echo "\nUncaught TYPO3 Exception " . $exceptionCodeNumber . $exception->getMessage() . "\n"; + echo "thrown in file " . $filePathAndName . "\n"; + echo "in line " . $exception->getLine() . "\n\n"; + } + + /** + * Renders some backtrace + * + * @param array $trace The trace + * @return string Backtrace information + * @author Robert Lemke + */ + protected function getBacktraceCode(array $trace) { + $backtraceCode = ''; + if (count($trace)) { + foreach ($trace as $index => $step) { + $class = isset($step['class']) ? $step['class'] . '::' : ''; + + $arguments = ''; + if (isset($step['args']) && is_array($step['args'])) { + foreach ($step['args'] as $argument) { + $arguments .= (strlen($arguments) === 0) ? '' : ', '; + if (is_object($argument)) { + $arguments .= '' . get_class($argument) . ''; + } elseif (is_string($argument)) { + $preparedArgument = (strlen($argument) < 100) ? $argument : substr($argument, 0, 50) . '…' . substr($argument, -50); + $preparedArgument = htmlspecialchars($preparedArgument); + $preparedArgument = str_replace("…", '…', $preparedArgument); + $preparedArgument = str_replace("\n", '⏎', $preparedArgument); + $arguments .= '"' . $preparedArgument . '"'; + } elseif (is_numeric($argument)) { + $arguments .= '' . (string)$argument . ''; + } else { + $arguments .= '' . gettype($argument) . ''; + } + } + } + + $backtraceCode .= '
';
+				$backtraceCode .= '' . (count($trace) - $index) . ' ' . $class . $step['function'] . '(' . $arguments . ')';
+				$backtraceCode .= '
'; + + if (isset($step['file'])) { + $backtraceCode .= $this->getCodeSnippet($step['file'], $step['line']) . '
'; + } + } + } + + return $backtraceCode; + } + + /** + * Returns a code snippet from the specified file. + * + * @param string $filePathAndName Absolute path and file name of the PHP file + * @param integer $lineNumber Line number defining the center of the code snippet + * @return string The code snippet + * @author Robert Lemke + */ + protected function getCodeSnippet($filePathAndName, $lineNumber) { + $codeSnippet = '
'; + if (@file_exists($filePathAndName)) { + $phpFile = @file($filePathAndName); + if (is_array($phpFile)) { + $startLine = ($lineNumber > 2) ? ($lineNumber - 2) : 1; + $endLine = ($lineNumber < (count($phpFile) - 2)) ? ($lineNumber + 3) : count($phpFile) + 1; + if ($endLine > $startLine) { + $codeSnippet = '
' . $filePathAndName . ':
';
+					for ($line = $startLine; $line < $endLine; $line++) {
+						$codeLine = str_replace("\t", ' ', $phpFile[$line-1]);
+
+						if ($line === $lineNumber) {
+							$codeSnippet .= '
';
+						}
+						$codeSnippet .= sprintf('%05d', $line) . ': ' . $codeLine;
+						if ($line === $lineNumber) {
+							$codeSnippet .= '
';
+						}
+					}
+					$codeSnippet .= '
'; + } + } + } + return $codeSnippet; + } +} + + +if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['t3lib/error/class.t3lib_error_debugexceptionhandler.php']) { + include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['t3lib/error/class.t3lib_error_debugexceptionhandler.php']); +} + +?> \ No newline at end of file Index: t3lib/error/class.t3lib_error_error.php =================================================================== --- t3lib/error/class.t3lib_error_error.php (revision 0) +++ t3lib/error/class.t3lib_error_error.php (revision 0) @@ -0,0 +1,99 @@ + +* All rights reserved +* +* This script is part of the TYPO3 project. The TYPO3 project is +* free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation; either version 2 of the License, or +* (at your option) any later version. +* +* The GNU General Public License can be found at +* http://www.gnu.org/copyleft/gpl.html. +* +* This script is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* This copyright notice MUST APPEAR in all copies of the script! +***************************************************************/ + + + +/** + * An object representation of a generic error. Subclass this to create + * more specific errors if necessary. + * + * This file is a backport from FLOW3 + * + * @package TYPO3 + * @subpackage t3lib_error + * @version $Id: Error.php 3189 2009-09-16 13:36:22Z k-fish $ + */ +class t3lib_error_Error { + + /** + * @var string The default (english) error message. + */ + protected $message = 'Unknown error'; + + /** + * @var string The error code + */ + protected $code; + + /** + * Constructs this error + * + * @param string $message An english error message which is used if no other error message can be resolved + * @param integer $code A unique error code + * @author Robert Lemke + * @api + */ + public function __construct($message, $code) { + $this->message = $message; + $this->code = $code; + } + + /** + * Returns the error message + * @return string The error message + * @author Andreas Förthner + * @api + */ + public function getMessage() { + return $this->message; + } + + /** + * Returns the error code + * @return string The error code + * @author Andreas Förthner + * @api + */ + public function getCode() { + return $this->code; + } + + /** + * Converts this error into a string + * + * @return string + * @author Robert Lemke + * @api + */ + public function __toString() { + return $this->message . ' (#' . $this->code . ')'; + } +} + + +if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['t3lib/error/class.t3lib_error_error.php']) { + include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['t3lib/error/class.t3lib_error_error.php']); +} + +?> \ No newline at end of file Index: t3lib/error/class.t3lib_error_errorhandler.php =================================================================== --- t3lib/error/class.t3lib_error_errorhandler.php (revision 0) +++ t3lib/error/class.t3lib_error_errorhandler.php (revision 0) @@ -0,0 +1,96 @@ + +* All rights reserved +* +* This script is part of the TYPO3 project. The TYPO3 project is +* free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation; either version 2 of the License, or +* (at your option) any later version. +* +* The GNU General Public License can be found at +* http://www.gnu.org/copyleft/gpl.html. +* +* This script is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* This copyright notice MUST APPEAR in all copies of the script! +***************************************************************/ + + + +/** + * Global error handler for TYPO3 + * + * This file is a backport from FLOW3 + * + * @package TYPO3 + * @subpackage t3lib_error + * @version $Id: ErrorHandler.php 3195 2009-09-17 11:27:14Z k-fish $ + */ +class t3lib_error_ErrorHandler implements t3lib_error_ErrorHandlerInterface { + + /** + * @var array + */ + protected $exceptionalErrors = array(); + + /** + * Constructs this error handler - registers itself as the default error handler. + * + * @author Robert Lemke + */ + public function __construct() { + set_error_handler(array($this, 'handleError')); + } + + /** + * Defines which error levels result should result in an exception thrown. + * + * @param array $exceptionalErrors An array of E_* error levels + * @return void + * @author Robert Lemke + */ + public function setExceptionalErrors(array $exceptionalErrors) { + $this->exceptionalErrors = $exceptionalErrors; + } + + /** + * Handles an error by converting it into an exception + * + * @param integer $errorLevel The error level - one of the E_* constants + * @param string $errorMessage The error message + * @param string $errorFile Name of the file the error occurred in + * @param integer $errorLine Line number where the error occurred + * @return void + * @throws t3lib_error_Exception with the data passed to this method + * @author Robert Lemke + */ + public function handleError($errorLevel, $errorMessage, $errorFile, $errorLine) { + $errorLevels = array ( + E_WARNING => 'Warning', + E_NOTICE => 'Notice', + E_USER_ERROR => 'User Error', + E_USER_WARNING => 'User Warning', + E_USER_NOTICE => 'User Notice', + E_STRICT => 'Runtime Notice', + E_RECOVERABLE_ERROR => 'Catchable Fatal Error' + ); + + if (in_array($errorLevel, (array)$this->exceptionalErrors)) { + throw new t3lib_error_Exception($errorLevels[$errorLevel] . ': ' . $errorMessage . ' in ' . $errorFile . ' line ' . $errorLine, 1); + } + } +} + + +if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['t3lib/error/class.t3lib_error_errorhandler.php']) { + include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['t3lib/error/class.t3lib_error_errorhandler.php']); +} + +?> \ No newline at end of file Index: t3lib/error/class.t3lib_error_exception.php =================================================================== --- t3lib/error/class.t3lib_error_exception.php (revision 0) +++ t3lib/error/class.t3lib_error_exception.php (revision 0) @@ -0,0 +1,44 @@ + +* All rights reserved +* +* This script is part of the TYPO3 project. The TYPO3 project is +* free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation; either version 2 of the License, or +* (at your option) any later version. +* +* The GNU General Public License can be found at +* http://www.gnu.org/copyleft/gpl.html. +* +* This script is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* This copyright notice MUST APPEAR in all copies of the script! +***************************************************************/ + + + +/** + * An exception which represents a PHP error. + * + * This file is a backport from FLOW3 + * + * @package TYPO3 + * @subpackage t3lib_error + * @version $Id: Exception.php 2813 2009-07-16 14:02:34Z k-fish $ + */ +class t3lib_error_Exception extends t3lib_exception { + +} + +if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['t3lib/error/class.t3lib_error_exception.php']) { + include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['t3lib/error/class.t3lib_error_exception.php']); +} + +?> \ No newline at end of file Index: t3lib/error/class.t3lib_error_productionexceptionhandler.php =================================================================== --- t3lib/error/class.t3lib_error_productionexceptionhandler.php (revision 0) +++ t3lib/error/class.t3lib_error_productionexceptionhandler.php (revision 0) @@ -0,0 +1,184 @@ + +* All rights reserved +* +* This script is part of the TYPO3 project. The TYPO3 project is +* free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation; either version 2 of the License, or +* (at your option) any later version. +* +* The GNU General Public License can be found at +* http://www.gnu.org/copyleft/gpl.html. +* +* This script is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* This copyright notice MUST APPEAR in all copies of the script! +***************************************************************/ + + + +/** + * A quite exception handler which catches but ignores any exception. + * + * This file is a backport from FLOW3 + * + * @package TYPO3 + * @subpackage t3lib_error + * @version $Id: ProductionExceptionHandler.php 3189 2009-09-16 13:36:22Z k-fish $ + */ +class t3lib_error_ProductionExceptionHandler extends t3lib_error_AbstractExceptionHandler { + + /** + * Constructs this exception handler - registers itself as the default exception handler. + * + * @author Robert Lemke + */ + public function __construct() { + @set_exception_handler(array($this, 'handleException')); + } + + /** + * Displays the given exception + * + * @param Exception $exception The exception object + * @return void + * @author Robert Lemke + */ + public function handleException(Exception $exception) { + parent::handleException($exception); + + switch (PHP_SAPI) { + case 'cli' : + $this->echoExceptionCLI($exception); + break; + default : + $this->echoExceptionWeb($exception); + } + } + + /** + * Echoes an exception for the web. + * + * @param Exception $exception The exception + * @return void + */ + public function echoExceptionWeb(Exception $exception) { + if (!headers_sent()) { + header("HTTP/1.1 500 Internal Server Error"); + } + + $exceptionCodeNumber = ($exception->getCode() > 0) ? '#' . $exception->getCode() . ': ' : ''; + $moreInformationLink = ($exceptionCodeNumber != '') ? '

More information

' : ''; + + echo ' + + + + + + + + +
+
+
500 Internal Server Error
+
+

500 Internal Server Error

+

The system experienced an internal error (uncaught exception):

+

' . get_class($exception) . '

+ ' . $moreInformationLink . ' +
+
+
+ +'; + } + + /** + * Echoes an exception for the command line. + * + * @param Exception $exception The exception + * @return void + */ + public function echoExceptionCLI(Exception $exception) { + exit(1); + } +} + +if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['t3lib/error/class.t3lib_error_productionexceptionhandler.php']) { + include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['t3lib/error/class.t3lib_error_productionexceptionhandler.php']); +} + +?> \ No newline at end of file Index: t3lib/error/class.t3lib_error_warning.php =================================================================== --- t3lib/error/class.t3lib_error_warning.php (revision 0) +++ t3lib/error/class.t3lib_error_warning.php (revision 0) @@ -0,0 +1,88 @@ + +* All rights reserved +* +* This script is part of the TYPO3 project. The TYPO3 project is +* free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation; either version 2 of the License, or +* (at your option) any later version. +* +* The GNU General Public License can be found at +* http://www.gnu.org/copyleft/gpl.html. +* +* This script is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* This copyright notice MUST APPEAR in all copies of the script! +***************************************************************/ + + + +/** + * An object representation of a generic warning. Subclass this to create + * more specific warnings if necessary. + * + * This file is a backport from FLOW3 + * + * @package TYPO3 + * @subpackage t3lib_error + * @version $Id: Warning.php 3189 2009-09-16 13:36:22Z k-fish $ + */ +class t3lib_error_Warning { + + /** + * @var string The default (english) error message. + */ + protected $message = 'Unknown warning'; + + /** + * @var string The error code + */ + protected $code; + + /** + * Constructs this warning + * + * @param string $message An english error message which is used if no other error message can be resolved + * @param integer $code A unique error code + * @author Robert Lemke + * @api + */ + public function __construct($message, $code) { + $this->message = $message; + $this->code = 0; + } + + /** + * Returns the error message + * @return string The error message + * @author Andreas Förthner + * @api + */ + public function getMessage() { + return $this->message; + } + + /** + * Returns the error code + * @return string The error code + * @author Andreas Förthner + * @api + */ + public function getCode() { + return $this->code; + } +} + + +if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['t3lib/error/class.t3lib_error_warning.php']) { + include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['t3lib/error/class.t3lib_error_warning.php']); +} + +?> \ No newline at end of file Index: t3lib/error/interface.t3lib_error_errorhandlerinterface.php =================================================================== --- t3lib/error/interface.t3lib_error_errorhandlerinterface.php (revision 0) +++ t3lib/error/interface.t3lib_error_errorhandlerinterface.php (revision 0) @@ -0,0 +1,64 @@ + +* All rights reserved +* +* This script is part of the TYPO3 project. The TYPO3 project is +* free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation; either version 2 of the License, or +* (at your option) any later version. +* +* The GNU General Public License can be found at +* http://www.gnu.org/copyleft/gpl.html. +* +* This script is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* This copyright notice MUST APPEAR in all copies of the script! +***************************************************************/ + + + +/** + * Error handler interface for TYPO3 + * + * This file is a backport from FLOW3 + * + * @package TYPO3 + * @subpackage t3lib_error + * @version $Id: ErrorHandlerInterface.php 3195 2009-09-17 11:27:14Z k-fish $ + */ +interface t3lib_error_ErrorHandlerInterface { + + /** + * Constructs this error handler - registers itself as the default error handler. + */ + public function __construct(); + + /** + * Defines which error levels result should result in an exception thrown. + * + * @param array $exceptionalErrors An array of E_* error levels + * @return void + */ + public function setExceptionalErrors(array $exceptionalErrors); + + /** + * Handles an error by converting it into an exception + * + * @param integer $errorLevel The error level - one of the E_* constants + * @param string $errorMessage The error message + * @param string $errorFile Name of the file the error occurred in + * @param integer $errorLine Line number where the error occurred + * @return void + * @throws t3lib_error_Exception with the data passed to this method + */ + public function handleError($errorLevel, $errorMessage, $errorFile, $errorLine); +} + +?> \ No newline at end of file Index: t3lib/error/interface.t3lib_error_exceptionhandlerinterface.php =================================================================== --- t3lib/error/interface.t3lib_error_exceptionhandlerinterface.php (revision 0) +++ t3lib/error/interface.t3lib_error_exceptionhandlerinterface.php (revision 0) @@ -0,0 +1,53 @@ + +* All rights reserved +* +* This script is part of the TYPO3 project. The TYPO3 project is +* free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation; either version 2 of the License, or +* (at your option) any later version. +* +* The GNU General Public License can be found at +* http://www.gnu.org/copyleft/gpl.html. +* +* This script is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* This copyright notice MUST APPEAR in all copies of the script! +***************************************************************/ + + + +/** + * Contract for an exception handler + * + * This file is a backport from FLOW3 + * + * @package TYPO3 + * @subpackage t3lib_error + * @version $Id: t3lib_error_ExceptionHandlerInterface.php 2813 2009-07-16 14:02:34Z k-fish $ + */ +interface t3lib_error_ExceptionHandlerInterface { + + /** + * Constructs this exception handler - registers itself as the default exception handler. + */ + public function __construct(); + + /** + * Handles the given exception + * + * @param Exception $exception: The exception object + * @return void + */ + public function handleException(Exception $exception); + +} + +?> \ No newline at end of file Index: t3lib/config_default.php =================================================================== --- t3lib/config_default.php (revision 6024) +++ t3lib/config_default.php (working copy) @@ -153,6 +153,13 @@ ) ), 'useCachingFramework' => 0, // Boolean: Enable this if you want to use the caching framework by default for the core caches cache_pages, cache_pagesection and cache_hash. + 'exceptionHandler' => 't3lib_error_ProductionExceptionHandler', + 'errorHandler' => 't3lib_error_ErrorHandler', + 'exceptionalErrors' => array( + E_USER_ERROR, + E_RECOVERABLE_ERROR + ), + ), 'EXT' => Array ( // Options related to the Extension Management 'noEdit' => 1, // Boolean: If set, the Extension Manager does NOT allow extension files to be edited! (Otherwise both local and global extensions can be edited.) @@ -488,6 +495,11 @@ @ini_set('display_errors', $displayErrors); } + // Error & Exceptionhandling +if ($displayErrors == 1) { + $TYPO3_CONF_VARS['SYS']['exceptionHandler'] = 't3lib_error_DebugExceptionHandler'; +} + // Set PHP memory limit depending on value of $TYPO3_CONF_VARS["SYS"]["setMemoryLimit"] if(intval($TYPO3_CONF_VARS["SYS"]["setMemoryLimit"])>16) { @ini_set('memory_limit',intval($TYPO3_CONF_VARS["SYS"]["setMemoryLimit"]).'m');