mirror of
https://github.com/filp/whoops.git
synced 2026-09-15 12:16:18 +00:00
Merge pull request #387 from jonasdt/frame-args
Dump frame arguments below the source code
This commit is contained in:
+2
-1
@@ -16,7 +16,8 @@
|
||||
},
|
||||
"require-dev": {
|
||||
"phpunit/phpunit": "^4.8 || ^5.0",
|
||||
"mockery/mockery": "0.9.*"
|
||||
"mockery/mockery": "0.9.*",
|
||||
"symfony/var-dumper": "~3.0"
|
||||
},
|
||||
"suggest": {
|
||||
"symfony/var-dumper": "Pretty print complex values better with var-dumper available",
|
||||
|
||||
@@ -94,6 +94,26 @@ header {
|
||||
border-bottom: 1px solid rgba(0, 0, 0, .1);
|
||||
}
|
||||
|
||||
.details pre.sf-dump {
|
||||
white-space: pre;
|
||||
word-wrap: inherit;
|
||||
}
|
||||
|
||||
.details pre.sf-dump,
|
||||
.details pre.sf-dump .sf-dump-num,
|
||||
.details pre.sf-dump .sf-dump-const,
|
||||
.details pre.sf-dump .sf-dump-str,
|
||||
.details pre.sf-dump .sf-dump-note,
|
||||
.details pre.sf-dump .sf-dump-ref,
|
||||
.details pre.sf-dump .sf-dump-public,
|
||||
.details pre.sf-dump .sf-dump-protected,
|
||||
.details pre.sf-dump .sf-dump-private,
|
||||
.details pre.sf-dump .sf-dump-meta,
|
||||
.details pre.sf-dump .sf-dump-key,
|
||||
.details pre.sf-dump .sf-dump-index {
|
||||
color: #463C54;
|
||||
}
|
||||
|
||||
.left-panel {
|
||||
height: 100%;
|
||||
overflow: auto;
|
||||
@@ -313,7 +333,7 @@ pre .xsl, code .xsl { color: #d0a0d0; } /* xslt tag */
|
||||
pre .atn, code .atn { color: #ef7c61; font-weight: normal;} /* html/xml attribute name */
|
||||
pre .atv, code .atv { color: #bcd42a; } /* html/xml attribute value */
|
||||
pre .dec, code .dec { color: #606; } /* decimal */
|
||||
pre.prettyprint, code.prettyprint {
|
||||
pre.prettyprint, code.prettyprint, .frame-args.prettyprint, .frame-args.prettyprint samp {
|
||||
font-family: "Inconsolata", "Fira Mono", "Source Code Pro", Monaco, Consolas, "Lucida Console", monospace;
|
||||
background: #333;
|
||||
color: #e9e4e5;
|
||||
|
||||
@@ -119,4 +119,10 @@ Zepto(function($) {
|
||||
e.preventDefault();
|
||||
$.get(this.href);
|
||||
});
|
||||
|
||||
// Symfony VarDumper: Close the by default expanded objects
|
||||
$('.sf-dump-expanded')
|
||||
.removeClass('sf-dump-expanded')
|
||||
.addClass('sf-dump-compact');
|
||||
$('.sf-dump-toggle span').html('▶');
|
||||
});
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
<?php foreach ($data as $k => $value): ?>
|
||||
<tr>
|
||||
<td><?php echo $tpl->escape($k) ?></td>
|
||||
<td><?php echo $tpl->escape($tpl->dump($value)) ?></td>
|
||||
<td><?php echo $tpl->dump($value) ?></td>
|
||||
</tr>
|
||||
<?php endforeach ?>
|
||||
</table>
|
||||
|
||||
@@ -47,6 +47,16 @@
|
||||
<?php endif ?>
|
||||
<?php endif ?>
|
||||
|
||||
<?php $frameArgs = $tpl->dumpArgs($frame); ?>
|
||||
<?php if ($frameArgs): ?>
|
||||
<div class="frame-file">
|
||||
Arguments
|
||||
</div>
|
||||
<div class="code-block frame-args prettyprint">
|
||||
<?php echo $frameArgs; ?>
|
||||
</div>
|
||||
<?php endif ?>
|
||||
|
||||
<?php
|
||||
// Append comments for this frame
|
||||
$comments = $frame->getComments();
|
||||
|
||||
@@ -14,4 +14,4 @@
|
||||
--><span class="frame-line"><?php echo (int) $frame->getLine() ?></span>
|
||||
</span>
|
||||
</div>
|
||||
<?php endforeach ?>
|
||||
<?php endforeach; ?>
|
||||
|
||||
@@ -0,0 +1,37 @@
|
||||
<?php
|
||||
/**
|
||||
* Whoops - php errors for cool kids
|
||||
* @author Filipe Dobreira <http://github.com/filp>
|
||||
*/
|
||||
|
||||
namespace Whoops\Util;
|
||||
|
||||
/**
|
||||
* Used as output callable for Symfony\Component\VarDumper\Dumper\HtmlDumper::dump()
|
||||
*
|
||||
* @see TemplateHelper::dump()
|
||||
*/
|
||||
class HtmlDumperOutput
|
||||
{
|
||||
private $output;
|
||||
|
||||
public function __invoke($line, $depth)
|
||||
{
|
||||
// A negative depth means "end of dump"
|
||||
if ($depth >= 0) {
|
||||
// Adds a two spaces indentation to the line
|
||||
$this->output .= str_repeat(' ', $depth) . $line . "\n";
|
||||
}
|
||||
}
|
||||
|
||||
public function getOutput()
|
||||
{
|
||||
return $this->output;
|
||||
}
|
||||
|
||||
public function clear()
|
||||
{
|
||||
$this->output = null;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -7,8 +7,8 @@
|
||||
namespace Whoops\Util;
|
||||
|
||||
use Symfony\Component\VarDumper\Cloner\VarCloner;
|
||||
use Symfony\Component\VarDumper\Dumper\CliDumper;
|
||||
use Symfony\Component\VarDumper\Dumper\HtmlDumper;
|
||||
use Whoops\Exception\Frame;
|
||||
|
||||
/**
|
||||
* Exposes useful tools for working with/in templates
|
||||
@@ -21,6 +21,16 @@ class TemplateHelper
|
||||
*/
|
||||
private $variables = array();
|
||||
|
||||
/**
|
||||
* @var HtmlDumper
|
||||
*/
|
||||
private $htmlDumper;
|
||||
|
||||
/**
|
||||
* @var HtmlDumperOutput
|
||||
*/
|
||||
private $htmlDumperOutput;
|
||||
|
||||
/**
|
||||
* Escapes a string for output in an HTML document
|
||||
*
|
||||
@@ -62,6 +72,33 @@ class TemplateHelper
|
||||
);
|
||||
}
|
||||
|
||||
private function getDumper()
|
||||
{
|
||||
if (!$this->htmlDumper && class_exists('Symfony\Component\VarDumper\Cloner\VarCloner')) {
|
||||
$this->htmlDumperOutput = new HtmlDumperOutput();
|
||||
// re-use the same var-dumper instance, so it won't re-render the global styles/scripts on each dump.
|
||||
$this->htmlDumper = new HtmlDumper($this->htmlDumperOutput);
|
||||
|
||||
$styles = array(
|
||||
'default' => 'color:#FFFFFF; line-height:normal; font:12px "Inconsolata", "Fira Mono", "Source Code Pro", Monaco, Consolas, "Lucida Console", monospace !important; word-wrap: break-word; white-space: pre-wrap; position:relative; z-index:99999; word-break: normal',
|
||||
'num' => 'color:#BCD42A',
|
||||
'const' => 'color: #4bb1b1;',
|
||||
'str' => 'color:#BCD42A',
|
||||
'note' => 'color:#ef7c61',
|
||||
'ref' => 'color:#A0A0A0',
|
||||
'public' => 'color:#FFFFFF',
|
||||
'protected' => 'color:#FFFFFF',
|
||||
'private' => 'color:#FFFFFF',
|
||||
'meta' => 'color:#FFFFFF',
|
||||
'key' => 'color:#BCD42A',
|
||||
'index' => 'color:#ef7c61',
|
||||
);
|
||||
$this->htmlDumper->setStyles($styles);
|
||||
}
|
||||
|
||||
return $this->htmlDumper;
|
||||
}
|
||||
|
||||
/**
|
||||
* Format the given value into a human readable string.
|
||||
*
|
||||
@@ -70,36 +107,50 @@ class TemplateHelper
|
||||
*/
|
||||
public function dump($value)
|
||||
{
|
||||
if (class_exists('Symfony\Component\VarDumper\Cloner\VarCloner')) {
|
||||
static $dumper = null;
|
||||
|
||||
// re-use the same var-dumper instance, so it won't re-render the global styles/scripts on each dump.
|
||||
if (!$dumper) {
|
||||
$dumper = new HtmlDumper();
|
||||
|
||||
$styles = array(
|
||||
'default' => '',
|
||||
'num' => '',
|
||||
'const' => '',
|
||||
'str' => '',
|
||||
'note' => '',
|
||||
'ref' => '',
|
||||
'public' => '',
|
||||
'protected' => '',
|
||||
'private' => '',
|
||||
'meta' => '',
|
||||
'key' => '',
|
||||
'index' => '',
|
||||
);
|
||||
$dumper->setStyles($styles);
|
||||
}
|
||||
$dumper = $this->getDumper();
|
||||
|
||||
if ($dumper) {
|
||||
$cloner = new VarCloner();
|
||||
return $dumper->dump($cloner->cloneVar($value));
|
||||
|
||||
// re-use the same DumpOutput instance, so it won't re-render the global styles/scripts on each dump.
|
||||
$dumper->dump($cloner->cloneVar($value), $this->htmlDumperOutput);
|
||||
|
||||
$output = $this->htmlDumperOutput->getOutput();
|
||||
$this->htmlDumperOutput->clear();
|
||||
|
||||
return $output;
|
||||
}
|
||||
|
||||
return print_r($value, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Format the args of the given Frame as a human readable html string
|
||||
*
|
||||
* @param Frame $frame
|
||||
* @return string the rendered html
|
||||
*/
|
||||
public function dumpArgs(Frame $frame)
|
||||
{
|
||||
// we support frame args only when the optional dumper is available
|
||||
if (!$this->getDumper()) {
|
||||
return '';
|
||||
}
|
||||
|
||||
$html = '';
|
||||
$numFrames = count($frame->getArgs());
|
||||
|
||||
if ($numFrames > 0) {
|
||||
$html = '<ol class="linenums">';
|
||||
foreach($frame->getArgs() as $j => $frameArg) {
|
||||
$html .= '<li>'. $this->dump($frameArg) .'</li>';
|
||||
}
|
||||
$html .= '</ol>';
|
||||
}
|
||||
|
||||
return $html;
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert a string to a slug version of itself
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user