From edfa76452ec3e4dc2e2e05832ec2fd183ab62788 Mon Sep 17 00:00:00 2001 From: Dmitriy Simushev Date: Thu, 24 Apr 2014 11:49:16 +0400 Subject: [PATCH] Add configs check to initialization procedure. Improve docs --- Mibew/Mibew/Plugin/Boilerplate/Plugin.php | 36 +++++++++++++++++++++-- 1 file changed, 34 insertions(+), 2 deletions(-) diff --git a/Mibew/Mibew/Plugin/Boilerplate/Plugin.php b/Mibew/Mibew/Plugin/Boilerplate/Plugin.php index 4401c17..e4722fa 100644 --- a/Mibew/Mibew/Plugin/Boilerplate/Plugin.php +++ b/Mibew/Mibew/Plugin/Boilerplate/Plugin.php @@ -12,7 +12,9 @@ * * $plugins_list[] = array( * 'name' => 'Mibew:Boilerplate', - * 'config' => array(); + * 'config' => array( + * 'very_important_value' => '$3.50', + * ); * ); * */ @@ -31,12 +33,42 @@ class Plugin extends \Mibew\Plugin\AbstractPlugin implements \Mibew\Plugin\Plugi /** * Determine if the plugin was initialized correctly or not. * - * By setting this propery to true by default we make the plugin + * By setting this propery to true by default we can make the plugin * initialized by default, so there is no need to add custom contructor * or initializer. + * + * This propery is overridden here only for example. We do not need to do + * so in each plugin. In general case it should be set to true in the plugin + * constructor when all necessary checks will be passed. + * + * Another way to control initialization state of the plugin is by means of + * {@link \Mibew\Plugin\PluginInterface::initialized()} method. */ protected $initialized = true; + /** + * Plugin's constructor. + * + * The code is situated here can initialize the plugin but cannot depend + * on other plugins. All dependent code shuold be placed in "run" method. + * + * The current implementation just checks plugin's configurations. + * + * @param array $config Associative array of configuration params from the + * main config file. + */ + public function __construct($config) + { + // Check if a fake config param is set or it does not. In the sake of + // simplicity we do not check the value. + if (!isset($config['very_important_value'])) { + // "very_important_value" param was not set. In this case we cannot + // initialize the plugin correctly, so we need to tell the system + // about it. + $this->initialized = false; + } + } + /** * The main entry point of a plugin *