PageRenderTime 55ms CodeModel.GetById 22ms RepoModel.GetById 1ms app.codeStats 0ms

/libraries/joomla/error/error.php

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