[ Index ] |
PHP Cross Reference of Joomla 4.2.2 documentation |
[Summary view] [Print] [Text view]
1 <?php 2 /* 3 * This file is part of the DebugBar package. 4 * 5 * (c) 2013 Maxime Bouroumeau-Fuseau 6 * 7 * For the full copyright and license information, please view the LICENSE 8 * file that was distributed with this source code. 9 */ 10 11 namespace DebugBar\DataCollector; 12 13 use Exception; 14 use Symfony\Component\Debug\Exception\FatalThrowableError; 15 16 /** 17 * Collects info about exceptions 18 */ 19 class ExceptionsCollector extends DataCollector implements Renderable 20 { 21 protected $exceptions = array(); 22 protected $chainExceptions = false; 23 24 // The HTML var dumper requires debug bar users to support the new inline assets, which not all 25 // may support yet - so return false by default for now. 26 protected $useHtmlVarDumper = false; 27 28 /** 29 * Adds an exception to be profiled in the debug bar 30 * 31 * @param Exception $e 32 * @deprecated in favor on addThrowable 33 */ 34 public function addException(Exception $e) 35 { 36 $this->addThrowable($e); 37 } 38 39 /** 40 * Adds a Throwable to be profiled in the debug bar 41 * 42 * @param \Throwable $e 43 */ 44 public function addThrowable($e) 45 { 46 $this->exceptions[] = $e; 47 if ($this->chainExceptions && $previous = $e->getPrevious()) { 48 $this->addThrowable($previous); 49 } 50 } 51 52 /** 53 * Configure whether or not all chained exceptions should be shown. 54 * 55 * @param bool $chainExceptions 56 */ 57 public function setChainExceptions($chainExceptions = true) 58 { 59 $this->chainExceptions = $chainExceptions; 60 } 61 62 /** 63 * Returns the list of exceptions being profiled 64 * 65 * @return array[\Throwable] 66 */ 67 public function getExceptions() 68 { 69 return $this->exceptions; 70 } 71 72 /** 73 * Sets a flag indicating whether the Symfony HtmlDumper will be used to dump variables for 74 * rich variable rendering. 75 * 76 * @param bool $value 77 * @return $this 78 */ 79 public function useHtmlVarDumper($value = true) 80 { 81 $this->useHtmlVarDumper = $value; 82 return $this; 83 } 84 85 /** 86 * Indicates whether the Symfony HtmlDumper will be used to dump variables for rich variable 87 * rendering. 88 * 89 * @return mixed 90 */ 91 public function isHtmlVarDumperUsed() 92 { 93 return $this->useHtmlVarDumper; 94 } 95 96 public function collect() 97 { 98 return array( 99 'count' => count($this->exceptions), 100 'exceptions' => array_map(array($this, 'formatThrowableData'), $this->exceptions) 101 ); 102 } 103 104 /** 105 * Returns exception data as an array 106 * 107 * @param Exception $e 108 * @return array 109 * @deprecated in favor on formatThrowableData 110 */ 111 public function formatExceptionData(Exception $e) 112 { 113 return $this->formatThrowableData($e); 114 } 115 116 /** 117 * Returns Throwable data as an array 118 * 119 * @param \Throwable $e 120 * @return array 121 */ 122 public function formatThrowableData($e) 123 { 124 $filePath = $e->getFile(); 125 if ($filePath && file_exists($filePath)) { 126 $lines = file($filePath); 127 $start = $e->getLine() - 4; 128 $lines = array_slice($lines, $start < 0 ? 0 : $start, 7); 129 } else { 130 $lines = array("Cannot open the file ($filePath) in which the exception occurred "); 131 } 132 133 $traceHtml = null; 134 if ($this->isHtmlVarDumperUsed()) { 135 $traceHtml = $this->getVarDumper()->renderVar($e->getTrace()); 136 } 137 138 return array( 139 'type' => get_class($e), 140 'message' => $e->getMessage(), 141 'code' => $e->getCode(), 142 'file' => $filePath, 143 'line' => $e->getLine(), 144 'stack_trace' => $e->getTraceAsString(), 145 'stack_trace_html' => $traceHtml, 146 'surrounding_lines' => $lines, 147 'xdebug_link' => $this->getXdebugLink($filePath, $e->getLine()) 148 ); 149 } 150 151 /** 152 * @return string 153 */ 154 public function getName() 155 { 156 return 'exceptions'; 157 } 158 159 /** 160 * @return array 161 */ 162 public function getWidgets() 163 { 164 return array( 165 'exceptions' => array( 166 'icon' => 'bug', 167 'widget' => 'PhpDebugBar.Widgets.ExceptionsWidget', 168 'map' => 'exceptions.exceptions', 169 'default' => '[]' 170 ), 171 'exceptions:badge' => array( 172 'map' => 'exceptions.count', 173 'default' => 'null' 174 ) 175 ); 176 } 177 }
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 |