8000 [Dotenv] Check required dotenvs by pizzaminded · Pull Request #32729 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[Dotenv] Check required dotenvs #32729

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

Closed
wants to merge 8 commits into from
Closed

[Dotenv] Check required dotenvs #32729

wants to merge 8 commits into from

Conversation

pizzaminded
Copy link
Contributor
@pizzaminded pizzaminded commented Jul 24, 2019
Q A
Branch? 4.4
Bug fix? no
New feature? yes
BC breaks? no
Deprecations? no
Tests pass? yes
Fixed tickets #...
License MIT
Doc PR #12030

TODO:

  • update documentation
  • fix tests

Added new method, which checks there are all environment variables defined in project.
This one may be used e.g. to tell other developer to provide all things needed to run app without any missing-envs-caused malfunctions.

It is checking only _ENV superglobal as there may be some vars defined in third-party software (like SetEnv in Apache)

@nicolas-grekas nicolas-grekas added this to the next milestone Jul 25, 2019
@pizzaminded pizzaminded changed the title [WIP] [Dotenv] Check required dotenvs [Dotenv] Check required dotenvs Jul 25, 2019
@xabbuh
Copy link
Member
xabbuh commented Jul 25, 2019

To me it doesn't look like this change really belongs to the Dotenv component. The component is meant to read environment variables from .env files. The code added here is about verifying the presence of some environment variables which is not tied to reading .env files. Those environment variables could be populated by any other mechanism as well without the Dotenv component being involved.

@pizzaminded
Copy link
Contributor Author

@xabbuh similar features are used e.g in Ruby's gem (https://github.com/bkeepers/dotenv#required-keys) and some PHP libs:

IMHO Dotenv could be one of the best places for this feature as it is used at the beginning of script, where it is possible to prevent further execution of scripts with invalid config.

@nicolas-grekas
Copy link
Member

Where do you get the list of required vars from in your use case?
Can't we derivate it from the .env file?
That'd fit well with the way 8000 we see it now: this file should list all the env vars that are needed by the app, even with an empty value.

@pizzaminded
Copy link
Contributor Author
pizzaminded commented Jul 25, 2019

@nicolas-grekas I got some environment variables defined in Apache's vhosts config to verify that request came from internal of external networks. For development purposes adding it to .env would be a good idea, but in testing (i mean UAT, not unit tests etc.) or production this might be tricky.

This also can act as an "reminder" for new developers that they need to define missing variables in .env file.

EDIT: setting environment variables in vhost as above is used e.g. in eZ Publish: https://doc.ez.no/display/EZP/Siteaccess+Matching#SiteaccessMatching-Matchingbyenvironmentvariable

@nicolas-grekas
Copy link
Member

This also can act as an "reminder" for new developers that they need to define missing variables in .env file.

In any case, the list of required vars needs to be put somewhere. The most logical place is the .env file to me.

@nicolas-grekas
Copy link
Member

I'm closing to snapshot the state of the PR and related discussion.
Feel free to submit another PR with the proposed alternative.

@nicolas-grekas nicolas-grekas modified the milestones: next, 4.4 Oct 27, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants
0