8000 [VarDumper] add meta-data on hover · symfony/symfony@bef48b3 · GitHub
[go: up one dir, main page]

Skip to content

Commit bef48b3

Browse files
[VarDumper] add meta-data on hover
1 parent 0e6465a commit bef48b3

File tree

16 files changed

+167
-133
lines changed

16 files changed

+167
-133
lines changed

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

Lines 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

Lines 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

Lines 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

Lines 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

Lines 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
' EED3 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

Lines 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

Lines 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

Lines 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

Lines 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

Lines 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);

0 commit comments

Comments
 (0)
0