Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 22d3df8

Browse filesBrowse files
committed
feature #12256 [VarDumper] add meta-data on hover (nicolas-grekas)
This PR was merged into the 2.6-dev branch. Discussion ---------- [VarDumper] add meta-data on hover | Q | A | ------------- | --- | Bug fix? | yes | New feature? | yes | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | - | License | MIT | Doc PR | - This PR adds meta-data on hover to HTML dumps: - strings length - constants value - control chars code - local refs count Commits ------- bef48b3 [VarDumper] add meta-data on hover
2 parents 453882c + bef48b3 commit 22d3df8
Copy full SHA for 22d3df8

File tree

Expand file treeCollapse file tree

16 files changed

+167
-133
lines changed
Filter options
Expand file treeCollapse file tree

16 files changed

+167
-133
lines changed

‎src/Symfony/Bridge/Twig/Tests/Extension/DumpExtensionTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Bridge/Twig/Tests/Extension/DumpExtensionTest.php
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ public function getDumpArgs()
9797
array('foo' => 'bar'),
9898
array(),
9999
"<pre class=sf-dump id=sf-dump data-indent-pad=\" \"><span class=sf-dump-note>array:1</span> [<samp>\n"
100-
." \"<span class=sf-dump-meta>foo</span>\" => \"<span class=sf-dump-str>bar</span>\"\n"
100+
." \"<span class=sf-dump-meta>foo</span>\" => \"<span class=sf-dump-str title=\"3 characters\">bar</span>\"\n"
101101
."</samp>]\n"
102102
."</pre><script>Sfdump(\"sf-dump\")</script>\n",
103103
),

‎src/Symfony/Component/HttpKernel/Tests/DataCollector/DumpDataCollectorTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/HttpKernel/Tests/DataCollector/DumpDataCollectorTest.php
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ public function testDump()
4949
$this->assertSame($xDump, $dump);
5050

5151
$this->assertStringStartsWith(
52-
'a:1:{i:0;a:5:{s:4:"data";O:39:"Symfony\Component\VarDumper\Cloner\Data":3:{s:45:"Symfony\Component\VarDumper\Cloner\Datadata";a:1:{i:0;a:1:{i:0;i:123;}}s:49:"Symfony\Component\VarDumper\Cloner\DatamaxDepth";i:-1;s:57:"Symfony\Component\VarDumper\Cloner\DatamaxItemsPerDepth";i:-1;}s:4:"name";s:25:"DumpDataCollectorTest.php";s:4:"file";s:',
52+
'a:1:{i:0;a:5:{s:4:"data";O:39:"Symfony\Component\VarDumper\Cloner\Data":4:{s:45:"Symfony\Component\VarDumper\Cloner\Datadata";a:1:{i:0;a:1:{i:0;i:123;}}s:49:"Symfony\Component\VarDumper\Cloner\DatamaxDepth";i:-1;s:57:"Symfony\Component\VarDumper\Cloner\DatamaxItemsPerDepth";i:-1;s:54:"Symfony\Component\VarDumper\Cloner\DatauseRefHandles";i:-1;}s:4:"name";s:25:"DumpDataCollectorTest.php";s:4:"file";s:',
5353
str_replace("\0", '', $collector->serialize())
5454
);
5555

+28Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Component\VarDumper\Caster;
13+
14+
use Symfony\Component\VarDumper\Cloner\Stub;
15+
16+
/**
17+
* Represents a PHP constant and its value.
18+
*
19+
* @author Nicolas Grekas <p@tchwork.com>
20+
*/
21+
class ConstStub extends Stub
22+
{
23+
public function __construct($name, $value)
24+
{
25+
$this->class = $name;
26+
$this->value = $value;
27+
}
28+
}

‎src/Symfony/Component/VarDumper/Caster/CasterStub.php renamed to ‎src/Symfony/Component/VarDumper/Caster/CutStub.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/VarDumper/Caster/CutStub.php
+6-9Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,10 @@
1818
*
1919
* @author Nicolas Grekas <p@tchwork.com>
2020
*/
21-
class CasterStub extends Stub
21+
class CutStub extends Stub
2222
{
23-
public function __construct($value, $class = '')
23+
public function __construct($value)
2424
{
25-
$this->class = $class;
2625
$this->value = $value;
2726

2827
switch (gettype($value)) {
@@ -47,12 +46,10 @@ public function __construct($value, $class = '')
4746
break;
4847

4948
case 'string':
50-
if ('' === $class) {
51-
$this->type = self::TYPE_STRING;
52-
$this->class = preg_match('//u', $value) ? self::STRING_UTF8 : self::STRING_BINARY;
53-
$this->cut = self::STRING_BINARY === $this->class ? strlen($value) : (function_exists('iconv_strlen') ? iconv_strlen($value, 'UTF-8') : -1);
54-
$this->value = '';
55-
}
49+
$this->type = self::TYPE_STRING;
50+
$this->class = preg_match('//u', $value) ? self::STRING_UTF8 : self::STRING_BINARY;
51+
$this->cut = self::STRING_BINARY === $this->class ? strlen($value) : (function_exists('iconv_strlen') ? iconv_strlen($value, 'UTF-8') : -1);
52+
$this->value = '';
5653
break;
5754
}
5855
}

‎src/Symfony/Component/VarDumper/Caster/DOMCaster.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/VarDumper/Caster/DOMCaster.php
+15-15Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ class DOMCaster
6464
public static function castException(\DOMException $e, array $a, Stub $stub, $isNested)
6565
{
6666
if (isset($a["\0*\0code"], self::$errorCodes[$a["\0*\0code"]])) {
67-
$a["\0*\0code"] = new CasterStub(self::$errorCodes[$a["\0*\0code"]], 'const');
67+
$a["\0*\0code"] = new ConstStub(self::$errorCodes[$a["\0*\0code"]], $a["\0*\0code"]);
6868
}
6969

7070
return $a;
@@ -93,21 +93,21 @@ public static function castNode(\DOMNode $dom, array $a, Stub $stub, $isNested)
9393
{
9494
$a += array(
9595
'nodeName' => $dom->nodeName,
96-
'nodeValue' => new CasterStub($dom->nodeValue),
97-
'nodeType' => new CasterStub(self::$nodeTypes[$dom->nodeType], 'const'),
98-
'parentNode' => new CasterStub($dom->parentNode),
96+
'nodeValue' => new CutStub($dom->nodeValue),
97+
'nodeType' => new ConstStub(self::$nodeTypes[$dom->nodeType], $dom->nodeType),
98+
'parentNode' => new CutStub($dom->parentNode),
9999
'childNodes' => $dom->childNodes,
100-
'firstChild' => new CasterStub($dom->firstChild),
101-
'lastChild' => new CasterStub($dom->lastChild),
102-
'previousSibling' => new CasterStub($dom->previousSibling),
103-
'nextSibling' => new CasterStub($dom->nextSibling),
100+
'firstChild' => new CutStub($dom->firstChild),
101+
'lastChild' => new CutStub($dom->lastChild),
102+
'previousSibling' => new CutStub($dom->previousSibling),
103+
'nextSibling' => new CutStub($dom->nextSibling),
104104
'attributes' => $dom->attributes,
105-
'ownerDocument' => new CasterStub($dom->ownerDocument),
105+
'ownerDocument' => new CutStub($dom->ownerDocument),
106106
'namespaceURI' => $dom->namespaceURI,
107107
'prefix' => $dom->prefix,
108108
'localName' => $dom->localName,
109109
'baseURI' => $dom->baseURI,
110-
'textContent' => new CasterStub($dom->textContent),
110+
'textContent' => new CutStub($dom->textContent),
111111
);
112112

113113
return $a;
@@ -119,13 +119,13 @@ public static function castNameSpaceNode(\DOMNameSpaceNode $dom, array $a, Stub
119119

120120
$a += array(
121121
'nodeName' => $dom->nodeName,
122-
'nodeValue' => new CasterStub($dom->nodeValue),
123-
'nodeType' => new CasterStub(self::$nodeTypes[$dom->nodeType], 'const'),
122+
'nodeValue' => new CutStub($dom->nodeValue),
123+
'nodeType' => new ConstStub(self::$nodeTypes[$dom->nodeType], $dom->nodeType),
124124
'prefix' => $dom->prefix,
125125
'localName' => $dom->localName,
126126
'namespaceURI' => $dom->namespaceURI,
127-
'ownerDocument' => new CasterStub($dom->ownerDocument),
128-
'parentNode' => new CasterStub($dom->parentNode),
127+
'ownerDocument' => new CutStub($dom->ownerDocument),
128+
'parentNode' => new CutStub($dom->parentNode),
129129
);
130130

131131
return $a;
@@ -139,7 +139,7 @@ public static function castDocument(\DOMDocument $dom, array $a, Stub $stub, $is
139139
$a += array(
140140
'doctype' => $dom->doctype,
141141
'implementation' => $dom->implementation,
142-
'documentElement' => new CasterStub($dom->documentElement),
142+
'documentElement' => new CutStub($dom->documentElement),
143143
'actualEncoding' => $dom->actualEncoding,
144144
'encoding' => $dom->encoding,
145145
'xmlEncoding' => $dom->xmlEncoding,

‎src/Symfony/Component/VarDumper/Caster/DoctrineCaster.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/VarDumper/Caster/DoctrineCaster.php
+3-3Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,9 @@ public static function castPersistentCollection(PersistentCollection $coll, arra
5050
{
5151
$prefix = "\0Doctrine\\ORM\\PersistentCollection\0";
5252

53-
$a[$prefix.'snapshot'] = new CasterStub($a[$prefix.'snapshot']);
54-
$a[$prefix.'association'] = new CasterStub($a[$prefix.'association']);
55-
$a[$prefix.'typeClass'] = new CasterStub($a[$prefix.'typeClass']);
53+
$a[$prefix.'snapshot'] = new CutStub($a[$prefix.'snapshot']);
54+
$a[$prefix.'association'] = new CutStub($a[$prefix.'association']);
55+
$a[$prefix.'typeClass'] = new CutStub($a[$prefix.'typeClass']);
5656

5757
return $a;
5858
}

‎src/Symfony/Component/VarDumper/Caster/ExceptionCaster.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/VarDumper/Caster/ExceptionCaster.php
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ public static function castException(\Exception $e, array $a, Stub $stub, $isNes
6161
public static function castErrorException(\ErrorException $e, array $a, Stub $stub, $isNested)
6262
{
6363
if (isset($a[$s = "\0*\0severity"], self::$errorTypes[$a[$s]])) {
64-
$a[$s] = new CasterStub(self::$errorTypes[$a[$s]], 'const');
64+
$a[$s] = new ConstStub(self::$errorTypes[$a[$s]], $a[$s]);
6565
}
6666

6767
return $a;

‎src/Symfony/Component/VarDumper/Caster/PdoCaster.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/VarDumper/Caster/PdoCaster.php
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ public static function castPdo(\PDO $c, array $a, Stub $stub, $isNested)
7272
try {
7373
$a[$attr] = 'ERRMODE' === $attr ? $errmode : $c->getAttribute(constant("PDO::ATTR_{$attr}"));
7474
if (isset($values[$a[$attr]])) {
75-
$a[$attr] = new CasterStub($values[$a[$attr]], 'const');
75+
$a[$attr] = new ConstStub($values[$a[$attr]], $a[$attr]);
7676
}
7777
} catch (\Exception $m) {
7878
}

‎src/Symfony/Component/VarDumper/Caster/SplCaster.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/VarDumper/Caster/SplCaster.php
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ public static function castDoublyLinkedList(\SplDoublyLinkedList $c, array $a, S
7272
$c->setIteratorMode(\SplDoublyLinkedList::IT_MODE_KEEP | $mode & ~\SplDoublyLinkedList::IT_MODE_DELETE);
7373

7474
$a += array(
75-
"\0~\0mode" => new CasterStub((($mode & \SplDoublyLinkedList::IT_MODE_LIFO) ? 'IT_MODE_LIFO' : 'IT_MODE_FIFO').' | '.(($mode & \SplDoublyLinkedList::IT_MODE_KEEP) ? 'IT_MODE_KEEP' : 'IT_MODE_DELETE'), 'const'),
75+
"\0~\0mode" => new ConstStub((($mode & \SplDoublyLinkedList::IT_MODE_LIFO) ? 'IT_MODE_LIFO' : 'IT_MODE_FIFO').' | '.(($mode & \SplDoublyLinkedList::IT_MODE_KEEP) ? 'IT_MODE_KEEP' : 'IT_MODE_DELETE'), $mode),
7676
"\0~\0dllist" => iterator_to_array($c),
7777
);
7878
$c->setIteratorMode($mode);

‎src/Symfony/Component/VarDumper/Caster/StubCaster.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/VarDumper/Caster/StubCaster.php
+3-3Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,13 @@
1414
use Symfony\Component\VarDumper\Cloner\Stub;
1515

1616
/**
17-
* Casts a CasterStub.
17+
* Casts a caster's Stub.
1818
*
1919
* @author Nicolas Grekas <p@tchwork.com>
2020
*/
2121
class StubCaster
2222
{
23-
public static function castStub(CasterStub $c, array $a, Stub $stub, $isNested)
23+
public static function castStub(Stub $c, array $a, Stub $stub, $isNested)
2424
{
2525
if ($isNested) {
2626
$stub->type = $c->type;
@@ -33,7 +33,7 @@ public static function castStub(CasterStub $c, array $a, Stub $stub, $isNested)
3333
}
3434
}
3535

36-
public static function castNestedFat($obj, array $a, Stub $stub, $isNested)
36+
public static function cutInternals($obj, array $a, Stub $stub, $isNested)
3737
{
3838
if ($isNested) {
3939
$stub->cut += count($a);

‎src/Symfony/Component/VarDumper/Cloner/AbstractCloner.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/VarDumper/Cloner/AbstractCloner.php
+4-3Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,13 @@
2121
abstract class AbstractCloner implements ClonerInterface
2222
{
2323
public static $defaultCasters = array(
24-
'Symfony\Component\VarDumper\Caster\CasterStub' => 'Symfony\Component\VarDumper\Caster\StubCaster::castStub',
24+
'Symfony\Component\VarDumper\Caster\CutStub' => 'Symfony\Component\VarDumper\Caster\StubCaster::castStub',
25+
'Symfony\Component\VarDumper\Caster\ConstStub' => 'Symfony\Component\VarDumper\Caster\StubCaster::castStub',
2526

2627
'Closure' => 'Symfony\Component\VarDumper\Caster\ReflectionCaster::castClosure',
2728
'Reflector' => 'Symfony\Component\VarDumper\Caster\ReflectionCaster::castReflector',
2829

29-
'Doctrine\Common\Persistence\ObjectManager' => 'Symfony\Component\VarDumper\Caster\StubCaster::castNestedFat',
30+
'Doctrine\Common\Persistence\ObjectManager' => 'Symfony\Component\VarDumper\Caster\StubCaster::cutInternals',
3031
'Doctrine\Common\Proxy\Proxy' => 'Symfony\Component\VarDumper\Caster\DoctrineCaster::castCommonProxy',
3132
'Doctrine\ORM\Proxy\Proxy' => 'Symfony\Component\VarDumper\Caster\DoctrineCaster::castOrmProxy',
3233
'Doctrine\ORM\PersistentCollection' => 'Symfony\Component\VarDumper\Caster\DoctrineCaster::castPersistentCollection',
@@ -57,7 +58,7 @@ abstract class AbstractCloner implements ClonerInterface
5758
'ErrorException' => 'Symfony\Component\VarDumper\Caster\ExceptionCaster::castErrorException',
5859
'Exception' => 'Symfony\Component\VarDumper\Caster\ExceptionCaster::castException',
5960
'Symfony\Component\DependencyInjection\ContainerInterface'
60-
=> 'Symfony\Component\VarDumper\Caster\StubCaster::castNestedFat',
61+
=> 'Symfony\Component\VarDumper\Caster\StubCaster::cutInternals',
6162
'Symfony\Component\VarDumper\Exception\ThrowingCasterException'
6263
=> 'Symfony\Component\VarDumper\Caster\ExceptionCaster::castThrowingCasterException',
6364

‎src/Symfony/Component/VarDumper/Cloner/Cursor.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/VarDumper/Cloner/Cursor.php
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ class Cursor
3333
public $hardRefHandle = 0;
3434
public $hashType;
3535
public $hashKey;
36+
public $hashKeyIsBinary;
3637
public $hashIndex = 0;
3738
public $hashLength = 0;
3839
public $hashCut = 0;

‎src/Symfony/Component/VarDumper/Cloner/Data.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/VarDumper/Cloner/Data.php
+13-6Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ class Data
1919
private $data;
2020
private $maxDepth = -1;
2121
private $maxItemsPerDepth = -1;
22+
private $useRefHandles = -1;
2223

2324
/**
2425
* @param array $data A array as returned by ClonerInterface::cloneVar().
@@ -39,16 +40,18 @@ public function getRawData()
3940
/**
4041
* Returns a depth limited clone of $this.
4142
*
42-
* @param int $maxDepth The max dumped depth level.
43-
* @param int $maxItemsPerDepth The max number of items dumped per depth level.
43+
* @param int $maxDepth The max dumped depth level.
44+
* @param int $maxItemsPerDepth The max number of items dumped per depth level.
45+
* @param bool $useRefHandles False to hide ref. handles.
4446
*
4547
* @return self A depth limited clone of $this.
4648
*/
47-
public function getLimitedClone($maxDepth, $maxItemsPerDepth)
49+
public function getLimitedClone($maxDepth, $maxItemsPerDepth, $useRefHandles = true)
4850
{
4951
$data = clone $this;
5052
$data->maxDepth = (int) $maxDepth;
5153
$data->maxItemsPerDepth = (int) $maxItemsPerDepth;
54+
$data->useRefHandles = $useRefHandles ? -1 : 0;
5255

5356
return $data;
5457
}
@@ -87,7 +90,7 @@ private function dumpItem($dumper, $cursor, &$refs, $item)
8790
$firstSeen = false;
8891
}
8992
$cursor->hardRefTo = $refs[$r];
90-
$cursor->hardRefHandle = $item->handle;
93+
$cursor->hardRefHandle = $this->useRefHandles & $item->handle;
9194
$cursor->hardRefCount = $item->refCount;
9295
}
9396
$type = $item->class ?: gettype($item->value);
@@ -102,7 +105,7 @@ private function dumpItem($dumper, $cursor, &$refs, $item)
102105
}
103106
$cursor->softRefTo = $refs[$r];
104107
}
105-
$cursor->softRefHandle = $item->handle;
108+
$cursor->softRefHandle = $this->useRefHandles & $item->handle;
106109
$cursor->softRefCount = $item->refCount;
107110
$cut = $item->cut;
108111

@@ -142,6 +145,8 @@ private function dumpItem($dumper, $cursor, &$refs, $item)
142145
} elseif ('array' === $type) {
143146
$dumper->enterHash($cursor, Cursor::HASH_INDEXED, 0, false);
144147
$dumper->leaveHash($cursor, Cursor::HASH_INDEXED, 0, false, 0);
148+
} elseif ('string' === $type) {
149+
$dumper->dumpString($cursor, $item, false, 0);
145150
} else {
146151
$dumper->dumpScalar($cursor, $type, $item);
147152
}
@@ -169,7 +174,9 @@ private function dumpChildren($dumper, $parentCursor, &$refs, $children, $hashCu
169174
$cursor->hashIndex = 0;
170175
$cursor->hashLength = count($children);
171176
$cursor->hashCut = $hashCut;
172-
foreach ($children as $cursor->hashKey => $child) {
177+
foreach ($children as $key => $child) {
178+
$cursor->hashKeyIsBinary = isset($key[0]) && !preg_match('//u', $key);
179+
$cursor->hashKey = $cursor->hashKeyIsBinary ? self::utf8Encode($key) : $key;
173180
$this->dumpItem($dumper, $cursor, $refs, $child);
174181
if (++$cursor->hashIndex === $this->maxItemsPerDepth || $cursor->stop) {
175182
$parentCursor->stop = true;

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.