[FEATURE] Create an Exception hierarchy for HTTP Status Exceptions
[Packages/TYPO3.CMS.git] / t3lib / error / class.t3lib_error_productionexceptionhandler.php
1 <?php
2 /***************************************************************
3 * Copyright notice
4 *
5 * (c) 2009-2011 Ingo Renner <ingo@typo3.org>
6 * All rights reserved
7 *
8 * This script is part of the TYPO3 project. The TYPO3 project is
9 * free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * The GNU General Public License can be found at
15 * http://www.gnu.org/copyleft/gpl.html.
16 *
17 * This script is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
21 *
22 * This copyright notice MUST APPEAR in all copies of the script!
23 ***************************************************************/
24
25
26 /**
27 * A quite exception handler which catches but ignores any exception.
28 *
29 * This file is a backport from FLOW3
30 *
31 * @package TYPO3
32 * @subpackage t3lib_error
33 */
34 class t3lib_error_ProductionExceptionHandler extends t3lib_error_AbstractExceptionHandler {
35
36 /**
37 * Constructs this exception handler - registers itself as the default exception handler.
38 *
39 * @author Robert Lemke <robert@typo3.org>
40 */
41 public function __construct() {
42 set_exception_handler(array($this, 'handleException'));
43 }
44
45 /**
46 * Echoes an exception for the web.
47 *
48 * @param Exception $exception The exception
49 * @return void
50 */
51 public function echoExceptionWeb(Exception $exception) {
52 $this->sendStatusHeaders($exception);
53
54 $this->writeLogEntries($exception, self::CONTEXT_WEB);
55
56 if ($exception->getCode() > 0) {
57 $moreInformationLink = '<p>More information regarding this error might be available <a href="'
58 . TYPO3_URL_EXCEPTION . $exception->getCode() . '" target="_blank">online</a>.</p>';
59 } else {
60 $moreInformationLink = '';
61 }
62
63 $title = 'Oops, an error occurred!';
64
65 if (method_exists($exception, 'getTitle') && strlen($exception->getTitle()) > 0) {
66 $title = $exception->getTitle();
67 }
68 // we use a nice-looking title for our visitors instead of the exception's class name
69 $messageObj = t3lib_div::makeInstance('t3lib_message_ErrorPageMessage', $exception->getMessage() . $moreInformationLink, $title);
70 $messageObj->output();
71 }
72
73 /**
74 * Echoes an exception for the command line.
75 *
76 * @param Exception $exception The exception
77 * @return void
78 */
79 public function echoExceptionCLI(Exception $exception) {
80 $this->writeLogEntries($exception, self::CONTEXT_CLI);
81 exit(1);
82 }
83 }
84
85 if (defined('TYPO3_MODE') && isset($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['t3lib/error/class.t3lib_error_productionexceptionhandler.php'])) {
86 include_once($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['t3lib/error/class.t3lib_error_productionexceptionhandler.php']);
87 }
88
89 ?>