Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 893b3c4

Browse files
alexandre-dauboisnicolas-grekas
authored andcommitted
[VarDumper] Select HtmlDumper only if Accept header contains "html"
1 parent 1da4bab commit 893b3c4

File tree

3 files changed

+19
-2
lines changed

3 files changed

+19
-2
lines changed

src/Symfony/Component/VarDumper/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ CHANGELOG
55
---
66

77
* Add support for adding more default casters to `AbstractCloner::addDefaultCasters()`
8+
* Select HtmlDumper only if `Accept` header contains "html"
89

910
7.3
1011
---
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
--TEST--
2+
Test dump() with "Accept: text/html" uses HTML dumper
3+
--FILE--
4+
<?php
5+
putenv('NO_COLOR=1');
6+
7+
$vendor = __DIR__;
8+
while (!file_exists($vendor.'/vendor')) {
9+
$vendor = \dirname($vendor);
10+
}
11+
require $vendor.'/vendor/autoload.php';
12+
13+
$_SERVER['HTTP_ACCEPT'] = 'text/html';
14+
dump('Test with HTML');
15+
--EXPECTF--
16+
%a>Test with HTML</%a

src/Symfony/Component/VarDumper/VarDumper.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,11 +76,11 @@ private static function register(): void
7676
case 'server' === $format:
7777
case $format && 'tcp' === parse_url($format, \PHP_URL_SCHEME):
7878
$host = 'server' === $format ? $_SERVER['VAR_DUMPER_SERVER'] ?? '127.0.0.1:9912' : $format;
79-
$dumper = \in_array(\PHP_SAPI, ['cli', 'phpdbg', 'embed'], true) ? new CliDumper() : new HtmlDumper();
79+
$dumper = str_contains($_SERVER['HTTP_ACCEPT'] ?? (\in_array(\PHP_SAPI, ['cli', 'phpdbg', 'embed'], true) ? 'txt' : 'html'), 'html') ? new HtmlDumper() : new CliDumper();
8080
$dumper = new ServerDumper($host, $dumper, self::getDefaultContextProviders());
8181
break;
8282
default:
83-
$dumper = \in_array(\PHP_SAPI, ['cli', 'phpdbg', 'embed'], true) ? new CliDumper() : new HtmlDumper();
83+
$dumper = str_contains($_SERVER['HTTP_ACCEPT'] ?? (\in_array(\PHP_SAPI, ['cli', 'phpdbg', 'embed'], true) ? 'txt' : 'html'), 'html') ? new HtmlDumper() : new CliDumper();
8484
}
8585

8686
if (!$dumper instanceof ServerDumper) {

0 commit comments

Comments
 (0)