aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorJan-Hendrik Willms <tleilax+studip@gmail.com>2024-05-06 09:21:07 +0000
committerDavid Siegfried <david.siegfried@uni-vechta.de>2024-05-06 09:21:07 +0000
commite2df6525b5b19f2ead4967630c437b89558afcf3 (patch)
treeca66753c52a488fd65e4685ba506511534ae44da /lib
parent06629e19ca03c3431a64302a18a1ff2a2f011be1 (diff)
allow setting configuration by environment variables, fixes #3560
Closes #3560 Merge request studip/studip!2875
Diffstat (limited to 'lib')
-rw-r--r--lib/bootstrap-autoload.php3
-rw-r--r--lib/bootstrap.php10
-rw-r--r--lib/classes/Config.class.php16
3 files changed, 25 insertions, 4 deletions
diff --git a/lib/bootstrap-autoload.php b/lib/bootstrap-autoload.php
index 3a767c1..eb9ac12 100644
--- a/lib/bootstrap-autoload.php
+++ b/lib/bootstrap-autoload.php
@@ -1,7 +1,4 @@
<?php
-// Include composer's autoload
-require __DIR__ . '/../composer/autoload.php';
-
// Setup autoloading
require 'lib/classes/StudipAutoloader.php';
StudipAutoloader::register();
diff --git a/lib/bootstrap.php b/lib/bootstrap.php
index 06ddca5..364f9d9 100644
--- a/lib/bootstrap.php
+++ b/lib/bootstrap.php
@@ -9,8 +9,16 @@
* the License, or (at your option) any later version.
*/
+// Include composer's autoload
+require __DIR__ . '/../composer/autoload.php';
+
+// Load enviroment
+$dot_env_path = __DIR__ . '/..';
+$dotenv = \Dotenv\Dotenv::createImmutable($dot_env_path);
+$dotenv->safeLoad();
+
// Default environment, do not change. Change in config/config_local.inc.php.
-const DEFAULT_ENV = 'production';
+define('DEFAULT_ENV', $_ENV['STUDIP_ENV'] ?? 'production');
//software version - please leave it as it is!
$SOFTWARE_VERSION = '6.0.alpha';
diff --git a/lib/classes/Config.class.php b/lib/classes/Config.class.php
index 2f6b728..642665d 100644
--- a/lib/classes/Config.class.php
+++ b/lib/classes/Config.class.php
@@ -127,9 +127,14 @@ class Config implements ArrayAccess, Countable, IteratorAggregate
*/
public function getValue($field)
{
+ if ($this->fromEnv($field)) {
+ return $_ENV["STUDIP_CONFIG_{$field}"];
+ }
+
if (array_key_exists($field, $this->data)) {
return $this->data[$field];
}
+
if (isset($GLOBALS[$field]) && !isset($_REQUEST[$field])) {
return $GLOBALS[$field];
}
@@ -450,4 +455,15 @@ class Config implements ArrayAccess, Countable, IteratorAggregate
return (string) $value;
}
+
+ /**
+ * Returns whether the value was set from the environment.
+ *
+ * @param string $field
+ * @return bool
+ */
+ public function fromEnv(string $field): bool
+ {
+ return isset($_ENV["STUDIP_CONFIG_{$field}"]);
+ }
}