Skip to content

Commit 597a4a1

Browse files
Merge branch '7.0' into 7.1
* 7.0: (21 commits) [ErrorHandler] Add missing self-closing tags on link elements Fix merge (bis) Fix merge Add missing return type [FrameworkBundle] ConfigBuilderCacheWarmer should be non-optional [HttpClient] Fix pausing responses before they start when using curl [Notifier] Updated the NTFY notifier to run without a user parameter [Translation] Fix constant domain resolution in PhpAstExtractor separate child and parent context in NotificationEmail on writes [Mailer] [Mailgun] Fix sender header encoding do not overwrite the cache key when it is false [Mailer] [Scaleway] Fix attachment handling [Mailer] Throw TransportException when unable to read from socket [Serializer] Rewrite `AbstractObjectNormalizer::createChildContext()` to use the provided `cache_key` from original context when creating child contexts Revert #47715 [HttpClient] Fix error chunk creation in passthru Adjusting and removing the 'review' attribute from the pt_br translation XML. [DependencyInjection] Fix loading all env vars from secrets when only a subset is needed Fix option filenameMaxLength to the File constraint (Image) [Serializer] Take unnamed variadic parameters into account when denormalizing ...
2 parents c05c9cc + 9f203a7 commit 597a4a1

File tree

3 files changed

+32
-5
lines changed

3 files changed

+32
-5
lines changed

EnvVarLoaderInterface.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
interface EnvVarLoaderInterface
2020
{
2121
/**
22-
* @return string[] Key/value pairs that can be accessed using the regular "%env()%" syntax
22+
* @return array<string|\Stringable> Key/value pairs that can be accessed using the regular "%env()%" syntax
2323
*/
2424
public function loadEnvVars(): array;
2525
}

EnvVarProcessor.php

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -165,10 +165,16 @@ public function getEnv(string $prefix, string $name, \Closure $getEnv): mixed
165165
if (false !== $i || 'string' !== $prefix) {
166166
$env = $getEnv($name);
167167
} elseif ('' === ($env = $_ENV[$name] ?? (str_starts_with($name, 'HTTP_') ? null : ($_SERVER[$name] ?? null)))
168-
|| (false !== $env && false === ($env = $env ?? getenv($name) ?? false)) // null is a possible value because of thread safety issues
168+
|| (false !== $env && false === $env ??= getenv($name) ?? false) // null is a possible value because of thread safety issues
169169
) {
170-
foreach ($this->loadedVars as $vars) {
171-
if (false !== ($env = ($vars[$name] ?? $env)) && '' !== $env) {
170+
foreach ($this->loadedVars as $i => $vars) {
171+
if (false === $env = $vars[$name] ?? $env) {
172+
continue;
173+
}
174+
if ($env instanceof \Stringable) {
175+
$this->loadedVars[$i][$name] = $env = (string) $env;
176+
}
177+
if ('' !== ($env ?? '')) {
172178
break;
173179
}
174180
}
@@ -186,7 +192,13 @@ public function getEnv(string $prefix, string $name, \Closure $getEnv): mixed
186192
continue;
187193
}
188194
$this->loadedVars[] = $vars = $loader->loadEnvVars();
189-
if (false !== ($env = ($vars[$name] ?? $env)) && '' !== $env) {
195+
if (false === $env = $vars[$name] ?? $env) {
196+
continue;
197+
}
198+
if ($env instanceof \Stringable) {
199+
$this->loadedVars[array_key_last($this->loadedVars)][$name] = $env = (string) $env;
200+
}
201+
if ('' !== ($env ?? '')) {
190202
$ended = false;
191203
break;
192204
}

Tests/EnvVarProcessorTest.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -808,6 +808,12 @@ public function loadEnvVars(): array
808808
return [
809809
'FOO_ENV_LOADER' => '123',
810810
'BAZ_ENV_LOADER' => '',
811+
'LAZY_ENV_LOADER' => new class() {
812+
public function __toString()
813+
{
814+
return '';
815+
}
816+
},
811817
];
812818
}
813819
};
@@ -819,6 +825,12 @@ public function loadEnvVars(): array
819825
'FOO_ENV_LOADER' => '234',
820826
'BAR_ENV_LOADER' => '456',
821827
'BAZ_ENV_LOADER' => '567',
828+
'LAZY_ENV_LOADER' => new class() {
829+
public function __toString()
830+
{
831+
return '678';
832+
}
833+
},
822834
];
823835
}
824836
};
@@ -841,6 +853,9 @@ public function loadEnvVars(): array
841853
$result = $processor->getEnv('string', 'FOO_ENV_LOADER', function () {});
842854
$this->assertSame('123', $result); // check twice
843855

856+
$result = $processor->getEnv('string', 'LAZY_ENV_LOADER', function () {});
857+
$this->assertSame('678', $result);
858+
844859
unset($_ENV['BAZ_ENV_LOADER']);
845860
unset($_ENV['BUZ_ENV_LOADER']);
846861
}

0 commit comments

Comments
 (0)