From ac85946e0fb47ab82ac382c7decf44fb569ea441 Mon Sep 17 00:00:00 2001 From: Matias Griese Date: Tue, 8 Dec 2020 13:41:05 +0200 Subject: [PATCH] Added support for setting `GRAV_ENVIRONMENT` by using environment variable or a constant --- CHANGELOG.md | 3 ++- system/src/Grav/Common/Config/Setup.php | 7 ++++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 848dd8bad..3a47e6e90 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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) diff --git a/system/src/Grav/Common/Config/Setup.php b/system/src/Grav/Common/Config/Setup.php index e8ebccbe2..fc82505f2 100644 --- a/system/src/Grav/Common/Config/Setup.php +++ b/system/src/Grav/Common/Config/Setup.php @@ -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; }