[VarDumper] Backport handler lock when using VAR_DUMPER_FORMAT
authorMaxime Steinhausser <maxime.steinhausser@elao.com>
Fri, 14 Aug 2020 14:49:01 +0000 (16:49 +0200)
committerMaxime Steinhausser <maxime.steinhausser@elao.com>
Fri, 14 Aug 2020 15:54:02 +0000 (17:54 +0200)
src/Symfony/Component/HttpKernel/DataCollector/DumpDataCollector.php
src/Symfony/Component/VarDumper/VarDumper.php

index d9f381b..4e430f8 100644 (file)
@@ -235,13 +235,7 @@ class DumpDataCollector extends DataCollector implements DataDumperInterface
                 --$i;
             }
 
-            if (isset($_SERVER['VAR_DUMPER_FORMAT'])) {
-                $html = 'html' === $_SERVER['VAR_DUMPER_FORMAT'];
-            } else {
-                $html = !\in_array(\PHP_SAPI, ['cli', 'phpdbg'], true) && stripos($h[$i], 'html');
-            }
-
-            if ($html) {
+            if (!\in_array(\PHP_SAPI, ['cli', 'phpdbg'], true) && stripos($h[$i], 'html')) {
                 $dumper = new HtmlDumper('php://output', $this->charset);
                 $dumper->setDisplayOptions(['fileLinkFormat' => $this->fileLinkFormat]);
             } else {
index d336d5d..febc1e0 100644 (file)
@@ -53,6 +53,12 @@ class VarDumper
     public static function setHandler(callable $callable = null)
     {
         $prevHandler = self::$handler;
+
+        // Prevent replacing the handler with expected format as soon as the env var was set:
+        if (isset($_SERVER['VAR_DUMPER_FORMAT'])) {
+            return $prevHandler;
+        }
+
         self::$handler = $callable;
 
         return $prevHandler;