Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Overriding defaults #37

Closed
ghost opened this issue Jun 30, 2017 · 5 comments
Closed

Overriding defaults #37

ghost opened this issue Jun 30, 2017 · 5 comments

Comments

@ghost
Copy link

ghost commented Jun 30, 2017

https://github.com/josegonzalez/php-dotenv/blob/master/src/josegonzalez/Dotenv/Loader.php#L220

I was under the impression that this package allowed merging of values from all files in the filepaths array. I see now that it doesn't.

Is there any chance this could be altered to merge and replace instead of just replace?

@josegonzalez
Copy link
Owner

Would you be fine with making that an opt-in not default?

@ghost
Copy link
Author

ghost commented Jul 1, 2017

After further reading of the code (I extended the class) I noticed that it's handled inside the loop. That got me thinking, that the api could be extended to allow custom processing of the file contents within that loop?

I'm not sure if that isn't overthinking it though.

An option to allow continuing the loop instead of breaking it would be ok though :D

@tanakahisateru
Copy link
Contributor

My workaround:

$dotenvLoader = new josegonzalez\Dotenv\Loader();
foreach ([
    __DIR__ . '/../.env',
    __DIR__ . '/../.env.default',
] as $path) {
    $dotenvLoader->setFilepath($path)->parse()->skipExisting()->toEnv()->putenv();
}

@stefanvangastel
Copy link
Contributor

Same solution here. We wanted to use DotEnv combined with Docker so sometimes have an .env file and with defaults and sometimes 'overwrite' or pre-set env var's with Docker. This resulted in errors or overwriting the Docker pre-defined env var's.

skipExisting() solved this issue so the Docker env var's remain intact.

@josegonzalez
Copy link
Owner

Closing as a workaround exists :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants