Skip to content

Commit e6947d1

Browse files
Merge branch '6.3' into 6.4
* 6.3: [Cache] Fix Redis6Proxy [Finder] Disable failing test about open_basedir Fix merge Fix merge [Notifier] Telegram Bridge add escaping for \ [Routing] Fix routing collection defaults when adding a new route to a collection [Messenger] Fix cloned TraceableStack not unstacking the stack independently [DependencyInjection] Fix autocasting null env values to empty string with container.env_var_processors_locator [Cache] Fix support for Redis Sentinel using php-redis 6.0.0 [Notifier] Fix Smsmode HttpClient mandatory headers minor #51693 Disable the dead code analysis in Psalm (stof) Update the PR template [SecurityBundle][PasswordHasher] Fix password migration with custom hasher service with security bundle config [Translator] Fix support for `default_path` in XML [FrameworkBundle] Handle tags array attributes in descriptors [HttpClient] Fix TraceableResponse if response has no destruct method [FrameworkBundle] Always use buildDir as `ConfigBuilderGenerator` outputDir
2 parents 57ca450 + 2ed62b3 commit e6947d1

File tree

3 files changed

+33
-7
lines changed

3 files changed

+33
-7
lines changed

Container.php

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -373,13 +373,9 @@ protected function getEnv(string $name): mixed
373373
$localName = $name;
374374
}
375375

376-
if ($processors->has($prefix)) {
377-
$processor = $processors->get($prefix);
378-
} else {
379-
$processor = new EnvVarProcessor($this);
380-
if (false === $i) {
381-
$prefix = '';
382-
}
376+
$processor = $processors->has($prefix) ? $processors->get($prefix) : new EnvVarProcessor($this);
377+
if (false === $i) {
378+
$prefix = '';
383379
}
384380

385381
$this->resolving[$envName] = true;

EnvVarProcessorInterface.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ interface EnvVarProcessorInterface
2424
* Returns the value of the given variable as managed by the current instance.
2525
*
2626
* @param string $prefix The namespace of the variable
27+
* @param string $prefix The namespace of the variable; when the empty string is passed, null values should be kept as is
2728
* @param string $name The name of the variable within the namespace
2829
* @param \Closure(string): mixed $getEnv A closure that allows fetching more env vars
2930
*

Tests/ContainerTest.php

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,13 @@
1414
use PHPUnit\Framework\TestCase;
1515
use Symfony\Component\DependencyInjection\Container;
1616
use Symfony\Component\DependencyInjection\ContainerInterface;
17+
use Symfony\Component\DependencyInjection\EnvVarProcessor;
1718
use Symfony\Component\DependencyInjection\Exception\InvalidArgumentException;
1819
use Symfony\Component\DependencyInjection\Exception\ServiceCircularReferenceException;
1920
use Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException;
2021
use Symfony\Component\DependencyInjection\ParameterBag\FrozenParameterBag;
2122
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBag;
23+
use Symfony\Component\DependencyInjection\ServiceLocator;
2224
use Symfony\Contracts\Service\ResetInterface;
2325

2426
class ContainerTest extends TestCase
@@ -404,6 +406,33 @@ public function testRequestAnInternalSharedPrivateService()
404406
$c->get('internal_dependency');
405407
$c->get('internal');
406408
}
409+
410+
public function testGetEnvDoesNotAutoCastNullWithDefaultEnvVarProcessor()
411+
{
412+
$container = new Container();
413+
$container->setParameter('env(FOO)', null);
414+
$container->compile();
415+
416+
$r = new \ReflectionMethod($container, 'getEnv');
417+
$r->setAccessible(true);
418+
$this->assertNull($r->invoke($container, 'FOO'));
419+
}
420+
421+
public function testGetEnvDoesNotAutoCastNullWithEnvVarProcessorsLocatorReturningDefaultEnvVarProcessor()
422+
{
423+
$container = new Container();
424+
$container->setParameter('env(FOO)', null);
425+
$container->set('container.env_var_processors_locator', new ServiceLocator([
426+
'string' => static function () use ($container): EnvVarProcessor {
427+
return new EnvVarProcessor($container);
428+
},
429+
]));
430+
$container->compile();
431+
432+
$r = new \ReflectionMethod($container, 'getEnv');
433+
$r->setAccessible(true);
434+
$this->assertNull($r->invoke($container, 'FOO'));
435+
}
407436
}
408437

409438
class ProjectServiceContainer extends Container

0 commit comments

Comments
 (0)