8000 [Var-Dumper] added feature to set default nodes collapsed by MGDSoft · Pull Request #18148 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[Var-Dumper] added feature to set default nodes collapsed #18148

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 11 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
[Var-Dumper] added feature to set default nodes collapsed
modify js htmldumper and add attr in root node
  • Loading branch information
MGDSoft committed Apr 2, 2016
commit c78eacfa9abfe7ad5350d9494c980a7c3f52bcd8
8 changes: 4 additions & 4 deletions src/Symfony/Bridge/Twig/Tests/Extension/DumpExtensionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,17 +86,17 @@ public function getDumpArgs()
{
return array(
array(array(), array(), '', false),
array(array(), array(), "<pre class=sf-dump id=sf-dump data-indent-pad=\" \">[]\n</pre><script>Sfdump(\"sf-dump\")</script>\n"),
array(array(), array(), "<pre class=sf-dump id=sf-dump data-indent-pad=\" \" data-collapsed-by-default-nodes-higher-than=\"1\">[]\n</pre><script>Sfdump(\"sf-dump\")</script>\n"),
array(
array(),
array(123, 456),
"<pre class=sf-dump id=sf-dump data-indent-pad=\" \"><span class=sf-dump-num>123</span>\n</pre><script>Sfdump(\"sf-dump\")</script>\n"
."<pre class=sf-dump id=sf-dump data-indent-pad=\" \"><span class=sf-dump-num>456</span>\n</pre><script>Sfdump(\"sf-dump\")</script>\n",
"<pre class=sf-dump id=sf-dump data-indent-pad=\" \" data-collapsed-by-default-nodes-higher-than=\"1\"><span class=sf-dump-num>123</span>\n</pre><script>Sfdump(\"sf-dump\")</script>\n"
."<pre class=sf-dump id=sf-dump data-indent-pad=\" \" data-collapsed-by-default-nodes-higher-than=\"1\"><span class=sf-dump-num>456</span>\n</pre><script>Sfdump(\"sf-dump\")</script>\n",
),
array(
array('foo' => 'bar'),
array(),
"<pre class=sf-dump id=sf-dump data-indent-pad=\" \"><span class=sf-dump-note>array:1</span> [<samp>\n"
"<pre class=sf-dump id=sf-dump data-indent-pad=\" \" data-collapsed-by-default-nodes-higher-than=\"1\"><span class=sf-dump-note>array:1</span> [<samp>\n"
." \"<span class=sf-dump-key>foo</span>\" => \"<span class=sf-dump-str title=\"3 characters\">bar</span>\"\n"
."</samp>]\n"
."</pre><script>Sfdump(\"sf-dump\")</script>\n",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public function testDump()

$xDump = array(
array(
'data' => "<pre class=sf-dump id=sf-dump data-indent-pad=\" \"><span class=sf-dump-num>123</span>\n</pre><script>Sfdump(\"sf-dump\")</script>\n",
'data' => "<pre class=sf-dump id=sf-dump data-indent-pad=\" \" data-collapsed-by-default-nodes-higher-than=\"1\"><span class=sf-dump-num>123</span>\n</pre><script>Sfdump(\"sf-dump\")</script>\n",
'name' => 'DumpDataCollectorTest.php',
'file' => __FILE__,
'line' => $line,
Expand Down Expand Up @@ -86,7 +86,7 @@ public function testCollectHtml()
$line = __LINE__ - 1;
$file = __FILE__;
$xOutput = <<<EOTXT
<pre class=sf-dump id=sf-dump data-indent-pad=" "><a href="test://{$file}:{$line}" title="{$file}"><span class=sf-dump-meta>DumpDataCollectorTest.php</span></a> on line <span class=sf-dump-meta>{$line}</span>:
<pre class=sf-dump id=sf-dump data-indent-pad=" " data-collapsed-by-default-nodes-higher-than="1"><a href="test://{$file}:{$line}" title="{$file}"><span class=sf-dump-meta>DumpDataCollectorTest.php</span></a> on line <span class=sf-dump-meta>{$line}</span>:
<span class=sf-dump-num>123</span>
</pre>

Expand Down
42 changes: 39 additions & 3 deletions src/Symfony/Component/VarDumper/Dumper/HtmlDumper.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class HtmlDumper extends CliDumper
public static $defaultOutput = 'php://output';

protected $dumpHeader;
protected $dumpPrefix = '<pre class=sf-dump id=%s data-indent-pad="%s">';
protected $dumpPrefix = '<pre class=sf-dump id=%s data-indent-pad="%s" data-collapsed-by-default-nodes-higher-than="%s">';
protected $dumpSuffix = '</pre><script>Sfdump("%s")</script>';
protected $dumpId = 'sf-dump';
protected $colors = true;
Expand All @@ -45,6 +45,10 @@ class HtmlDumper extends CliDumper
'index' => 'color:#1299DA',
);

protected $jsProperties = array(
'collapsedByDefaultNodesHigherThan' => 1
);

/**
* {@inheritdoc}
*/
Expand Down Expand Up @@ -75,6 +79,16 @@ public function setStyles(array $styles)
$this->styles = $styles + $this->styles;
}

/**
* Configures js properties.
*
* @param array $jsProperties A map of jsProperties names to customize the behavior.
*/
public function setJsProperties(array $jsProperties)
{
$this->jsProperties = $jsProperties;
}

/**
* Sets an HTML header that will be dumped once in the output stream.
*
Expand Down Expand Up @@ -119,6 +133,7 @@ protected function getDumpHeader()

$line = <<<'EOHTML'
<script>

Sfdump = window.Sfdump || (function (doc) {

var refStyle = doc.createElement('style'),
Expand Down Expand Up @@ -175,6 +190,7 @@ function toggle(a, recursive) {

return function (root) {
root = doc.getElementById(root);
var collapsedByDefaultNodesHigherThan = root.getAttribute('data-collapsed-by-default-nodes-higher-than');

function a(e, f) {
addEventListener(root, e, function (e) {
Expand Down Expand Up @@ -252,6 +268,19 @@ function isCtrlKey(e) {
len = t.length;
i = t = 0;

function getLevelNodeFromRoot(node, level) {
level = level || 0;
level++;

node = node.parentNode;

if ('sf-dump' == node.className) {
return level;
}

return getLevelNodeFromRoot(node, level);
}

while (i < len) {
elt = root[i];
if ("SAMP" == elt.tagName) {
Expand All @@ -267,9 +296,11 @@ function isCtrlKey(e) {
a.title = (a.title ? a.title+'\n[' : '[')+keyHint+'+click] Expand all children';
a.innerHTML += '<span>▼</span>';
a.className += ' sf-dump-toggle';
if ('sf-dump' != elt.parentNode.className) {

if (getLevelNodeFromRoot(elt) > collapsedByDefaultNodesHigherThan) {
toggle(a);
}

} else if ("sf-dump-ref" == elt.className && (a = elt.getAttribute('href'))) {
a = a.substr(1);
elt.className += ' '+a;
Expand Down Expand Up @@ -431,7 +462,12 @@ protected function style($style, $value, $attr = array())
protected function dumpLine($depth, $endOfValue = false)
{
if (-1 === $this->lastDepth) {
$this->line = sprintf($this->dumpPrefix, $this->dumpId, $this->indentPad).$this->line;
$this->line = sprintf(
$this->dumpPrefix,
$this->dumpId,
$this->indentPad,
$this->jsProperties['collapsedByDefaultNodesHigherThan']
) . $this->line;
}
if (!$this->headerIsDumped) {
$this->line = $this->getDumpHeader().$this->line;
Expand Down
0