-
-
Notifications
You must be signed in to change notification settings - Fork 642
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
Allow to set change/disable destination array #113
Comments
Done in #300. See https://github.com/vlucas/phpdotenv#loader-customization for an example. |
Some examples. Example 1The following example assumes This example will load the <?php
use Dotenv\Dotenv;
$dotenv = Dotenv::create($path);
$variables = $dotenv->load(); Example 2The following example assumes Similar to the first example, only this time we avoid calling any non-thread-safe functions. <?php
use Dotenv\Environment\Adapter\EnvConstAdapter;
use Dotenv\Environment\Adapter\ServerConstAdapter;
use Dotenv\Environment\DotenvFactory;
use Dotenv\Dotenv;
$factory = new DotenvFactory([new EnvConstAdapter(), new ServerConstAdapter()]);
Dotenv::create($path, null, $factory)->load(); EXAMPLE 3The following example assumes This example will load the <?php
use Dotenv\Environment\Adapter\ArrayAdapter;
use Dotenv\Environment\DotenvFactory;
use Dotenv\Dotenv;
$dotenv = Dotenv::create($path, null, new DotenvFactory([new ArrayAdapter()]));
$variables = $dotenv->load(); EXAMPLE 4The following example assumes Once again, this example will not mutate your actual environment, allowing you to inspect the contents of an env file in isolation. <?php
use Dotenv\Environment\Adapter\ArrayAdapter;
use Dotenv\Environment\DotenvFactory;
use Dotenv\Loader;
$loader = new Loader([], new DotenvFactory([new ArrayAdapter()]));
$variables = $loader->loadDirect($content)); |
I came across a project, which logs it's $_SERVER and $_ENV values in log file on errors, and that kinda sucks. I ended up with a small snippet, that clears $_ENV and $_SERVER from loaded values, but, getenv() function still works properly.
What do you thing about this option? I know this is a specific situation, but sometimes, a dev can by accident enable error reporting on production, which sometimes (Yii2, for example), dumps the whole ENV and SERVER array to the user. If that happens, all API keys, passwords, etc are compromised.
My current snippet:
The text was updated successfully, but these errors were encountered: