@@ -993,20 +993,19 @@ environment variables, with their values, referenced in Symfony's container conf
993993 # run this command to show all the details for a specific env var:
994994 $ php bin/console debug:container --env-var=FOO
995995
996- Create Your Own Logic To Load Env Vars
997- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
996+ Creating Your Own Logic To Load Env Vars
997+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
998998
999- You can implement your own logic to load environment variables in your
1000- application if the default behavior doesn't exactly fit your needs. This
1001- can be done by implementing the
1002- :class: `Symfony\\ Component\\ DependencyInjection\\ EnvVarLoaderInterface `.
999+ You can implement your own logic to load environment variables if the default
1000+ Symfony behavior doesn't fit your needs. To do so, create a service whose class
1001+ implements :class: `Symfony\\ Component\\ DependencyInjection\\ EnvVarLoaderInterface `.
10031002
10041003.. note ::
10051004
1006- When using autoconfiguration, implementing the interface is the only
1007- required step. Otherwise, you have to manually add the
1008- `` container.env_var_loader `` tag to your class. You can learn more about
1009- it in :doc: ` the dedicated page < /service_container/tags >` .
1005+ If you're using the :ref: ` default services.yaml configuration < service-container-services-load-example >`,
1006+ the autoconfiguration feature will enable and tag thise service automatically.
1007+ Otherwise, you need to register and :doc: ` tag your service < /service_container/tags >`
1008+ with the `` container.env_var_loader `` tag .
10101009
10111010Let's say you have a JSON file named ``env.json `` containing your environment
10121011variables:
@@ -1020,22 +1019,22 @@ variables:
10201019 }
10211020 }
10221021
1023- We can create a new class named ``JsonEnvVarLoader `` to populate our environment
1024- variables from the file::
1022+ You can define a class like the following ``JsonEnvVarLoader `` to populate the
1023+ environment variables from the file::
10251024
10261025 namespace App\DependencyInjection;
10271026
10281027 use Symfony\Component\DependencyInjection\EnvVarLoaderInterface;
10291028
1030- class JsonEnvVarLoader implements EnvVarLoaderInterface
1029+ final class JsonEnvVarLoader implements EnvVarLoaderInterface
10311030 {
10321031 private const ENV_VARS_FILE = 'env.json';
10331032
10341033 public function loadEnvVars(): array
10351034 {
10361035 $fileName = __DIR__.\DIRECTORY_SEPARATOR.self::ENV_VARS_FILE;
10371036 if (!is_file($fileName)) {
1038- // throw an error or just ignore this loader, depending on your needs
1037+ // throw an exception or just ignore this loader, depending on your needs
10391038 }
10401039
10411040 $content = json_decode(file_get_contents($fileName), true);
@@ -1044,9 +1043,9 @@ variables from the file::
10441043 }
10451044 }
10461045
1047- That's it! Now the application will look at a ``env.json `` file in the
1048- current directory to populate environment variables, additionally to the
1049- already existing ``.env `` files.
1046+ That's it! Now the application will look for a ``env.json `` file in the
1047+ current directory to populate environment variables (in addition to the
1048+ already existing ``.env `` files) .
10501049
10511050.. tip ::
10521051
0 commit comments