-
Notifications
You must be signed in to change notification settings - Fork 61
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
fix loading environment variable with symfony 5.1 #127
base: master
Are you sure you want to change the base?
Changes from 4 commits
4744163
7cf5e6c
a96f521
068cb02
3fc6f21
4766c95
cdb00f8
22728b4
91cb6b8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,6 +22,8 @@ | |
use Symfony\Component\DependencyInjection\Definition; | ||
use Symfony\Component\DependencyInjection\Parameter; | ||
use Symfony\Component\DependencyInjection\Reference; | ||
use Symfony\Component\Dotenv\Dotenv; | ||
use Symfony\Component\Dotenv\Exception\PathException; | ||
|
||
final class SymfonyExtension implements Extension | ||
{ | ||
|
@@ -176,12 +178,25 @@ private function loadMinkParameters(ContainerBuilder $container): void | |
private function loadBootstrap(?string $bootstrap): void | ||
{ | ||
if ($bootstrap === null) { | ||
$this->loadEnv(); | ||
|
||
return; | ||
} | ||
|
||
require_once $bootstrap; | ||
} | ||
|
||
private function loadEnv() | ||
{ | ||
$env = getenv('APP_ENV'); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Here i think is needed to pick the env like this $config['environment'] ?? $_SERVER['APP_ENV'] ?? $_ENV['APP_ENV'] ?? 'test'; // Is how is done in 117 line number. |
||
try { | ||
(new Dotenv())->bootEnv(basename(dirname(__DIR__)).'/../.env', $env); | ||
} | ||
catch (PathException $exception) { | ||
return null; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What is the point here to return null? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think it was to do something like this if another method of loading variables came up :
Should we throw an exception if the variables could not be loaded ? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Here just to do return, instead of return null. |
||
} | ||
} | ||
|
||
private function fallbackToTestEnvironment(): void | ||
{ | ||
// If there's no defined server / environment variable with an environment, default to test | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe instead of loading it in loadBootstrap method, to load it separately just before calling loadBoostrap, to make a check if bootstrap is not specified to try to load environment variables.
Just to have a separated context. What do you think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes I think you are right, since the bootstrap.php file has disappeared
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What you mean has disappeared, i see that in configure method, there is still bootstrap configuration, and also there is configuration of environment, and in loadEnv method, where APP_ENV is loaded.
What i think is to let loadBoostrap method like it was, and if bootstrap configuration is null, then to have a fallback to load from .env file, if no, to do nothing like before.
Example:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The file was config/bootstrap.php
yes of course nothing should be changed to keep a retro compatibility
I agree with you