Added support for setting GRAV_ENVIRONMENT by using environment variable or a constant

This commit is contained in:
Matias Griese
2020-12-08 13:41:05 +02:00
parent fc55a8e49b
commit ac85946e0f
2 changed files with 8 additions and 2 deletions

View File

@@ -4,9 +4,10 @@
1. [](#new)
* Auto-Escape enabled by default. Manually enable **Twig Compatibility** and disable **Auto-Escape** to use the old setting.
* Updated unit tests to use codeception 4.1
* Added support for setting `GRAV_ENVIRONMENT` by using environment variable or a constant
* Added support for setting `GRAV_SETUP_PATH` by using environment variable (constant already worked)
1. [](#improved)
* Improved `bin/grav install` command
* Added support for setting `GRAV_SETUP_PATH` by using environment variable
1. [](#bugfix)
* Fixed potential error when upgrading Grav
* Fixed broken list in `bin/gpm index` [#3092](https://github.com/getgrav/grav/issues/3092)

View File

@@ -163,6 +163,10 @@ class Setup extends Data
*/
public function __construct($container)
{
// If environment is not set, look for the environment variable and then the constant.
static::$environment = static::$environment ??
(getenv('GRAV_ENVIRONMENT') ?: (defined('GRAV_ENVIRONMENT') ? GRAV_ENVIRONMENT : null));
// If no environment is set, make sure we get one (CLI or hostname).
if (!static::$environment) {
if (defined('GRAV_CLI')) {
@@ -182,7 +186,8 @@ class Setup extends Data
// Pre-load setup.php which contains our initial configuration.
// Configuration may contain dynamic parts, which is why we need to always load it.
// If "GRAV_SETUP_PATH" has been defined, use it, otherwise use defaults.
$file = getenv('GRAV_SETUP_PATH') ?: (defined('GRAV_SETUP_PATH') ? GRAV_SETUP_PATH : 'setup.php');
$file = getenv('GRAV_SETUP_PATH')
?: (defined('GRAV_SETUP_PATH') ? GRAV_SETUP_PATH : 'setup.php');
if (!str_starts_with($file, '/')) {
$file = GRAV_ROOT . '/' . $file;
}