Load environment variables from $_ENV
, $_SERVER
and getenv()
if in thread-safe environment
#205
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.
This changeset adds support for loading environment variables from the DI container configuration from
$_ENV
,$_SERVER
andgetenv()
if in a thread-safe environment:The previous version only supported explicit configuration of container variables and automatically loading environment variables from
$_SERVER
only. The updated version will now also load environment variables from$_ENV
andgetenv()
if executed in a thread-safe environment.$_ENV
superglobal will only contain the environment variables whenvariables_order
includesE
(the default in PHP, but disabled by default in Debian/Ubuntu-based distributions). Accordingly, this is commonly an empty array.$_SERVER
superglobal will only contain the environment variables in CLI and CGI/FastCGI environment and whenvariables_order
includesS
(the default). Most notably, this will not contain any environment variables for PHP's development web server.getenv()
function (andputenv()
) can be used to access the process environment. This works across all environments, but may exhibit unsafe behavior and leak environment variables from other threads if executed in a multithreaded environment (such as when running as a multithreaded Apache module). Accordingly, we will only fall back to this method when PHP is not compiled with thread safety (NTS, which is the default and means it can not safely be used in a multithreaded environment anyway) or when used in an environment that does not leverage multithreading to handle parallel requests (ZTS used in CLI or CGI/FastCGI). Most notably, this will now be used as a fall back for PHP's development web server.As a result, automatically loading environment variables from the
Container
will now "just work" across all environments. Considering the above logic, the resulting code appears relatively straightforward. Together with this analysis and multiple tries, you're looking at several days worth of work, enjoy!Builds on top of #184 and #91.
Refs #200, #201 and #204.
Also refs #101 as this is the next big step in adding better configuration support and support for environment variables and
.env
(dotenv) files in the future.