More robust environment variable fetching #530
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Goal
The
getenv
andputenv
functions in PHP are not threadsafe. For this reason, sometimes people choose not to call them when loading any environment variables in a scripted fashion, for example, from a ruby-style.env
file, using some custom software.Thus, we may need to check beyond
getenv
to find the environment variable the user has set. Fortunately, there is a mature package for doing this (and for loading.env
files... it is actually exactly the package that ships with Laravel): vlucas/phpdotenv.Design
We replace the calls to
getenv
with checking all of the possible sources environment variables could be in:$_SERVER[...]
,$_ENV[...]
,getenv(...)
,apache_getenv(...)
(where available).Changeset
There area no API changes.
Tests
An additional test has been added, demonstrating that loading the api key and server url into the env superglobal can now be detected by the client on instantiation.
Review
For the pull request reviewer(s), this changeset has been reviewed for: