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 031c401

Browse filesBrowse files
[VarDumper] add meta-data on hover
1 parent 0e6465a commit 031c401
Copy full SHA for 031c401

File tree

Expand file treeCollapse file tree

13 files changed

+147
-97
lines changed
Filter options
Expand file treeCollapse file tree

13 files changed

+147
-97
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/VarDumper/Caster/CasterStub.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/VarDumper/Caster/CasterStub.php
+5-8Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,8 @@
2020
*/
2121
class CasterStub 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
}
+27Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
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+
/**
15+
* Represents a PHP constant and its value.
16+
*
17+
* @author Nicolas Grekas <p@tchwork.com>
18+
*/
19+
class ConstStub extends CasterStub
20+
{
21+
public function __construct($name, $value)
22+
{
23+
$this->type = self::TYPE_CONST;
24+
$this->class = $name;
25+
$this->value = $value;
26+
}
27+
}

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

Copy file name to clipboardExpand all lines: src/Symfony/Component/VarDumper/Caster/DOMCaster.php
+3-3Lines changed: 3 additions & 3 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;
@@ -94,7 +94,7 @@ public static function castNode(\DOMNode $dom, array $a, Stub $stub, $isNested)
9494
$a += array(
9595
'nodeName' => $dom->nodeName,
9696
'nodeValue' => new CasterStub($dom->nodeValue),
97-
'nodeType' => new CasterStub(self::$nodeTypes[$dom->nodeType], 'const'),
97+
'nodeType' => new ConstStub(self::$nodeTypes[$dom->nodeType], $dom->nodeType),
9898
'parentNode' => new CasterStub($dom->parentNode),
9999
'childNodes' => $dom->childNodes,
100100
'firstChild' => new CasterStub($dom->firstChild),
@@ -120,7 +120,7 @@ public static function castNameSpaceNode(\DOMNameSpaceNode $dom, array $a, Stub
120120
$a += array(
121121
'nodeName' => $dom->nodeName,
122122
'nodeValue' => new CasterStub($dom->nodeValue),
123-
'nodeType' => new CasterStub(self::$nodeTypes[$dom->nodeType], 'const'),
123+
'nodeType' => new ConstStub(self::$nodeTypes[$dom->nodeType], $dom->nodeType),
124124
'prefix' => $dom->prefix,
125125
'localName' => $dom->localName,
126126
'namespaceURI' => $dom->namespaceURI,

‎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/Cloner/Data.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/VarDumper/Cloner/Data.php
+7Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,11 @@ private function dumpItem($dumper, $cursor, &$refs, $item)
9494
$item = $item->value;
9595
}
9696
if ($item instanceof Stub) {
97+
if (Stub::TYPE_CONST === $item->type) {
98+
$dumper->dumpConst($cursor, $item->class, $item->value);
99+
100+
return;
101+
}
97102
if ($item->refCount) {
98103
if (!isset($refs[$r = $item->handle])) {
99104
$cursor->refIndex = $refs[$r] = $cursor->refIndex ?: ++$refs[0];
@@ -142,6 +147,8 @@ private function dumpItem($dumper, $cursor, &$refs, $item)
142147
} elseif ('array' === $type) {
143148
$dumper->enterHash($cursor, Cursor::HASH_INDEXED, 0, false);
144149
$dumper->leaveHash($cursor, Cursor::HASH_INDEXED, 0, false, 0);
150+
} elseif ('string' === $type) {
151+
$dumper->dumpString($cursor, $item, false, 0);
145152
} else {
146153
$dumper->dumpScalar($cursor, $type, $item);
147154
}

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

Copy file name to clipboardExpand all lines: src/Symfony/Component/VarDumper/Cloner/DumperInterface.php
+9Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,15 @@ public function dumpScalar(Cursor $cursor, $type, $value);
3737
*/
3838
public function dumpString(Cursor $cursor, $str, $bin, $cut);
3939

40+
/**
41+
* Dumps a constant.
42+
*
43+
* @param Cursor $cursor The Cursor position in the dump.
44+
* @param string $name The constant name.
45+
* @param scalar $value The constant value.
46+
*/
47+
public function dumpConst(Cursor $cursor, $name, $value);
48+
4049
/**
4150
* Dumps while entering an hash.
4251
*

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

Copy file name to clipboardExpand all lines: src/Symfony/Component/VarDumper/Cloner/Stub.php
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
class Stub
2020
{
2121
const TYPE_REF = 'ref';
22+
const TYPE_CONST = 'const';
2223
const TYPE_STRING = 'string';
2324
const TYPE_ARRAY = 'array';
2425
const TYPE_OBJECT = 'object';

‎src/Symfony/Component/VarDumper/Dumper/CliDumper.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/VarDumper/Dumper/CliDumper.php
+50-45Lines changed: 50 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -41,13 +41,7 @@ class CliDumper extends AbstractDumper
4141
'meta' => '38;5;27',
4242
);
4343

44-
protected static $controlChars = array(
45-
"\x1B", // ESC must be the first
46-
"\x00", "\x01", "\x02", "\x03", "\x04", "\x05", "\x06", "\x07",
47-
"\x08", "\x09", "\x0A", "\x0B", "\x0C", "\x0D", "\x0E", "\x0F",
48-
"\x10", "\x11", "\x12", "\x13", "\x14", "\x15", "\x16", "\x17",
49-
"\x18", "\x19", "\x1A", "\x1C", "\x1D", "\x1E", "\x1F", "\x7F",
50-
);
44+
protected static $controlCharsRx = "/\\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0A\x0B\x0C\x0D\x0E\x0F\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1A\x1B\x1C\x1D\x1E\x1F\x7F/";
5145

5246
/**
5347
* Enables/disables colored output.
@@ -84,12 +78,18 @@ public function setStyles(array $styles)
8478
/**
8579
* {@inheritdoc}
8680
*/
87-
public function dumpScalar(Cursor $cursor, $type, $val)
81+
public function dumpConst(Cursor $cursor, $name, $value)
8882
{
89-
if ('string' === $type) {
90-
return $this->dumpString($cursor, $val, false, 0);
91-
}
83+
$this->dumpKey($cursor);
84+
$this->line .= $this->style('const', $name, compact('value'));
85+
$this->dumpLine($cursor->depth);
86+
}
9287

88+
/**
89+
* {@inheritdoc}
90+
*/
91+
public function dumpScalar(Cursor $cursor, $type, $value)
92+
{
9393
$this->dumpKey($cursor);
9494

9595
$style = 'const';
@@ -103,28 +103,28 @@ public function dumpScalar(Cursor $cursor, $type, $val)
103103
$style = 'num';
104104

105105
switch (true) {
106-
case INF === $val: $val = 'INF'; break;
107-
case -INF === $val: $val = '-INF'; break;
108-
case is_nan($val): $val = 'NAN'; break;
106+
case INF === $value: $value = 'INF'; break;
107+
case -INF === $value: $value = '-INF'; break;
108+
case is_nan($value): $value = 'NAN'; break;
109109
default:
110-
$val = (string) $val;
111-
if (false === strpos($val, $this->decimalPoint)) {
112-
$val .= $this->decimalPoint.'0';
110+
$value = (string) $value;
111+
if (false === strpos($value, $this->decimalPoint)) {
112+
$value .= $this->decimalPoint.'0';
113113
}
114114
break;
115115
}
116116
break;
117117

118118
case 'NULL':
119-
$val = 'null';
119+
$value = 'null';
120120
break;
121121

122122
case 'boolean':
123-
$val = $val ? 'true' : 'false';
123+
$value = $value ? 'true' : 'false';
124124
break;
125125
}
126126

127-
$this->line .= $this->style($style, $val);
127+
$this->line .= $this->style($style, $value);
128128

129129
$this->dumpLine($cursor->depth);
130130
}
@@ -140,6 +140,10 @@ public function dumpString(Cursor $cursor, $str, $bin, $cut)
140140
$this->line .= '""';
141141
$this->dumpLine($cursor->depth);
142142
} else {
143+
$attr = array(
144+
'length' => function_exists('iconv_strlen') && 0 <= $cut ? iconv_strlen($str, 'UTF-8') + $cut : 0,
145+
'binary' => $bin,
146+
);
143147
$str = explode("\n", $str);
144148
$m = count($str) - 1;
145149
$i = $lineCut = 0;
@@ -164,7 +168,7 @@ public function dumpString(Cursor $cursor, $str, $bin, $cut)
164168
if ($m) {
165169
$this->line .= $this->indentPad;
166170
}
167-
$this->line .= $this->style('str', $str);
171+
$this->line .= $this->style('str', $str, $attr);
168172

169173
if ($i++ == $m) {
170174
$this->line .= '"';
@@ -204,13 +208,13 @@ public function enterHash(Cursor $cursor, $type, $class, $hasChild)
204208
}
205209

206210
if (Cursor::HASH_RESOURCE === $type) {
207-
$prefix .= $this->style('ref', '@'.$cursor->softRefHandle);
211+
$prefix .= $this->style($cursor->softRefCount ? 'ref' : 'solo-ref', '@'.$cursor->softRefHandle, array('count' => $cursor->softRefCount));
208212
} elseif ($cursor->softRefTo) {
209-
$prefix .= $this->style('ref', '#'.(0 < $cursor->softRefHandle ? $cursor->softRefHandle : $cursor->softRefTo));
213+
$prefix .= $this->style('ref', '#'.(0 < $cursor->softRefHandle ? $cursor->softRefHandle : $cursor->softRefTo), array('count' => $cursor->softRefCount));
210214
} elseif (0 < $cursor->softRefHandle) {
211215
$prefix .= $this->style('solo-ref', '#'.$cursor->softRefHandle);
212216
} elseif ($cursor->hardRefTo && !$cursor->refIndex && $class) {
213-
$prefix .= $this->style('ref', '&'.$cursor->hardRefTo);
217+
$prefix .= $this->style('ref', '&'.$cursor->hardRefTo, array('count' => $cursor->hardRefCount));
214218
}
215219

216220
$this->line .= $prefix;
@@ -258,7 +262,8 @@ protected function dumpEllipsis(Cursor $cursor, $hasChild, $cut)
258262
protected function dumpKey(Cursor $cursor)
259263
{
260264
if (null !== $key = $cursor->hashKey) {
261-
if ($bin = isset($key[0]) && !preg_match('//u', $key)) {
265+
$attr = array('binary' => isset($key[0]) && !preg_match('//u', $key));
266+
if ($bin = $attr['binary']) {
262267
$key = Data::utf8Encode($key);
263268
$bin = 'b';
264269
}
@@ -284,24 +289,28 @@ protected function dumpKey(Cursor $cursor)
284289

285290
switch ($key[0]) {
286291
case '+': // User inserted keys
287-
$this->line .= $bin.'"'.$this->style('public', $key[1]).'": ';
292+
$attr['dynamic'] = true;
293+
$this->line .= $bin.'"'.$this->style('public', $key[1], $attr).'": ';
288294
break 2;
289295

290296
case '~': $style = 'meta'; break;
291297
case '*': $style = 'protected'; break;
292-
default: $style = 'private'; break;
298+
default:
299+
$attr['class'] = $key[0];
300+
$style = 'private';
301+
break;
293302
}
294303

295-
$this->line .= $bin.$this->style($style, $key[1]).': ';
304+
$this->line .= $bin.$this->style($style, $key[1], $attr).': ';
296305
} else {
297306
// This case should not happen
298-
$this->line .= $bin.'"'.$this->style('private', $key).'": ';
307+
$this->line .= $bin.'"'.$this->style('private', $key, array('class' => '')).'": ';
299308
}
300309
break;
301310
}
302311

303312
if ($cursor->hardRefTo) {
304-
$this->line .= ($cursor->hardRefCount ? $this->style('ref', '&'.$cursor->hardRefTo) : $this->style('solo-ref', '&')).' ';
313+
$this->line .= ($cursor->hardRefCount ? $this->style('ref', '&'.$cursor->hardRefTo, array('count' => $cursor->hardRefCount)) : $this->style('solo-ref', '&')).' ';
305314
}
306315
}
307316
}
@@ -310,32 +319,28 @@ protected function dumpKey(Cursor $cursor)
310319
* Decorates a value with some style.
311320
*
312321
* @param string $style The type of style being applied.
313-
* @param string $val The value being styled.
322+
* @param string $value The value being styled.
323+
* @param array $attr Optional context information.
314324
*
315325
* @return string The value with style decoration.
316326
*/
317-
protected function style($style, $val)
327+
protected function style($style, $value, $attr = array())
318328
{
319329
if (null === $this->colors) {
320330
$this->colors = $this->supportsColors($this->outputStream);
321331
}
322332

323-
if (!$this->colors || '' === $val) {
324-
return $val;
333+
if (!$this->colors || '' === $value) {
334+
return $value;
325335
}
326336

327-
if ('str' === $style || 'meta' === $style || 'public' === $style) {
328-
foreach (static::$controlChars as $c) {
329-
if (false !== strpos($val, $c)) {
330-
$r = "\x7F" === $c ? '?' : chr(64 + ord($c));
331-
$r = "\033[{$this->styles[$style]};{$this->styles['cchr']}m{$r}\033[m";
332-
$r = "\033[m{$r}\033[{$this->styles[$style]}m";
333-
$val = str_replace($c, $r, $val);
334-
}
335-
}
336-
}
337+
$style = $this->styles[$style];
338+
$cchr = "\033[m\033[{$style};{$this->styles['cchr']}m%s\033[m\033[{$style}m";
339+
$value = preg_replace_callback(self::$controlCharsRx, function ($r) use ($cchr) {
340+
return sprintf($cchr, "\x7F" === $r[0] ? '?' : chr(64 + ord($r[0])));
341+
}, $value);
337342

338-
return sprintf("\033[%sm%s\033[m", $this->styles[$style], $val);
343+
return sprintf("\033[%sm%s\033[m", $style, $value);
339344
}
340345

341346
/**

0 commit comments

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