Skip to content

Commit

Permalink
bug #12411 [VarDumper] Use Unicode Control Pictures (nicolas-grekas)
Browse files Browse the repository at this point in the history
This PR was merged into the 2.6-dev branch.

Discussion
----------

[VarDumper] Use Unicode Control Pictures

| Q             | A
| ------------- | ---
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | -
| License       | MIT
| Doc PR        | -

I wasn't satisfied with how control chars where dumped, until I found the [Unicode Control Pictures](http://www.unicode.org/charts/PDF/U2400.pdf).
This PR takes advantage of them:

![capture du 2014-11-04 10 52 15](https://cloud.githubusercontent.com/assets/243674/4897678/752fac20-6408-11e4-9186-7b788c9a88bb.png)

Commits
-------

6258ae8 [DebugBundle] remove README.md
50021bd [Debug] No gc_collect_cycles(), it's costly and can segfault
b592e90 [VarDumper] inline dump() function loading
cd076e4 [VarDumper] Use Unicode Control Pictures
  • Loading branch information
fabpot committed Nov 9, 2014
2 parents 5d8fbb8 + 6258ae8 commit ad74db9
Show file tree
Hide file tree
Showing 8 changed files with 23 additions and 28 deletions.
15 changes: 15 additions & 0 deletions UPGRADE-2.6.md
Expand Up @@ -349,3 +349,18 @@ OptionsResolver
// throws InvalidOptionsException
$resolver->resolve(array('port' => '25'));
```

VarDumper and DebugBundle
-------------------------

The component and the bundle are new to Symfony 2.6. We encourage you
to enable the bundle in your `app/AppKernel.php` for the *dev* or *test*
environments. Just add this line before loading the `WebProfilerBundle`:

```php
$bundles[] = new Symfony\Bundle\DebugBundle\DebugBundle();
```

Then enjoy dumping variables by calling `dump($var)` anywhere in your PHP
and `{% dump var %}` or `{{ dump(var) }}` in Twig. Dumps are displayed
**in the web debug toolbar**.
22 changes: 0 additions & 22 deletions src/Symfony/Bundle/DebugBundle/README.md

This file was deleted.

1 change: 0 additions & 1 deletion src/Symfony/Component/Debug/ErrorHandler.php
Expand Up @@ -487,7 +487,6 @@ public function handleException(\Exception $exception, array $error = null)
public static function handleFatalError(array $error = null)
{
self::$reservedMemory = '';
gc_collect_cycles();
$handler = set_error_handler('var_dump', 0);
$handler = is_array($handler) ? $handler[0] : null;
restore_error_handler();
Expand Down
1 change: 0 additions & 1 deletion src/Symfony/Component/VarDumper/Cloner/AbstractCloner.php
Expand Up @@ -84,7 +84,6 @@ abstract class AbstractCloner implements ClonerInterface
protected $maxString = -1;

private $casters = array();
private $data = array(array(null));
private $prevErrorHandler;
private $classInfo = array();

Expand Down
2 changes: 1 addition & 1 deletion src/Symfony/Component/VarDumper/Dumper/CliDumper.php
Expand Up @@ -331,7 +331,7 @@ protected function dumpKey(Cursor $cursor)
}

if ($cursor->hardRefTo) {
$this->line .= $this->style('ref', '&'.$cursor->hardRefTo, array('count' => $cursor->hardRefCount)).' ';
$this->line .= $this->style('ref', '&'.($cursor->hardRefCount ? $cursor->hardRefTo : ''), array('count' => $cursor->hardRefCount)).' ';
}
}
}
Expand Down
5 changes: 3 additions & 2 deletions src/Symfony/Component/VarDumper/Dumper/HtmlDumper.php
Expand Up @@ -35,7 +35,7 @@ class HtmlDumper extends CliDumper
'num' => 'font-weight:bold; color:#1299DA',
'const' => 'font-weight:bold',
'str' => 'font-weight:bold; color:#56DB3A',
'cchr' => 'font-style:italic',
'cchr' => 'color:#FF8400',
'note' => 'color:#1299DA',
'ref' => 'color:#A0A0A0',
'public' => 'color:#FFFFFF',
Expand Down Expand Up @@ -319,7 +319,8 @@ protected function style($style, $value, $attr = array())

$v = htmlspecialchars($value, ENT_QUOTES, 'UTF-8');
$v = preg_replace_callback(self::$controlCharsRx, function ($r) {
return sprintf('<span class=sf-dump-cchr title=\\x%02X>%s</span>', ord($r[0]), "\x7F" === $r[0] ? '?' : chr(64 + ord($r[0])));
// Use Unicode Control Pictures - see http://www.unicode.org/charts/PDF/U2400.pdf
return sprintf('<span class=sf-dump-cchr title=\\x%02X>&#%d;</span>', ord($r[0]), "\x7F" !== $r[0] ? 0x2400 + ord($r[0]) : 0x2421);
}, $v);

if ('ref' === $style) {
Expand Down
2 changes: 1 addition & 1 deletion src/Symfony/Component/VarDumper/Tests/HtmlDumperTest.php
Expand Up @@ -62,7 +62,7 @@ public function testGet()
<span class=sf-dump-key>5</span> => <span class=sf-dump-num>-INF</span>
<span class=sf-dump-key>6</span> => <span class=sf-dump-num>{$intMax}</span>
"<span class=sf-dump-key>str</span>" => "<span class=sf-dump-str title="4 characters">d&#233;j&#224;</span>"
<span class=sf-dump-key>7</span> => b"<span class=sf-dump-str title="2 binary or non-UTF-8 characters">&#233;<span class=sf-dump-cchr title=\\x00>@</span></span>"
<span class=sf-dump-key>7</span> => b"<span class=sf-dump-str title="2 binary or non-UTF-8 characters">&#233;<span class=sf-dump-cchr title=\\x00>&#9216;</span></span>"
"<span class=sf-dump-key>[]</span>" => []
"<span class=sf-dump-key>res</span>" => <abbr title="`stream` resource" class=sf-dump-note>:stream</abbr> {<a class=sf-dump-ref>@{$res1}</a><samp>
<span class=sf-dump-meta>wrapper_type</span>: "<span class=sf-dump-str title="9 characters">plainfile</span>"
Expand Down
3 changes: 3 additions & 0 deletions src/Symfony/Component/VarDumper/VarDumper.php
Expand Up @@ -15,6 +15,9 @@
use Symfony\Component\VarDumper\Dumper\CliDumper;
use Symfony\Component\VarDumper\Dumper\HtmlDumper;

// Load the global dump() function
require_once __DIR__.'/Resources/functions/dump.php';

/**
* @author Nicolas Grekas <p@tchwork.com>
*/
Expand Down

0 comments on commit ad74db9

Please sign in to comment.