Skip to content

Commit 09357c9

Browse files
[DebugBundle] adjust after review
1 parent c6e23bd commit 09357c9

File tree

5 files changed

+91
-12
lines changed

5 files changed

+91
-12
lines changed

Caster/DOMCaster.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,8 @@ public static function castImplementation($dom, array $a, $isNested, &$cut)
6868

6969
public static function castNode(\DOMNode $dom, array $a, $isNested, &$cut)
7070
{
71+
// Commented lines denote properties that exist but are better not dumped for clarity.
72+
7173
$a += array(
7274
'nodeName' => $dom->nodeName,
7375
//'nodeValue' => $dom->nodeValue,
@@ -93,6 +95,8 @@ public static function castNode(\DOMNode $dom, array $a, $isNested, &$cut)
9395

9496
public static function castNameSpaceNode(\DOMNameSpaceNode $dom, array $a, $isNested, &$cut)
9597
{
98+
// Commented lines denote properties that exist but are better not dumped for clarity.
99+
96100
$a += array(
97101
'nodeName' => $dom->nodeName,
98102
//'nodeValue' => $dom->nodeValue,

Cloner/Data.php

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -183,19 +183,19 @@ public static function utf8Encode($s)
183183
{
184184
if (function_exists('iconv')) {
185185
return iconv('CP1252', 'UTF-8', $s);
186-
} else {
187-
$s .= $s;
188-
$len = strlen($s);
189-
190-
for ($i = $len >> 1, $j = 0; $i < $len; ++$i, ++$j) {
191-
switch (true) {
192-
case $s[$i] < "\x80": $s[$j] = $s[$i]; break;
193-
case $s[$i] < "\xC0": $s[$j] = "\xC2"; $s[++$j] = $s[$i]; break;
194-
default: $s[$j] = "\xC3"; $s[++$j] = chr(ord($s[$i]) - 64); break;
195-
}
196-
}
186+
}
197187

198-
return substr($s, 0, $j);
188+
$s .= $s;
189+
$len = strlen($s);
190+
191+
for ($i = $len >> 1, $j = 0; $i < $len; ++$i, ++$j) {
192+
switch (true) {
193+
case $s[$i] < "\x80": $s[$j] = $s[$i]; break;
194+
case $s[$i] < "\xC0": $s[$j] = "\xC2"; $s[++$j] = $s[$i]; break;
195+
default: $s[$j] = "\xC3"; $s[++$j] = chr(ord($s[$i]) - 64); break;
196+
}
199197
}
198+
199+
return substr($s, 0, $j);
200200
}
201201
}

Resources/functions/dump.php

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <[email protected]>
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+
use Symfony\Component\VarDumper\VarDumper;
13+
14+
if (!function_exists('dump')) {
15+
/**
16+
* @author Nicolas Grekas <[email protected]>
17+
*/
18+
function dump($var)
19+
{
20+
foreach (func_get_args() as $var) {
21+
VarDumper::dump($var);
22+
}
23+
}
24+
}

VarDumper.php

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <[email protected]>
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;
13+
14+
use Symfony\Component\VarDumper\Cloner\ExtCloner;
15+
use Symfony\Component\VarDumper\Cloner\PhpCloner;
16+
use Symfony\Component\VarDumper\Dumper\CliDumper;
17+
use Symfony\Component\VarDumper\Dumper\HtmlDumper;
18+
19+
/**
20+
* @author Nicolas Grekas <[email protected]>
21+
*/
22+
class VarDumper
23+
{
24+
private static $handler;
25+
26+
public static function dump($var)
27+
{
28+
if (null === self::$handler) {
29+
$cloner = extension_loaded('symfony_debug') ? new ExtCloner() : new PhpCloner();
30+
$dumper = 'cli' === PHP_SAPI ? new CliDumper() : new HtmlDumper();
31+
self::$handler = function ($var) use ($cloner, $dumper) {
32+
$dumper->dump($cloner->cloneVar($var));
33+
};
34+
}
35+
36+
return call_user_func(self::$handler, $h);
37+
}
38+
39+
public static function setHandler($callable)
40+
{
41+
if (!is_callable($callable, true)) {
42+
throw new \InvalidArgumentException('Invalid PHP callback.');
43+
}
44+
45+
$prevHandler = self::$handler;
46+
self::$handler = $callable;
47+
48+
return $prevHandler;
49+
}
50+
}

composer.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
"ext-symfony_debug": ""
1919
},
2020
"autoload": {
21+
"files": [ "Resources/functions/dump.php" ],
2122
"psr-0": { "Symfony\\Component\\VarDumper\\": "" }
2223
},
2324
"target-dir": "Symfony/Component/VarDumper",

0 commit comments

Comments
 (0)