aboutsummaryrefslogtreecommitdiff
path: root/app/Models/UserConfiguration.php
diff options
context:
space:
mode:
Diffstat (limited to 'app/Models/UserConfiguration.php')
-rw-r--r--app/Models/UserConfiguration.php28
1 files changed, 28 insertions, 0 deletions
diff --git a/app/Models/UserConfiguration.php b/app/Models/UserConfiguration.php
index eaa08d92d..d98d85fe3 100644
--- a/app/Models/UserConfiguration.php
+++ b/app/Models/UserConfiguration.php
@@ -108,4 +108,32 @@ final class FreshRSS_UserConfiguration extends Minz_Configuration {
}
return $default_user_conf;
}
+
+ /**
+ * Register and return the configuration for a given user.
+ *
+ * Note this function has been created to generate temporary configuration
+ * objects. If you need a long-time configuration, please don't use this function.
+ *
+ * @param string $username the name of the user of which we want the configuration.
+ * @return FreshRSS_UserConfiguration|null object, or null if the configuration cannot be loaded.
+ * @throws Minz_ConfigurationNamespaceException
+ */
+ public static function getForUser(string $username): ?FreshRSS_UserConfiguration {
+ if (!FreshRSS_user_Controller::checkUsername($username)) {
+ return null;
+ }
+ $namespace = 'user_' . $username;
+ try {
+ FreshRSS_UserConfiguration::register($namespace,
+ USERS_PATH . '/' . $username . '/config.php',
+ FRESHRSS_PATH . '/config-user.default.php');
+ } catch (Minz_FileNotExistException $e) {
+ Minz_Log::warning($e->getMessage(), ADMIN_LOG);
+ return null;
+ }
+
+ $user_conf = FreshRSS_UserConfiguration::get($namespace);
+ return $user_conf;
+ }
}