From 6bb0e09ff0687675e78af8acf57e0e7ee2cab1cb Mon Sep 17 00:00:00 2001 From: Alan Knowles Date: Mon, 25 Jan 2021 13:51:19 +0800 Subject: [PATCH] Fix #6574 - default configuration for project - base class --- Config.php | 76 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 76 insertions(+) create mode 100644 Config.php diff --git a/Config.php b/Config.php new file mode 100644 index 00000000..7eb31607 --- /dev/null +++ b/Config.php @@ -0,0 +1,76 @@ +overlayDefaults($cfg); + + if (!empty($this->memory_limit)) { + $mem = ini_get('memory_limit'); + if (php_sapi_name() != 'cli' && $this->to_bytes($mem) < $this->to_bytes($this->memory_limit)) { + die("increase the memory limit settings to 2048M or more"); + } + + } + + return $cfg; + } + + function to_bytes($val) { + $val = trim($val); + $last = strtolower($val[strlen($val)-1]); + switch($last) { + // The 'G' modifier is available since PHP 5.1.0 + case 'g': + $val = substr($val, 0, -1); + $val *= 1024; + case 'm': + $val = substr($val, 0, -1); + $val *= 1024; + $val = substr($val, 0, -1); + case 'k': + $val *= 1024; + } + + return $val; + } + function overlayDefaults($cfg) + { + $this->defaults['disable'] = implode(',', $this->defaults['disable']); + foreach($this->defaults as $k=>$v) { + if (is_array($v)) { + + if (!isset($cfg[$k])) { + $cfg[$k] = $v; + continue; + } + + foreach($v as $kk=>$vv) { + if (isset($cfg[$k][$kk])) { + continue; + } + + $cfg[$k][$kk] = $vv; + } + } + + if (!isset($cfg[$k])) { + $cfg[$k] = $v; + } + } + + return $cfg; + } + + +} -- 2.39.2