WIP: EGPCS vs GPCS for environment
Summary:
The Environment class provides a standard way to query both
$_ENV and $_SERVER. Advantage against getenv() is it doesn't
return false if the value doesn't exist, but throw an exception.
The getOr method allows to provide a default value,
so $_ENV['foo'] ?? $_SERVER['foo'] ?? default can be
expressed a more compact way.
This is intended to allow applications to fetch environment
and be sure to get the environment variable as an answer.
$_ENV and $_SERVER for environment
PHP allows to control the order of superglobals array,
like $_SERVER and $_ENV, but also to restrain to set one.
When software is configured through environment variables,
this situation creates a tricky situation:
- The default PHP value is EGPCS, so we've $_ENV
- The suggested production config is GPCS, without $_ENV
By default, Fedora and Ubuntu PHP packages maintainers
set the variables_order configuration variable to GPCS,
not filling the $_ENV array.
Meanwhile, any variable defined through php-fpm environment
will be filled in $_SERVER. $_SERVER would also receive the
php-fpm process environment if clean_env is set to false.
As far as a generic application is concerned, this situation
means any environment variable could be set in $_ENV, $_SERVER
or both. In PHP core, the getenv() method read both arrays.
References
- https://www.php.net/manual/en/ini.core.php
- https://www.php.net/manual/en/install.fpm.configuration.php
Test Plan: Units tests covering all methods.
Reviewers: dereckson
Reviewed By: dereckson
Differential Revision: https://devcentral.nasqueron.org/D2497