[ Index ] |
PHP Cross Reference of Joomla 4.2.2 documentation |
[Summary view] [Print] [Text view]
1 <?php 2 3 /** 4 * Joomla! Content Management System 5 * 6 * @copyright (C) 2006 Open Source Matters, Inc. <https://www.joomla.org> 7 * @license GNU General Public License version 2 or later; see LICENSE.txt 8 */ 9 10 namespace Joomla\CMS\Document; 11 12 use Joomla\CMS\Factory as CmsFactory; 13 use Joomla\CMS\Layout\LayoutHelper; 14 15 // phpcs:disable PSR1.Files.SideEffects 16 \defined('JPATH_PLATFORM') or die; 17 // phpcs:enable PSR1.Files.SideEffects 18 19 /** 20 * ErrorDocument class, provides an easy interface to parse and display an HTML based error page 21 * 22 * @since 1.7.0 23 */ 24 class ErrorDocument extends HtmlDocument 25 { 26 /** 27 * Flag if debug mode has been enabled 28 * 29 * @var boolean 30 * @since 1.7.0 31 */ 32 public $debug = false; 33 34 /** 35 * Error Object 36 * 37 * @var \Throwable 38 * @since 1.7.0 39 */ 40 public $error; 41 42 /** 43 * Error Object 44 * 45 * @var \Throwable 46 * @since 1.7.0 47 */ 48 protected $_error; 49 50 /** 51 * Class constructor 52 * 53 * @param array $options Associative array of attributes 54 * 55 * @since 1.7.0 56 */ 57 public function __construct($options = array()) 58 { 59 parent::__construct($options); 60 61 // Set document type 62 $this->_type = 'error'; 63 } 64 65 /** 66 * Set error object 67 * 68 * @param \Throwable $error Error object to set 69 * 70 * @return boolean True on success 71 * 72 * @since 1.7.0 73 */ 74 public function setError($error) 75 { 76 if ($error instanceof \Throwable) { 77 $this->_error = & $error; 78 79 return true; 80 } 81 82 return false; 83 } 84 85 /** 86 * Load a renderer 87 * 88 * @param string $type The renderer type 89 * 90 * @return RendererInterface 91 * 92 * @since 4.0.0 93 * @throws \RuntimeException 94 */ 95 public function loadRenderer($type) 96 { 97 // Need to force everything to go to the HTML renderers or we duplicate all the things 98 return $this->factory->createRenderer($this, $type, 'html'); 99 } 100 101 /** 102 * Render the document 103 * 104 * @param boolean $cache If true, cache the output 105 * @param array $params Associative array of attributes 106 * 107 * @return string The rendered data 108 * 109 * @since 1.7.0 110 */ 111 public function render($cache = false, $params = array()) 112 { 113 // If no error object is set return null 114 if (!isset($this->_error)) { 115 return; 116 } 117 118 // Set the status header 119 $status = $this->_error->getCode(); 120 121 if ($status < 400 || $status > 599) { 122 $status = 500; 123 } 124 125 $errorReporting = CmsFactory::getApplication()->get('error_reporting'); 126 127 if ($errorReporting === "development" || $errorReporting === "maximum") { 128 $status .= ' ' . str_replace("\n", ' ', $this->_error->getMessage()); 129 } 130 131 CmsFactory::getApplication()->setHeader('status', $status); 132 133 // Set variables 134 $this->debug = $params['debug'] ?? false; 135 $this->error = $this->_error; 136 137 $params['file'] = 'error.php'; 138 139 return parent::render($cache, $params); 140 } 141 142 /** 143 * Render the backtrace 144 * 145 * @return string The contents of the backtrace 146 * 147 * @since 1.7.0 148 */ 149 public function renderBacktrace() 150 { 151 // If no error object is set return null 152 if (!isset($this->_error)) { 153 return; 154 } 155 156 // The back trace 157 $backtrace = $this->_error->getTrace(); 158 159 // Add the position of the actual file 160 array_unshift($backtrace, array('file' => $this->_error->getFile(), 'line' => $this->_error->getLine(), 'function' => '')); 161 162 return LayoutHelper::render('joomla.error.backtrace', array('backtrace' => $backtrace)); 163 } 164 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Wed Sep 7 05:41:13 2022 | Chilli.vc Blog - For Webmaster,Blog-Writer,System Admin and Domainer |