Skip to content

[Runtime] Support Dotenv extra paths #60116

@natepage

Description

@natepage

Description

The Runtime component currently supports a seamless integration with the Dotenv component, and even allow to control its behaviour via runtime options within the SymfonyRuntime.

The current implementation accepts a single path, and uses it to boot the environment using Dotenv::bootEnv().
It would be great if we could extend this logic to support extra paths so applications could use multiple env vars files without having to handle the logic themselves.

The Dotenv component already support extra paths via the following functions:

  • public function load(string $path, string ...$extraPaths): void
  • public function overload(string $path, string ...$extraPaths): void

The idea here would be to add a new dotenv_extra_paths runtime option so the runtime could use it, keeping in mind the existing dotenv_overload option to call either load or overload with those extra paths.

Our current use-case is to support region specific env vars files so we could have the following:

  • envs/dev.env
  • envs/dev-ap-southeast-2.env

Note that our use-case also incorporate custom path for the env vars files, but the extra paths solution discussed here would work independently.

Happy to work on a PR if the idea is acceptable

Example

$_SERVER['APP_RUNTIME_OPTIONS'] = [
    'dotenv_path' => \sprintf('envs/%s.env', $_SERVER['APP_ENV'] ?? 'local'),
    'dotenv_extra_paths' => [
        \sprintf('envs/%s-%s.env', $_SERVER['APP_ENV'] ?? 'local', $_SERVER['AWS_REGION']),
    ],
    'dotenv_overload' => true,
];

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions