Skip to content

Commit 9f203a7

Browse files
Merge branch '6.4' into 7.0
* 6.4: (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 b95f9bb + a3fe5b0 commit 9f203a7

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
@@ -164,10 +164,16 @@ public function getEnv(string $prefix, string $name, \Closure $getEnv): mixed
164164
if (false !== $i || 'string' !== $prefix) {
165165
$env = $getEnv($name);
166166
} elseif ('' === ($env = $_ENV[$name] ?? (str_starts_with($name, 'HTTP_') ? null : ($_SERVER[$name] ?? null)))
167-
|| (false !== $env && false === ($env = $env ?? getenv($name) ?? false)) // null is a possible value because of thread safety issues
167+
|| (false !== $env && false === $env ??= getenv($name) ?? false) // null is a possible value because of thread safety issues
168168
) {
169-
foreach ($this->loadedVars as $vars) {
170-
if (false !== ($env = ($vars[$name] ?? $env)) && '' !== $env) {
169+
foreach ($this->loadedVars as $i => $vars) {
170+
if (false === $env = $vars[$name] ?? $env) {
171+
continue;
172+
}
173+
if ($env instanceof \Stringable) {
174+
$this->loadedVars[$i][$name] = $env = (string) $env;
175+
}
176+
if ('' !== ($env ?? '')) {
171177
break;
172178
}
173179
}
@@ -185,7 +191,13 @@ public function getEnv(string $prefix, string $name, \Closure $getEnv): mixed
185191
continue;
186192
}
187193
$this->loadedVars[] = $vars = $loader->loadEnvVars();
188-
if (false !== ($env = ($vars[$name] ?? $env)) && '' !== $env) {
194+
if (false === $env = $vars[$name] ?? $env) {
195+
continue;
196+
}
197+
if ($env instanceof \Stringable) {
198+
$this->loadedVars[array_key_last($this->loadedVars)][$name] = $env = (string) $env;
199+
}
200+
if ('' !== ($env ?? '')) {
189201
$ended = false;
190202
break;
191203
}

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)