From 1e59f1b815e3cc06ba193ad3f695d5ad379646ce Mon Sep 17 00:00:00 2001 From: Benjamin Renard Date: Wed, 1 Mar 2023 14:17:15 +0100 Subject: [PATCH] Config: add ini_set() helper method --- src/App.php | 6 +++--- src/Config.php | 11 +++++++++++ src/Session.php | 4 ++-- 3 files changed, 16 insertions(+), 5 deletions(-) diff --git a/src/App.php b/src/App.php index 0116083..c46cceb 100644 --- a/src/App.php +++ b/src/App.php @@ -52,12 +52,12 @@ class App { // Define upload_tmp_dir if (self::isset('upload_tmp_directory')) - ini_set('upload_tmp_dir', self::get('upload_tmp_directory', null, 'string')); + Config :: ini_set('upload_tmp_dir', self::get('upload_tmp_directory', null, 'string')); if (self::isset('upload_max_filesize')) { - ini_set('upload_max_filesize', self::get('upload_max_filesize', null, 'string')); + Config :: ini_set('upload_max_filesize', self::get('upload_max_filesize', null, 'string')); // post_max_size must be larger than upload_max_filesize // See: https://www.php.net/manual/en/ini.core.php#ini.post-max-size - ini_set('post_max_size', strval(self::get('upload_max_filesize', null, 'int') * 1.1)); + Config :: ini_set('post_max_size', strval(self::get('upload_max_filesize', null, 'int') * 1.1)); } if (self :: get('log.enabled', true, 'bool')) diff --git a/src/Config.php b/src/Config.php index 94cc442..93d02d5 100644 --- a/src/Config.php +++ b/src/Config.php @@ -229,6 +229,17 @@ Class Config { return true; } + /** + * Helper to set PHP INI option and log error + * @param string $option + * @param string|int|float|bool|null $value + * @return void + */ + public static function ini_set($option, $value) { + if (ini_set($option, $value) === false) + Log::warning('Fail to set INI options "%s" to "%s"', $option, $value); + } + } # vim: tabstop=4 shiftwidth=4 softtabstop=4 expandtab diff --git a/src/Session.php b/src/Session.php index d0e1d3b..22c0df7 100644 --- a/src/Session.php +++ b/src/Session.php @@ -35,8 +35,8 @@ class Session { if (is_int($max_duration)) self :: $max_duration = $max_duration; - ini_set('session.gc_maxlifetime', strval(self :: $max_duration)); - ini_set('session.cookie_lifetime', strval(self :: $max_duration)); + Config :: ini_set('session.gc_maxlifetime', strval(self :: $max_duration)); + Config :: ini_set('session.cookie_lifetime', strval(self :: $max_duration)); // Start session session_start();