Added support for printing frame args in the framestack.

This commit is contained in:
Markus Staab
2015-11-29 15:44:28 +01:00
committed by Jonas De Taeye
parent c477d2ff70
commit c25bbbcedc
4 changed files with 84 additions and 26 deletions
+9
View File
@@ -136,6 +136,15 @@ header {
font-size: 14px;
}
.frame-arg {
margin-left: 20px;
display: block;
}
.frame-arg-separated .sf-dump::after {
content: ',';
}
.frame-index {
font-size: 11px;
color: #a29d9d;
@@ -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>
@@ -7,6 +7,7 @@
<span class="frame-index"><?php echo (count($frames) - $i - 1) ?></span>
<span class="frame-class"><?php echo $tpl->escape($frame->getClass() ?: '') ?></span>
<span class="frame-function"><?php echo $tpl->escape($frame->getFunction() ?: '') ?></span>
<?php echo $tpl->dumpArgs($frame); ?>
</div>
<span class="frame-file">
@@ -14,4 +15,4 @@
--><span class="frame-line"><?php echo (int) $frame->getLine() ?></span>
</span>
</div>
<?php endforeach ?>
<?php endforeach; ?>
+72 -24
View File
@@ -9,6 +9,7 @@ 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
@@ -62,6 +63,34 @@ class TemplateHelper
);
}
private function getDumper()
{
static $dumper = null;
if (!$dumper && class_exists('Symfony\Component\VarDumper\Cloner\VarCloner')) {
// re-use the same var-dumper instance, so it won't re-render the global styles/scripts on each dump.
$dumper = new HtmlDumper();
$styles = array(
'default' => '',
'num' => '',
'const' => '',
'str' => '',
'note' => '',
'ref' => '',
'public' => '',
'protected' => '',
'private' => '',
'meta' => '',
'key' => '',
'index' => '',
);
$dumper->setStyles($styles);
}
return $dumper;
}
/**
* Format the given value into a human readable string.
*
@@ -70,36 +99,55 @@ 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));
$output = '';
$dumper->dump($cloner->cloneVar($value), function ($line, $depth) use (&$output) {
// A negative depth means "end of dump"
if ($depth >= 0) {
// Adds a two spaces indentation to the line
$output .= str_repeat(' ', $depth).$line."\n";
}
});
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 .= '(';
foreach($frame->getArgs() as $j => $frameArg) {
$class = 'frame-arg';
if ($j != $numFrames - 1 ) {
$class .= ' frame-arg-separated';
}
$html .= '<span class="'. $class .'">'. $this->dump($frameArg) .'</span>';
}
$html .= ')';
}
return $html;
}
/**
* Convert a string to a slug version of itself
*