8000 [VarDumper][DebugBundle] Fix dump labels compatibility · symfony/symfony@7c55551 · GitHub
[go: up one dir, main page]

Skip to content

Commit 7c55551

Browse files
committed
[VarDumper][DebugBundle] Fix dump labels compatibility
1 parent 825fd03 commit 7c55551

File tree

5 files changed

+27
-11
lines changed

5 files changed

+27
-11
lines changed

src/Symfony/Bundle/DebugBundle/DebugBundle.php

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,14 +35,19 @@ public function boot()
3535
// The dump data collector is used by default, so dump output is sent to
3636
// the WDT. In a CLI context, if dump is used too soon, the data collector
3737
// will buffer it, and release it at the end of the script.
38-
VarDumper::setHandler(function ($var) use ($container) {
38+
VarDumper::setHandler(function ($var, string $label = null) use ($container) {
3939
$dumper = $container->get('data_collector.dump');
4040
$cloner = $container->get('var_dumper.cloner');
41-
$handler = function ($var) use ($dumper, $cloner) {
42-
$dumper->dump($cloner->cloneVar($var));
41+
$handler = function ($var, string $label = null) use ($dumper, $cloner) {
42+
$var = $cloner->cloneVar($var);
43+
if (null !== $label) {
44+
$var = $var->withContext(['label' => $label]);
45+
}
46+
47+
$dumper->dump($var);
4348
};
4449
VarDumper::setHandler($handler);
45-
$handler($var);
50+
$handler($var, $label);
4651
});
4752
}
4853
}

src/Symfony/Component/HttpKernel/EventListener/DumpListener.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,11 @@ public function configure()
4545
$dumper = $this->dumper;
4646
$connection = $this->connection;
4747

48-
VarDumper::setHandler(static function ($var) use ($cloner, $dumper, $connection) {
48+
VarDumper::setHandler(static function ($var, string $label = null) use ($cloner, $dumper, $connection) {
4949
$data = $cloner->cloneVar($var);
50+
if (null !== $label) {
51+
$data = $data->withContext(['label' => $label]);
52+
}
5053

5154
if (!$connection || !$connection->write($data)) {
5255
$dumper->dump($data);

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

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -271,11 +271,19 @@ public function dump(DumperInterface $dumper)
271271
$cursor = new Cursor();
272272
$label = $this->context['label'] ?? '';
273273

274-
if ($cursor->attr = $this->context[SourceContextProvider::class] ?? []) {
275-
$cursor->attr['if_links'] = true;
274+
if (($cursor->attr = $this->context[SourceContextProvider::class] ?? []) || '' !== $label) {
275+
$label .= '^';
276+
if ($cursor->attr) {
277+
$cursor->attr['if_links'] = '^' === $label ? true : $label;
278+
}
279+
276280
$cursor->hashType = -1;
277-
$dumper->dumpScalar($cursor, 'default', $label.'^');
278-
$cursor->attr = ['if_links' => true];
281+
$dumper->dumpScalar($cursor, 'default', $label);
282+
283+
if ($cursor->attr) {
284+
$cursor->attr = ['if_links' => '^' === $label ? true : ' '];
285+
}
286+
279287
$dumper->dumpScalar($cursor, 'default', ' ');
280288
$cursor->hashType = 0;
281289
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -513,7 +513,7 @@ protected function style(string $style, string $value, array $attr = []): string
513513
$value = "\033]8;;{$attr['href']}\033\\{$value}\033]8;;\033\\";
514514
}
515515
} elseif ($attr['if_links'] ?? false) {
516-
return '';
516+
return \is_string($attr['if_links']) ? $attr['if_links'] : '';
517517
}
518518

519519
return $value;

src/Symfony/Component/VarDumper/Resources/functions/dump.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ function dump(mixed ...$vars): mixed
2525
return null;
2626
}
2727

28-
if (isset($vars[0]) && 1 === count($vars)) {
28+
if (array_key_exists(0, $vars) && 1 === count($vars)) {
2929
VarDumper::dump($vars[0]);
3030
$k = 0;
3131
} else {

0 commit comments

Comments
 (0)
0