-
-
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
Environment variables object #208
Conversation
This looks like a worthwhile refactoring, and makes a lot of sense from a concerns and testing perspective. You've even used protected variables for open/closed principles! I'm not a maintainer I'm afraid, but see this as valuable, particularly as it opens the door for people to extend |
+1 |
Any updates would be much appreciated. |
src/EnvironmentVariables.php
Outdated
*/ | ||
public static function create() | ||
{ | ||
return new self(false); |
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.
Since this class is not final, we need "static" here, not "self". Alternatively, it could be desirable to actually make the class final.
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.
If we go down the "final" path, it would be good to do protected ->private modifications also, but since there's no specific interface that describes EnvironmentVariables implementations, I think there's no point in making this class final.
So I'll fix this method to support late static binding as you suggested.
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.
@GrahamCampbell can you approve this review since the references to 'self' here have been changed to 'static'?
877659e
to
89cdc3f
Compare
Why is the build failing, those error messages does not make any sense? Race condition or something, I guess I should sync my branch with changes on the master. |
Note that after syncing with changes on the master branch introduced with #215, I had to slightly adapt them. To be honest, I really don't understand why those changes were needed at the first place. |
I like this overall. What are your thoughts on reading in all the ENV vars (maybe merging |
@vlucas That is definitely something that can be considered, but I think it kinda goes beyond the scope of the initial idea. This was a simple refactor for a better separation of concerns, as well as to encapsulate/abstract logic for dealing with environment variables, and use it in an object-oriented fashion, as opposed to using Therefore, I see yours and many other ideas as a follow up on this one, which after being merged opens opportunities for other improvements as well. I would rather improve things gradually, in smaller increments, rather than having one big PR with lots of (unrelated) changes in it. |
src/EnvironmentVariables.php
Outdated
*/ | ||
public static function create() | ||
{ | ||
return new self(false); |
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.
@GrahamCampbell can you approve this review since the references to 'self' here have been changed to 'static'?
@GrahamCampbell any news about this approval ? |
I'm working on rebasing this now. Having to check that every change that was made since is being copied into your new class. |
Replaced by #300. Gone with a more abstract approach, so it can be truly flexible. |
Extracted logic for getting/setting variables into a separate
EnvironmentVariables
object in order to have a clear separation of responsibilities between loading values from a file and accessing values using native PHP facilitators.EnvironmentVariables
object can be used standalone, for read-only purposes, as an alternative for usinggetenv()
function or global variables. It can also injected into a DI container so that environment variables are available when constructing services. For example: