diff options
| author | 2023-03-26 14:17:22 +0200 | |
|---|---|---|
| committer | 2023-03-26 14:17:22 +0200 | |
| commit | 5f898dcc5ee244e4adbd6aa83b607c844d432fb6 (patch) | |
| tree | 3511bcb3f78d053f4488e70000ab55fee7bb688a /app/Models/Context.php | |
| parent | df24fa2207f56909084c613495b6f235b351c640 (diff) | |
Modernize Constants and use new constant for string 'currentUser' (#5089)
* Modernize Constants and use new constant 'currentUser'
* Add FreshRSS_Context::currentUser() function and use
* Add FreshRSS_Context::currentUser() function and use
* Add FreshRSS_Context::currentUser() function and use
* Add FreshRSS_Context::currentUser() function and use
* Add FreshRSS_Context::currentUser() function and use
* Update app/Controllers/userController.php
* Update app/Controllers/userController.php
* Update app/Controllers/userController.php
* Update app/Models/Auth.php
* Update p/api/greader.php
* Update p/api/greader.php
* Update p/api/greader.php
* Update app/Models/Context.php
* Update app/Models/LogDAO.php
* Update lib/Minz/Log.php
* Update p/api/greader.php
* Update app/layout/header.phtml
* Update app/views/helpers/export/articles.phtml
* Update cli/do-install.php
* Remarque's from Alkarex
* Remarque's from Alkarex
* Refactor using new Minz_User class
* Consistent naming of public constants
---------
Co-authored-by: Luc <sanchezluc+freshrss@gmail.com>
Co-authored-by: Alexandre Alapetite <alexandre@alapetite.fr>
Diffstat (limited to 'app/Models/Context.php')
| -rw-r--r-- | app/Models/Context.php | 21 |
1 files changed, 12 insertions, 9 deletions
diff --git a/app/Models/Context.php b/app/Models/Context.php index 734458d7f..35bd192d7 100644 --- a/app/Models/Context.php +++ b/app/Models/Context.php @@ -4,7 +4,7 @@ * The context object handles the current configuration file and different * useful functions associated to the current view state. */ -class FreshRSS_Context { +final class FreshRSS_Context { /** * @var FreshRSS_UserConfiguration|null @@ -55,7 +55,7 @@ class FreshRSS_Context { /** * Initialize the context for the global system. */ - public static function initSystem($reload = false) { + public static function initSystem(bool $reload = false): FreshRSS_SystemConfiguration { if ($reload || FreshRSS_Context::$system_conf == null) { //TODO: Keep in session what we need instead of always reloading from disk FreshRSS_Context::$system_conf = FreshRSS_SystemConfiguration::init(DATA_PATH . '/config.php', FRESHRSS_PATH . '/config.default.php'); @@ -68,8 +68,9 @@ class FreshRSS_Context { /** * Initialize the context for the current user. + * @return FreshRSS_UserConfiguration|false */ - public static function initUser($username = '', $userMustExist = true) { + public static function initUser(string $username = '', bool $userMustExist = true) { FreshRSS_Context::$user_conf = null; if (!isset($_SESSION)) { Minz_Session::init('FreshRSS'); @@ -77,9 +78,9 @@ class FreshRSS_Context { Minz_Session::lock(); if ($username == '') { - $username = Minz_Session::param('currentUser', ''); + $username = Minz_User::name() ?? ''; } - if (($username === '_' || FreshRSS_user_Controller::checkUsername($username)) && + if (($username === Minz_User::INTERNAL_USER || FreshRSS_user_Controller::checkUsername($username)) && (!$userMustExist || FreshRSS_user_Controller::userExists($username))) { try { //TODO: Keep in session what we need instead of always reloading from disk @@ -88,7 +89,7 @@ class FreshRSS_Context { FRESHRSS_PATH . '/config-user.default.php', FreshRSS_Context::$system_conf->configurationSetter()); - Minz_Session::_param('currentUser', $username); + Minz_User::change($username); } catch (Exception $ex) { Minz_Log::warning($ex->getMessage(), USERS_PATH . '/_/' . LOG_FILENAME); } @@ -96,7 +97,7 @@ class FreshRSS_Context { if (FreshRSS_Context::$user_conf == null) { Minz_Session::_params([ 'loginOk' => false, - 'currentUser' => false, + Minz_User::CURRENT_USER => false, ]); } Minz_Session::unlock(); @@ -212,6 +213,7 @@ class FreshRSS_Context { * * If $array is true, the first item of the returned value is 'f' or 'c' and * the second is the id. + * @return string|array{string,bool|int} */ public static function currentGet($array = false) { if (self::$current_get['all']) { @@ -239,6 +241,7 @@ class FreshRSS_Context { } elseif (self::$current_get['tags']) { return 'T'; } + return ''; } /** @@ -272,8 +275,8 @@ class FreshRSS_Context { /** * @return bool true if $get parameter correspond to the $current_get attribute. */ - public static function isCurrentGet($get): bool { - $type = $get[0]; + public static function isCurrentGet(string $get): bool { + $type = substr($get, 0, 1); $id = substr($get, 2); switch($type) { |
