From 1709b920d17ba685e200405dcc8b9cb221a35e61 Mon Sep 17 00:00:00 2001 From: Daniel Rudolf Date: Wed, 2 Mar 2016 21:46:35 +0100 Subject: [PATCH] Add AbstractPicoPlugin::getPluginConfig() method --- lib/AbstractPicoPlugin.php | 29 ++++++++++++++++++++++++++--- 1 file changed, 26 insertions(+), 3 deletions(-) diff --git a/lib/AbstractPicoPlugin.php b/lib/AbstractPicoPlugin.php index 4ee337e..68587f0 100644 --- a/lib/AbstractPicoPlugin.php +++ b/lib/AbstractPicoPlugin.php @@ -74,9 +74,9 @@ abstract class AbstractPicoPlugin implements PicoPluginInterface if ($pluginEnabled !== null) { $this->setEnabled($pluginEnabled); } else { - $pluginConfig = $this->getConfig(get_called_class()); - if (is_array($pluginConfig) && isset($pluginConfig['enabled'])) { - $this->setEnabled($pluginConfig['enabled']); + $pluginEnabled = $this->getPluginConfig('enabled'); + if ($pluginEnabled !== null) { + $this->setEnabled($pluginEnabled); } elseif ($this->enabled) { // make sure dependencies are already fulfilled, // otherwise the plugin needs to be enabled manually @@ -135,6 +135,29 @@ abstract class AbstractPicoPlugin implements PicoPluginInterface return $this->pico; } + /** + * Returns either the value of the specified plugin config variable or + * the config array + * + * @param string $configName optional name of a config variable + * @return mixed returns either the value of the named plugin + * config variable, null if the config variable doesn't exist or the + * plugin's config array if no config name was supplied + */ + protected function getPluginConfig($configName = null) + { + $pluginConfig = $this->getConfig(get_called_class()); + if ($pluginConfig) { + if ($configName === null) { + return $pluginConfig; + } elseif (isset($pluginConfig[$configName])) { + return $pluginConfig[$configName]; + } + } + + return null; + } + /** * Passes all not satisfiable method calls to Pico *