addThrowable($e); } /** * Adds a Throwable to be profiled in the debug bar * * @param \Throwable $e */ public function addThrowable($e) { $this->exceptions[] = $e; if ($this->chainExceptions && $previous = $e->getPrevious()) { $this->addThrowable($previous); } } /** * Configure whether or not all chained exceptions should be shown. * * @param bool $chainExceptions */ public function setChainExceptions($chainExceptions = true) { $this->chainExceptions = $chainExceptions; } /** * Returns the list of exceptions being profiled * * @return array[\Throwable] */ public function getExceptions() { return $this->exceptions; } /** * Sets a flag indicating whether the Symfony HtmlDumper will be used to dump variables for * rich variable rendering. * * @param bool $value * @return $this */ public function useHtmlVarDumper($value = true) { $this->useHtmlVarDumper = $value; return $this; } /** * Indicates whether the Symfony HtmlDumper will be used to dump variables for rich variable * rendering. * * @return mixed */ public function isHtmlVarDumperUsed() { return $this->useHtmlVarDumper; } public function collect() { return array( 'count' => count($this->exceptions), 'exceptions' => array_map(array($this, 'formatThrowableData'), $this->exceptions) ); } /** * Returns exception data as an array * * @param Exception $e * @return array * @deprecated in favor on formatThrowableData */ public function formatExceptionData(Exception $e) { return $this->formatThrowableData($e); } /** * Returns Throwable data as an array * * @param \Throwable $e * @return array */ public function formatThrowableData($e) { $filePath = $e->getFile(); if ($filePath && file_exists($filePath)) { $lines = file($filePath); $start = $e->getLine() - 4; $lines = array_slice($lines, $start < 0 ? 0 : $start, 7); } else { $lines = array("Cannot open the file ($filePath) in which the exception occurred "); } $traceHtml = null; if ($this->isHtmlVarDumperUsed()) { $traceHtml = $this->getVarDumper()->renderVar($e->getTrace()); } return array( 'type' => get_class($e), 'message' => $e->getMessage(), 'code' => $e->getCode(), 'file' => $filePath, 'line' => $e->getLine(), 'stack_trace' => $e->getTraceAsString(), 'stack_trace_html' => $traceHtml, 'surrounding_lines' => $lines, 'xdebug_link' => $this->getXdebugLink($filePath, $e->getLine()) ); } /** * @return string */ public function getName() { return 'exceptions'; } /** * @return array */ public function getWidgets() { return array( 'exceptions' => array( 'icon' => 'bug', 'widget' => 'PhpDebugBar.Widgets.ExceptionsWidget', 'map' => 'exceptions.exceptions', 'default' => '[]' ), 'exceptions:badge' => array( 'map' => 'exceptions.count', 'default' => 'null' ) ); } }