PageRenderTime 37ms CodeModel.GetById 18ms app.highlight 14ms RepoModel.GetById 1ms app.codeStats 0ms

/libraries/joomla/error/error.php

https://bitbucket.org/organicdevelopment/joomla-2.5
PHP | 910 lines | 394 code | 102 blank | 414 comment | 40 complexity | 29e783247b2bc2d91a91d932992177f7 MD5 | raw file
  1<?php
  2/**
  3 * @package     Joomla.Platform
  4 * @subpackage  Error
  5 *
  6 * @copyright   Copyright (C) 2005 - 2012 Open Source Matters, Inc. All rights reserved.
  7 * @license     GNU General Public License version 2 or later; see LICENSE
  8 */
  9
 10defined('JPATH_PLATFORM') or die;
 11
 12// Error Definition: Illegal Options
 13define('JERROR_ILLEGAL_OPTIONS', 1);
 14// Error Definition: Callback does not exist
 15define('JERROR_CALLBACK_NOT_CALLABLE', 2);
 16// Error Definition: Illegal Handler
 17define('JERROR_ILLEGAL_MODE', 3);
 18
 19/**
 20 * Error Handling Class
 21 *
 22 * This class is inspired in design and concept by patErrorManager <http://www.php-tools.net>
 23 *
 24 * patErrorManager contributors include:
 25 * - gERD Schaufelberger	<gerd@php-tools.net>
 26 * - Sebastian Mordziol	<argh@php-tools.net>
 27 * - Stephan Schmidt		<scst@php-tools.net>
 28 *
 29 * @package     Joomla.Platform
 30 * @subpackage  Error
 31 * @since       11.1
 32 * @deprecated  12.1   Use PHP Exception
 33 */
 34abstract class JError
 35{
 36	/**
 37	 * Legacy error handling marker
 38	 *
 39	 * @var    boolean  True to enable legacy error handling using JError, false to use exception handling.  This flag
 40	 *                  is present to allow an easy transition into exception handling for code written against the
 41	 *                  existing JError API in Joomla.
 42	 * @since  11.1
 43	 */
 44	public static $legacy = false;
 45
 46	/**
 47	 * Array of message levels
 48	 *
 49	 * @var    array
 50	 * @since  11.1
 51	 */
 52	protected static $levels = array(E_NOTICE => 'Notice', E_WARNING => 'Warning', E_ERROR => 'Error');
 53
 54	protected static $handlers = array(
 55		E_NOTICE => array('mode' => 'ignore'),
 56		E_WARNING => array('mode' => 'ignore'),
 57		E_ERROR => array('mode' => 'ignore')
 58	);
 59
 60	protected static $stack = array();
 61
 62	/**
 63	 * Method to determine if a value is an exception object.  This check supports
 64	 * both JException and PHP5 Exception objects
 65	 *
 66	 * @param   mixed  &$object  Object to check
 67	 *
 68	 * @return  boolean  True if argument is an exception, false otherwise.
 69	 *
 70	 * @since   11.1
 71	 *
 72	 * @deprecated  12.1
 73	 */
 74	public static function isError(& $object)
 75	{
 76		// Deprecation warning.
 77		JLog::add('JError::isError() is deprecated.', JLog::WARNING, 'deprecated');
 78
 79		// Supports PHP 5 exception handling
 80		return $object instanceof Exception;
 81	}
 82
 83	/**
 84	 * Method for retrieving the last exception object in the error stack
 85	 *
 86	 * @param   boolean  $unset  True to remove the error from the stack.
 87	 *
 88	 * @return  mixed  Last exception object in the error stack or boolean false if none exist
 89	 *
 90	 * @deprecated  12.1
 91	 * @since   11.1
 92	 */
 93	public static function getError($unset = false)
 94	{
 95		// Deprecation warning.
 96		JLog::add('JError::getError() is deprecated.', JLog::WARNING, 'deprecated');
 97
 98		if (!isset(JError::$stack[0]))
 99		{
100			return false;
101		}
102
103		if ($unset)
104		{
105			$error = array_shift(JError::$stack);
106		}
107		else
108		{
109			$error = &JError::$stack[0];
110		}
111		return $error;
112	}
113
114	/**
115	 * Method for retrieving the exception stack
116	 *
117	 * @return  array  Chronological array of errors that have been stored during script execution
118	 *
119	 * @deprecated  12.1
120	 * @since   11.1
121	 */
122	public static function getErrors()
123	{
124		// Deprecation warning.
125		JLog::add('JError::getErrors() is deprecated.', JLog::WARNING, 'deprecated');
126
127		return JError::$stack;
128	}
129
130	/**
131	 * Method to add non-JError thrown JExceptions to the JError stack for debugging purposes
132	 *
133	 * @param   JException  &$e  Add an exception to the stack.
134	 *
135	 * @return  void
136	 *
137	 * @since       11.1
138	 * @deprecated  12.1
139	 */
140	public static function addToStack(JException &$e)
141	{
142		// Deprecation warning.
143		JLog::add('JError::addToStack() is deprecated.', JLog::WARNING, 'deprecated');
144
145		JError::$stack[] = &$e;
146	}
147
148	/**
149	 * Create a new JException object given the passed arguments
150	 *
151	 * @param   integer  $level      The error level - use any of PHP's own error levels for
152	 *                               this: E_ERROR, E_WARNING, E_NOTICE, E_USER_ERROR,
153	 *                               E_USER_WARNING, E_USER_NOTICE.
154	 * @param   string   $code       The application-internal error code for this error
155	 * @param   string   $msg        The error message, which may also be shown the user if need be.
156	 * @param   mixed    $info       Optional: Additional error information (usually only
157	 *                               developer-relevant information that the user should never see,
158	 *                               like a database DSN).
159	 * @param   boolean  $backtrace  Add a stack backtrace to the exception.
160	 *
161	 * @return  mixed    The JException object
162	 *
163	 * @since       11.1
164	 * @deprecated  12.1  Use PHP Exception
165	 * @see         JException
166	 */
167	public static function raise($level, $code, $msg, $info = null, $backtrace = false)
168	{
169		// Deprecation warning.
170		JLog::add('JError::raise() is deprecated.', JLog::WARNING, 'deprecated');
171
172		jimport('joomla.error.exception');
173
174		// Build error object
175		$exception = new JException($msg, $code, $level, $info, $backtrace);
176		return JError::throwError($exception);
177	}
178
179	/**
180	 * Throw an error
181	 *
182	 * @param   object  &$exception  An exception to throw.
183	 *
184	 * @return  reference
185	 *
186	 * @deprecated  12.1  Use PHP Exception
187	 * @see     JException
188	 * @since   11.1
189	 */
190	public static function throwError(&$exception)
191	{
192		// Deprecation warning.
193		JLog::add('JError::throwError() is deprecated.', JLog::WARNING, 'deprecated');
194
195		static $thrown = false;
196
197		// If thrown is hit again, we've come back to JError in the middle of throwing another JError, so die!
198		if ($thrown)
199		{
200			self::handleEcho($exception, array());
201			// Inifite loop.
202			jexit();
203		}
204
205		$thrown = true;
206		$level = $exception->get('level');
207
208		// See what to do with this kind of error
209		$handler = JError::getErrorHandling($level);
210
211		$function = 'handle' . ucfirst($handler['mode']);
212		if (is_callable(array('JError', $function)))
213		{
214			$reference = call_user_func_array(array('JError', $function), array(&$exception, (isset($handler['options'])) ? $handler['options'] : array()));
215		}
216		else
217		{
218			// This is required to prevent a very unhelpful white-screen-of-death
219			jexit(
220				'JError::raise -> Static method JError::' . $function . ' does not exist.' . ' Contact a developer to debug' .
221				'<br /><strong>Error was</strong> ' . '<br />' . $exception->getMessage()
222			);
223		}
224		// We don't need to store the error, since JException already does that for us!
225		// Remove loop check
226		$thrown = false;
227
228		return $reference;
229	}
230
231	/**
232	 * Wrapper method for the raise() method with predefined error level of E_ERROR and backtrace set to true.
233	 *
234	 * @param   string  $code  The application-internal error code for this error
235	 * @param   string  $msg   The error message, which may also be shown the user if need be.
236	 * @param   mixed   $info  Optional: Additional error information (usually only
237	 *                         developer-relevant information that the user should
238	 *                         never see, like a database DSN).
239	 *
240	 * @return  object  $error  The configured JError object
241	 *
242	 * @deprecated   12.1       Use PHP Exception
243	 * @see        raise()
244	 * @since   11.1
245	 */
246	public static function raiseError($code, $msg, $info = null)
247	{
248		// Deprecation warning.
249		JLog::add('JError::raiseError() is deprecated.', JLog::WARNING, 'deprecated');
250
251		return JError::raise(E_ERROR, $code, $msg, $info, true);
252	}
253
254	/**
255	 * Wrapper method for the {@link raise()} method with predefined error level of E_WARNING and
256	 * backtrace set to false.
257	 *
258	 * @param   string  $code  The application-internal error code for this error
259	 * @param   string  $msg   The error message, which may also be shown the user if need be.
260	 * @param   mixed   $info  Optional: Additional error information (usually only
261	 *                         developer-relevant information that
262	 *                         the user should never see, like a database DSN).
263	 *
264	 * @return  object  The configured JError object
265	 *
266	 * @deprecated  12.1  Use PHP Exception
267	 * @see        JError
268	 * @see        raise()
269	 * @since      11.1
270	 */
271	public static function raiseWarning($code, $msg, $info = null)
272	{
273		// Deprecation warning.
274		JLog::add('JError::raiseWarning() is deprecated.', JLog::WARNING, 'deprecated');
275
276		return JError::raise(E_WARNING, $code, $msg, $info);
277	}
278
279	/**
280	 * Wrapper method for the {@link raise()} method with predefined error
281	 * level of E_NOTICE and backtrace set to false.
282	 *
283	 * @param   string  $code  The application-internal error code for this error
284	 * @param   string  $msg   The error message, which may also be shown the user if need be.
285	 * @param   mixed   $info  Optional: Additional error information (usually only
286	 *                         developer-relevant information that the user
287	 *                         should never see, like a database DSN).
288	 *
289	 * @return  object   The configured JError object
290	 *
291	 * @deprecated       12.1   Use PHP Exception
292	 * @see     raise()
293	 * @since   11.1
294	 */
295	public static function raiseNotice($code, $msg, $info = null)
296	{
297		// Deprecation warning.
298		JLog::add('JError::raiseNotice() is deprecated.', JLog::WARNING, 'deprecated');
299
300		return JError::raise(E_NOTICE, $code, $msg, $info);
301	}
302
303	/**
304	 * Method to get the current error handler settings for a specified error level.
305	 *
306	 * @param   integer  $level  The error level to retrieve. This can be any of PHP's
307	 *                           own error levels, e.g. E_ALL, E_NOTICE...
308	 *
309	 * @return  array    All error handling details
310	 *
311	 * @deprecated   12.1  Use PHP Exception
312	 * @since   11.1
313	 */
314	public static function getErrorHandling($level)
315	{
316		// Deprecation warning.
317		JLog::add('JError::getErrorHandling() is deprecated.', JLog::WARNING, 'deprecated');
318
319		return JError::$handlers[$level];
320	}
321
322	/**
323	 * Method to set the way the JError will handle different error levels. Use this if you want to override the default settings.
324	 *
325	 * Error handling modes:
326	 * - ignore
327	 * - echo
328	 * - verbose
329	 * - die
330	 * - message
331	 * - log
332	 * - callback
333	 *
334	 * You may also set the error handling for several modes at once using PHP's bit operations.
335	 * Examples:
336	 * - E_ALL = Set the handling for all levels
337	 * - E_ERROR | E_WARNING = Set the handling for errors and warnings
338	 * - E_ALL ^ E_ERROR = Set the handling for all levels except errors
339	 *
340	 * @param   integer  $level    The error level for which to set the error handling
341	 * @param   string   $mode     The mode to use for the error handling.
342	 * @param   mixed    $options  Optional: Any options needed for the given mode.
343	 *
344	 * @return  mixed  True on success or a JException object if failed.
345	 *
346	 * @deprecated  12.1  Use PHP Exception
347	 * @since   11.1
348	 */
349	public static function setErrorHandling($level, $mode, $options = null)
350	{
351		// Deprecation warning.
352		JLog::add('JError::setErrorHandling() is deprecated.', JLog::WARNING, 'deprecated');
353
354		$levels = JError::$levels;
355
356		$function = 'handle' . ucfirst($mode);
357
358		if (!is_callable(array('JError', $function)))
359		{
360			return JError::raiseError(E_ERROR, 'JError:' . JERROR_ILLEGAL_MODE, 'Error Handling mode is not known', 'Mode: ' . $mode . ' is not implemented.');
361		}
362
363		foreach ($levels as $eLevel => $eTitle)
364		{
365			if (($level & $eLevel) != $eLevel)
366			{
367				continue;
368			}
369
370			// Set callback options
371			if ($mode == 'callback')
372			{
373				if (!is_array($options))
374				{
375					return JError::raiseError(E_ERROR, 'JError:' . JERROR_ILLEGAL_OPTIONS, 'Options for callback not valid');
376				}
377
378				if (!is_callable($options))
379				{
380					$tmp = array('GLOBAL');
381					if (is_array($options))
382					{
383						$tmp[0] = $options[0];
384						$tmp[1] = $options[1];
385					}
386					else
387					{
388						$tmp[1] = $options;
389					}
390
391					return JError::raiseError(
392						E_ERROR,
393						'JError:' . JERROR_CALLBACK_NOT_CALLABLE,
394						'Function is not callable',
395						'Function:' . $tmp[1] . ' scope ' . $tmp[0] . '.'
396					);
397				}
398			}
399
400			// Save settings
401			JError::$handlers[$eLevel] = array('mode' => $mode);
402			if ($options != null)
403			{
404				JError::$handlers[$eLevel]['options'] = $options;
405			}
406		}
407
408		return true;
409	}
410
411	/**
412	 * Method that attaches the error handler to JError
413	 *
414	 * @return  void
415	 *
416	 * @deprecated  12.1
417	 * @see     set_error_handler
418	 * @since   11.1
419	 */
420	public static function attachHandler()
421	{
422		// Deprecation warning.
423		JLog::add('JError::getErrorHandling() is deprecated.', JLog::WARNING, 'deprecated');
424
425		set_error_handler(array('JError', 'customErrorHandler'));
426	}
427
428	/**
429	 * Method that detaches the error handler from JError
430	 *
431	 * @return  void
432	 *
433	 * @deprecated  12.1
434	 * @see     restore_error_handler
435	 * @since   11.1
436	 */
437	public static function detachHandler()
438	{
439		// Deprecation warning.
440		JLog::add('JError::detachHandler() is deprecated.', JLog::WARNING, 'deprecated');
441
442		restore_error_handler();
443	}
444
445	/**
446	 * Method to register a new error level for handling errors
447	 *
448	 * This allows you to add custom error levels to the built-in
449	 * - E_NOTICE
450	 * - E_WARNING
451	 * - E_NOTICE
452	 *
453	 * @param   integer  $level    Error level to register
454	 * @param   string   $name     Human readable name for the error level
455	 * @param   string   $handler  Error handler to set for the new error level [optional]
456	 *
457	 * @return  boolean  True on success; false if the level already has been registered
458	 *
459	 * @deprecated  12.1
460	 * @since   11.1
461	 */
462	public static function registerErrorLevel($level, $name, $handler = 'ignore')
463	{
464		// Deprecation warning.
465		JLog::add('JError::registerErrorLevel() is deprecated.', JLog::WARNING, 'deprecated');
466
467		if (isset(JError::$levels[$level]))
468		{
469			return false;
470		}
471
472		JError::$levels[$level] = $name;
473		JError::setErrorHandling($level, $handler);
474
475		return true;
476	}
477
478	/**
479	 * Translate an error level integer to a human readable string
480	 * e.g. E_ERROR will be translated to 'Error'
481	 *
482	 * @param   integer  $level  Error level to translate
483	 *
484	 * @return  mixed  Human readable error level name or boolean false if it doesn't exist
485	 *
486	 * @deprecated  12.1
487	 * @since   11.1
488	 */
489
490	public static function translateErrorLevel($level)
491	{
492		// Deprecation warning.
493		JLog::add('JError::translateErrorLevel() is deprecated.', JLog::WARNING, 'deprecated');
494
495		if (isset(JError::$levels[$level]))
496		{
497			return JError::$levels[$level];
498		}
499
500		return false;
501	}
502
503	/**
504	 * Ignore error handler
505	 * - Ignores the error
506	 *
507	 * @param   object  &$error   Exception object to handle
508	 * @param   array   $options  Handler options
509	 *
510	 * @return  object   The exception object
511	 *
512	 * @deprecated  12.1
513	 * @see     raise()
514	 * @since   11.1
515	 */
516	public static function handleIgnore(&$error, $options)
517	{
518		// Deprecation warning.
519		JLog::add('JError::handleIgnore() is deprecated.', JLog::WARNING, 'deprecated');
520
521		return $error;
522	}
523
524	/**
525	 * Echo error handler
526	 * - Echos the error message to output
527	 *
528	 * @param   object  &$error   Exception object to handle
529	 * @param   array   $options  Handler options
530	 *
531	 * @return  object  The exception object
532	 *
533	 * @deprecated  12.1
534	 * @see         raise()
535	 * @since       11.1
536	 */
537	public static function handleEcho(&$error, $options)
538	{
539		// Deprecation warning.
540		JLog::add('JError::handleEcho() is deprecated.', JLog::WARNING, 'deprecated');
541
542		$level_human = JError::translateErrorLevel($error->get('level'));
543
544		// If system debug is set, then output some more information.
545		if (defined('JDEBUG'))
546		{
547			$backtrace = $error->getTrace();
548			$trace = '';
549			for ($i = count($backtrace) - 1; $i >= 0; $i--)
550			{
551				if (isset($backtrace[$i]['class']))
552				{
553					$trace .= sprintf("\n%s %s %s()", $backtrace[$i]['class'], $backtrace[$i]['type'], $backtrace[$i]['function']);
554				}
555				else
556				{
557					$trace .= sprintf("\n%s()", $backtrace[$i]['function']);
558				}
559
560				if (isset($backtrace[$i]['file']))
561				{
562					$trace .= sprintf(' @ %s:%d', $backtrace[$i]['file'], $backtrace[$i]['line']);
563				}
564			}
565		}
566
567		if (isset($_SERVER['HTTP_HOST']))
568		{
569			// output as html
570			echo "<br /><b>jos-$level_human</b>: "
571				. $error->get('message') . "<br />\n"
572				. (defined('JDEBUG') ? nl2br($trace) : '');
573		}
574		else
575		{
576			// Output as simple text
577			if (defined('STDERR'))
578			{
579				fwrite(STDERR, "J$level_human: " . $error->get('message') . "\n");
580				if (defined('JDEBUG'))
581				{
582					fwrite(STDERR, $trace);
583				}
584			}
585			else
586			{
587				echo "J$level_human: " . $error->get('message') . "\n";
588				if (defined('JDEBUG'))
589				{
590					echo $trace;
591				}
592			}
593		}
594
595		return $error;
596	}
597
598	/**
599	 * Verbose error handler
600	 * - Echos the error message to output as well as related info
601	 *
602	 * @param   object  &$error   Exception object to handle
603	 * @param   array   $options  Handler options
604	 *
605	 * @return  object  The exception object
606	 *
607	 * @deprecated  12.1
608	 * @see         raise()
609	 * @since       11.1
610	 */
611	public static function handleVerbose(&$error, $options)
612	{
613		// Deprecation warning.
614		JLog::add('JError::handleVerbose() is deprecated.', JLog::WARNING, 'deprecated');
615
616		$level_human = JError::translateErrorLevel($error->get('level'));
617		$info = $error->get('info');
618
619		if (isset($_SERVER['HTTP_HOST']))
620		{
621			// Output as html
622			echo "<br /><b>J$level_human</b>: " . $error->get('message') . "<br />\n";
623
624			if ($info != null)
625			{
626				echo "&#160;&#160;&#160;" . $info . "<br />\n";
627			}
628
629			echo $error->getBacktrace(true);
630		}
631		else
632		{
633			// Output as simple text
634			echo "J$level_human: " . $error->get('message') . "\n";
635			if ($info != null)
636			{
637				echo "\t" . $info . "\n";
638			}
639
640		}
641
642		return $error;
643	}
644
645	/**
646	 * Die error handler
647	 * - Echos the error message to output and then dies
648	 *
649	 * @param   object  &$error   Exception object to handle
650	 * @param   array   $options  Handler options
651	 *
652	 * @return  object  The exception object
653	 *
654	 * @deprecated  12.1
655	 * @see         raise()
656	 * @since       11.1
657	 */
658	public static function handleDie(&$error, $options)
659	{
660		// Deprecation warning.
661		JLog::add('JError::handleDie() is deprecated.', JLog::WARNING, 'deprecated');
662
663		$level_human = JError::translateErrorLevel($error->get('level'));
664
665		if (isset($_SERVER['HTTP_HOST']))
666		{
667			// Output as html
668			jexit("<br /><b>J$level_human</b>: " . $error->get('message') . "<br />\n");
669		}
670		else
671		{
672			// Output as simple text
673			if (defined('STDERR'))
674			{
675				fwrite(STDERR, "J$level_human: " . $error->get('message') . "\n");
676				jexit();
677			}
678			else
679			{
680				jexit("J$level_human: " . $error->get('message') . "\n");
681			}
682		}
683
684		return $error;
685	}
686
687	/**
688	 * Message error handler
689	 * Enqueues the error message into the system queue
690	 *
691	 * @param   object  &$error   Exception object to handle
692	 * @param   array   $options  Handler options
693	 *
694	 * @return  object  The exception object
695	 *
696	 * @deprecated  12.1
697	 * @see         raise()
698	 * @since       11.1
699	 */
700	public static function handleMessage(&$error, $options)
701	{
702		// Deprecation warning.
703		JLog::add('JError::handleMessage() is deprecated.', JLog::WARNING, 'deprecated');
704
705		$appl = JFactory::getApplication();
706		$type = ($error->get('level') == E_NOTICE) ? 'notice' : 'error';
707		$appl->enqueueMessage($error->get('message'), $type);
708
709		return $error;
710	}
711
712	/**
713	 * Log error handler
714	 * Logs the error message to a system log file
715	 *
716	 * @param   object  &$error   Exception object to handle
717	 * @param   array   $options  Handler options
718	 *
719	 * @return  object  The exception object
720	 *
721	 * @deprecated  12.1
722	 * @see         raise()
723	 * @since       11.1
724	 */
725	public static function handleLog(&$error, $options)
726	{
727		// Deprecation warning.
728		JLog::add('JError::handleLog() is deprecated.', JLog::WARNING, 'deprecated');
729
730		static $log;
731
732		if ($log == null)
733		{
734			$fileName = date('Y-m-d') . '.error.log';
735			$options['format'] = "{DATE}\t{TIME}\t{LEVEL}\t{CODE}\t{MESSAGE}";
736			$log = JLog::getInstance($fileName, $options);
737		}
738
739		$entry['level'] = $error->get('level');
740		$entry['code'] = $error->get('code');
741		$entry['message'] = str_replace(array("\r", "\n"), array('', '\\n'), $error->get('message'));
742		$log->addEntry($entry);
743
744		return $error;
745	}
746
747	/**
748	 * Callback error handler
749	 * - Send the error object to a callback method for error handling
750	 *
751	 * @param   object  &$error   Exception object to handle
752	 * @param   array   $options  Handler options
753	 *
754	 * @return  object  The exception object
755	 *
756	 * @deprecated  12.1
757	 * @see         raise()
758	 * @since       11.1
759	 */
760	public static function handleCallback(&$error, $options)
761	{
762		// Deprecation warning.
763		JLog::add('JError::handleCallback() is deprecated.', JLog::WARNING, 'deprecated');
764
765		return call_user_func($options, $error);
766	}
767
768	/**
769	 * Display a custom error page and exit gracefully
770	 *
771	 * @param   object  &$error  Exception object
772	 *
773	 * @return  void
774	 *
775	 * @deprecated  12.1
776	 * @since   11.1
777	 */
778	public static function customErrorPage(&$error)
779	{
780		// Deprecation warning.
781		JLog::add('JError::customErrorPage() is deprecated.', JLog::WARNING, 'deprecated');
782
783		// Initialise variables.
784		$app = JFactory::getApplication();
785		$document = JDocument::getInstance('error');
786		if ($document)
787		{
788			$config = JFactory::getConfig();
789
790			// Get the current template from the application
791			$template = $app->getTemplate();
792
793			// Push the error object into the document
794			$document->setError($error);
795
796			@ob_end_clean();
797			$document->setTitle(JText::_('Error') . ': ' . $error->get('code'));
798			$data = $document->render(false, array('template' => $template, 'directory' => JPATH_THEMES, 'debug' => $config->get('debug')));
799
800			// Failsafe to get the error displayed.
801			if (empty($data))
802			{
803				self::handleEcho($error, array());
804			}
805			else
806			{
807				// Do not allow cache
808				JResponse::allowCache(false);
809
810				JResponse::setBody($data);
811				echo JResponse::toString();
812			}
813		}
814		else
815		{
816			// Just echo the error since there is no document
817			// This is a common use case for Command Line Interface applications.
818			self::handleEcho($error, array());
819		}
820		$app->close(0);
821	}
822
823	/**
824	 * Display a message to the user
825	 *
826	 * @param   integer  $level  The error level - use any of PHP's own error levels
827	 *                   for this: E_ERROR, E_WARNING, E_NOTICE, E_USER_ERROR,
828	 *                   E_USER_WARNING, E_USER_NOTICE.
829	 * @param   string   $msg    Error message, shown to user if need be.
830	 *
831	 * @return  void
832	 *
833	 * @deprecated  12.1
834	 * @since   11.1
835	 */
836	public static function customErrorHandler($level, $msg)
837	{
838		// Deprecation warning.
839		JLog::add('JError::customErrorHandler() is deprecated.', JLog::WARNING, 'deprecated');
840
841		JError::raise($level, '', $msg);
842	}
843
844	/**
845	 * Render the backtrace
846	 *
847	 * @param   integer  $error  The error
848	 *
849	 * @return  string  Contents of the backtrace
850	 *
851	 * @deprecated  12.1
852	 * @since   11.1
853	 */
854	public static function renderBacktrace($error)
855	{
856		// Deprecation warning.
857		JLog::add('JError::renderBacktrace() is deprecated.', JLog::WARNING, 'deprecated');
858
859		$contents = null;
860		$backtrace = $error->getTrace();
861
862		if (is_array($backtrace))
863		{
864			ob_start();
865			$j = 1;
866			echo '<table cellpadding="0" cellspacing="0" class="Table">';
867			echo '		<tr>';
868			echo '				<td colspan="3" class="TD"><strong>Call stack</strong></td>';
869			echo '		</tr>';
870			echo '		<tr>';
871			echo '				<td class="TD"><strong>#</strong></td>';
872			echo '				<td class="TD"><strong>Function</strong></td>';
873			echo '				<td class="TD"><strong>Location</strong></td>';
874			echo '		</tr>';
875
876			for ($i = count($backtrace) - 1; $i >= 0; $i--)
877			{
878				echo '		<tr>';
879				echo '				<td class="TD">' . $j . '</td>';
880
881				if (isset($backtrace[$i]['class']))
882				{
883					echo '		<td class="TD">' . $backtrace[$i]['class'] . $backtrace[$i]['type'] . $backtrace[$i]['function'] . '()</td>';
884				}
885				else
886				{
887					echo '		<td class="TD">' . $backtrace[$i]['function'] . '()</td>';
888				}
889
890				if (isset($backtrace[$i]['file']))
891				{
892					echo '				<td class="TD">' . $backtrace[$i]['file'] . ':' . $backtrace[$i]['line'] . '</td>';
893				}
894				else
895				{
896					echo '				<td class="TD">&#160;</td>';
897				}
898
899				echo '		</tr>';
900				$j++;
901			}
902
903			echo '</table>';
904			$contents = ob_get_contents();
905			ob_end_clean();
906		}
907
908		return $contents;
909	}
910}