diff options
| author | 2021-02-05 12:29:37 -0500 | |
|---|---|---|
| committer | 2021-02-05 18:29:37 +0100 | |
| commit | 0577bc772bb28b3bda0f33b184c79aa226e606ca (patch) | |
| tree | 5daf4a273e167f123d8e600d7c13aef484a7add7 /lib | |
| parent | d7cfea155f2515a2e5681c5fa2470214cbe1d662 (diff) | |
Add a method to retrieve a configuration value (#3422)
This will simplify extension code by removing a lot of logic from
the extension itself when it's not needed. I've tested it on one
of my extension with all the other recent extension modifications
and I could remove half of the code needed before.
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/Minz/Extension.php | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/lib/Minz/Extension.php b/lib/Minz/Extension.php index 7f377b3d9..062463897 100644 --- a/lib/Minz/Extension.php +++ b/lib/Minz/Extension.php @@ -12,6 +12,7 @@ abstract class Minz_Extension { private $version; private $type; private $config_key = 'extensions'; + private $user_configuration; public static $authorized_types = array( 'system', @@ -236,6 +237,21 @@ abstract class Minz_Extension { return FreshRSS_Context::$user_conf->{$this->config_key}[$this->getName()]; } + /** + * @param mixed $default + * @return mixed + */ + public function getUserConfigurationValue(string $key, $default = null) { + if (!is_array($this->user_configuration)) { + $this->user_configuration = $this->getUserConfiguration(); + } + + if (array_key_exists($key, $this->user_configuration)) { + return $this->user_configuration[$key]; + } + return $default; + } + public function setUserConfiguration(array $configuration) { if (!$this->isUserConfigurationEnabled()) { return; |
