-
-
Notifications
You must be signed in to change notification settings - Fork 633
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
[2.1] Move loader creation to the constructor #102
[2.1] Move loader creation to the constructor #102
Conversation
Could you include a test case that failed before this change please? |
This allow the use of "required" to validate variables without loading without explicitely loading a .env file. Add test case for required validation without loading
420f804
to
631e266
Compare
@GrahamCampbell Done. |
Move loader creation to the constructor
🍻 |
@@ -35,8 +36,6 @@ public function __construct($path, $file = '.env') | |||
*/ | |||
public function load() | |||
{ | |||
$this->loader = new Loader($this->filePath, $immutable = true); |
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.
I don't think this can be removed, but there is not a test case to cover the scenario for why.
Basically, if you call overload
, and then load
on a different file, the same loader will be retained from overload
, which will leave the immutable
variable set to false
(from the overload
method), and the expected behavior will diverge from what this method is supposed to do. A test case needs to be added to ensure this does not happen, and this line probably needs to be added back in. @GrahamCampbell
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.
So, if i'm getting this right, You would have the line in the constructor and in the load
method, and the load method would overwrite the "default" loader with a new one?
This allow the use of
$dotenv->required
to validate environment variables without loading without explicitly loading a .env file. Unless i'm horribly mistaken, this should fix #101 and allow validation environment variables even if we don't use a .env file.