Skip to content

Commit 0bd175f

Browse files
committed
Merge branch '5.4' into 6.3
* 5.4: [DotEnv] Mention the `overrideExistingVars` parameter of `DotEnv` simplify compiler pass example
2 parents ed5f0c6 + ab4e69f commit 0bd175f

File tree

2 files changed

+29
-15
lines changed

2 files changed

+29
-15
lines changed

configuration.rst

+19
Original file line numberDiff line numberDiff line change
@@ -885,6 +885,25 @@ the env files ending in ``.local`` (``.env.local`` and ``.env.<environment>.loca
885885
**should not be committed** because only you will use them. In fact, the
886886
``.gitignore`` file that comes with Symfony prevents them from being committed.
887887

888+
Overriding Environment Variables Defined By The System
889+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
890+
891+
If you need to override an environment variable defined by the system, use the
892+
``overrideExistingVars`` parameter defined by the
893+
:method:`Symfony\\Component\\Dotenv\\Dotenv::loadEnv`,
894+
:method:`Symfony\\Component\\Dotenv\\Dotenv::bootEnv`, and
895+
:method:`Symfony\\Component\\Dotenv\\Dotenv::populate` methods::
896+
897+
use Symfony\Component\Dotenv\Dotenv;
898+
899+
$dotenv = new Dotenv();
900+
$dotenv->loadEnv(__DIR__.'/.env', null, 'dev', ['test'], true);
901+
902+
// ...
903+
904+
This will override environment variables defined by the system but it **won't**
905+
override environment variables defined in ``.env`` files.
906+
888907
.. _configuration-env-var-in-prod:
889908

890909
Configuring Environment Variables in Production

testing.rst

+10-15
Original file line numberDiff line numberDiff line change
@@ -599,32 +599,27 @@ to remove the ``kernel.reset`` tag from some services in your test environment::
599599
// src/Kernel.php
600600
namespace App;
601601

602-
use App\DependencyInjection\Compiler\CustomPass;
603602
use Symfony\Bundle\FrameworkBundle\Kernel\MicroKernelTrait;
603+
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
604604
use Symfony\Component\DependencyInjection\ContainerBuilder;
605605
use Symfony\Component\HttpKernel\Kernel as BaseKernel;
606606

607-
class Kernel extends BaseKernel
607+
class Kernel extends BaseKernel implements CompilerPassInterface
608608
{
609609
use MicroKernelTrait;
610610

611611
// ...
612612

613-
protected function build(ContainerBuilder $container): void
613+
protected function process(ContainerBuilder $container): void
614614
{
615615
if ('test' === $this->environment) {
616-
$container->addCompilerPass(new class() implements CompilerPassInterface {
617-
public function process(ContainerBuilder $container): void
618-
{
619-
// prevents the security token to be cleared
620-
$container->getDefinition('security.token_storage')->clearTag('kernel.reset');
621-
622-
// prevents Doctrine entities to be detached
623-
$container->getDefinition('doctrine')->clearTag('kernel.reset');
624-
625-
// ...
626-
}
627-
});
616+
// prevents the security token to be cleared
617+
$container->getDefinition('security.token_storage')->clearTag('kernel.reset');
618+
619+
// prevents Doctrine entities to be detached
620+
$container->getDefinition('doctrine')->clearTag('kernel.reset');
621+
622+
// ...
628623
}
629624
}
630625
}

0 commit comments

Comments
 (0)