Skip to content

Commit 936cb7d

Browse files
committed
Read environment variable from superglobals
The Dotenv component has recently been switched to using superglobals instead of putenv(). Let us support both and give priority to superglobals. Closes #31857
1 parent 3b0e9df commit 936cb7d

File tree

2 files changed

+32
-3
lines changed

2 files changed

+32
-3
lines changed

src/Symfony/Bridge/PhpUnit/DeprecationErrorHandler.php

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,19 @@ public static function register($mode = 0)
9090
}
9191
}
9292

93+
/**
94+
* @return bool
95+
*/
96+
public static function isEnabled()
97+
{
98+
return self::getModeFromEnvironment() !== 'disabled';
99+
}
100+
101+
public static function registerAndConfigureFromEnvironment()
102+
{
103+
self::register(self::getModeFromEnvironment());
104+
}
105+
93106
public static function collectDeprecations($outputFile)
94107
{
95108
$deprecations = [];
@@ -209,12 +222,28 @@ public function shutdown()
209222
});
210223
}
211224

225+
/**
226+
* @return mixed string|false
227+
*/
228+
private static function getModeFromEnvironment()
229+
{
230+
if (isset($_SERVER['SYMFONY_DEPRECATIONS_HELPER'])) {
231+
return $_SERVER['SYMFONY_DEPRECATIONS_HELPER'];
232+
}
233+
234+
if (isset($_ENV['SYMFONY_DEPRECATIONS_HELPER'])) {
235+
return $_ENV['SYMFONY_DEPRECATIONS_HELPER'];
236+
}
237+
238+
return getenv('SYMFONY_DEPRECATIONS_HELPER');
239+
}
240+
212241
private function getConfiguration()
213242
{
214243
if (null !== $this->configuration) {
215244
return $this->configuration;
216245
}
217-
$mode = getenv('SYMFONY_DEPRECATIONS_HELPER');
246+
$mode = self::getModeFromEnvironment();
218247
if ('strict' === $mode) {
219248
return $this->configuration = Configuration::inStrictMode();
220249
}

src/Symfony/Bridge/PhpUnit/bootstrap.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,6 @@
3535
}
3636
}
3737

38-
if ('disabled' !== getenv('SYMFONY_DEPRECATIONS_HELPER')) {
39-
DeprecationErrorHandler::register(getenv('SYMFONY_DEPRECATIONS_HELPER'));
38+
if (DeprecationErrorHandler::isEnabled()) {
39+
DeprecationErrorHandler::registerAndConfigureFromEnvironment();
4040
}

0 commit comments

Comments
 (0)