PageRenderTime 61ms CodeModel.GetById 30ms RepoModel.GetById 0ms app.codeStats 0ms

/libraries/legacy/error/error.php

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