Ver Fonte

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.
Alexis Degrugillier há 5 anos atrás
pai
commit
0577bc772b
1 ficheiros alterados com 16 adições e 0 exclusões
  1. 16 0
      lib/Minz/Extension.php

+ 16 - 0
lib/Minz/Extension.php

@@ -12,6 +12,7 @@ abstract class Minz_Extension {
 	private $version;
 	private $version;
 	private $type;
 	private $type;
 	private $config_key = 'extensions';
 	private $config_key = 'extensions';
+	private $user_configuration;
 
 
 	public static $authorized_types = array(
 	public static $authorized_types = array(
 		'system',
 		'system',
@@ -236,6 +237,21 @@ abstract class Minz_Extension {
 		return FreshRSS_Context::$user_conf->{$this->config_key}[$this->getName()];
 		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) {
 	public function setUserConfiguration(array $configuration) {
 		if (!$this->isUserConfigurationEnabled()) {
 		if (!$this->isUserConfigurationEnabled()) {
 			return;
 			return;