You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
feature #35308 [Dotenv] Add Dotenv::bootEnv() to check for .env.local.php before calling Dotenv::loadEnv() (nicolas-grekas)
This PR was merged into the 5.1-dev branch.
Discussion
----------
[Dotenv] Add Dotenv::bootEnv() to check for .env.local.php before calling Dotenv::loadEnv()
| Q | A
| ------------- | ---
| Branch? | master
| Bug fix? | no
| New feature? | yes
| Deprecations? | yes
| Tickets | -
| License | MIT
| Doc PR | -
The goal of this PR is to eventually get rid of the `config/bootstrap.php` file in Symfony 5.1 apps.
I think we've done enough iterations on that piece of bootstrapping logic to put it inside the `Dotenv` component.
This fully replaces https://github.com/symfony/recipes/blob/master/symfony/framework-bundle/4.2/config/bootstrap.php
It doesn't conflict with current apps so they'll be fine keeping the `config/bootstrap.php` file until they're upgraded.
The new bootstrapping logic will require adding this line in `bin/console` and `public/index.php`:
```php
(new Dotenv())->bootEnv(dirname(__DIR__).'/.env');
```
Recipes updated at symfony/recipes#724
Commits
-------
98c7d30 [Dotenv] Add Dotenv::bootEnv() to check for .env.local.php before calling Dotenv::loadEnv()
if (\in_array($envKey = (string) $envKey, ['1', ''], true)) {
49
+
@trigger_error(sprintf('Passing a boolean to the constructor of "%s" is deprecated since Symfony 5.1, use "Dotenv::usePutenv()".', __CLASS__), E_USER_DEPRECATED);
50
+
$this->usePutenv = (bool) $envKey;
51
+
$envKey = 'APP_ENV';
52
+
}
53
+
54
+
$this->envKey = $envKey;
55
+
$this->debugKey = $debugKey;
56
+
}
57
+
58
+
/**
59
+
* @return $this
60
+
*/
61
+
publicfunctionsetProdEnvs(array$prodEnvs): self
62
+
{
63
+
$this->prodEnvs = $prodEnvs;
64
+
65
+
return$this;
66
+
}
67
+
68
+
/**
69
+
* @param bool $usePutenv If `putenv()` should be used to define environment variables or not.
70
+
* Beware that `putenv()` is not thread safe, that's why this setting defaults to false
71
+
*
72
+
* @return $this
73
+
*/
74
+
publicfunctionusePutenv($usePutenv = true): self
45
75
{
46
76
$this->usePutenv = $usePutenv;
77
+
78
+
return$this;
47
79
}
48
80
49
81
/**
@@ -66,29 +98,31 @@ public function load(string $path, string ...$extraPaths): void
66
98
* .env.local is always ignored in test env because tests should produce the same results for everyone.
67
99
* .env.dist is loaded when it exists and .env is not found.
68
100
*
69
-
* @param string $path A file to load
70
-
* @param string $varName The name of the env vars that defines the app env
71
-
* @param string $defaultEnv The app env to use when none is defined
72
-
* @param array $testEnvs A list of app envs for which .env.local should be ignored
101
+
* @param string $path A file to load
102
+
* @param string $envKey|null The name of the env vars that defines the app env
103
+
* @param string $defaultEnv The app env to use when none is defined
104
+
* @param array $testEnvs A list of app envs for which .env.local should be ignored
73
105
*
74
106
* @throws FormatException when a file has a syntax error
75
107
* @throws PathException when a file does not exist or is not readable
0 commit comments