public static function init($options, $helpersOptions = array()) { // plugins are registered in plugin broker self::$_pluginBroker = new X_VlcShares_Plugins_Broker(); if (!$options instanceof Zend_Config) { if (!is_array($options)) { $options = array(); } $options = new Zend_Config($options); } if (!$helpersOptions instanceof Zend_Config) { if (!is_array($helpersOptions)) { $helpersOptions = array(); } $helpersOptions = new Zend_Config($helpersOptions); } $plugins = Application_Model_PluginsMapper::i()->fetchAll(); //foreach ($options as $o_k => $o_v ) { // $pValue = $o_v->toArray(); // $pKey = $o_k; foreach ($plugins as $plugin) { /* @var $plugin Application_Model_Plugin */ if (!$plugin->isEnabled() && $plugin->getType() != Application_Model_Plugin::SYSTEM) { continue; } $pKey = $plugin->getKey(); try { if ($options->{$pKey}) { $pValue = $options->{$pKey}->toArray(); } else { // no configs $pValue = array(); } } catch (Exception $e) { // no configs $pValue = array(); } $pValue['class'] = $plugin->getClass(); if ($plugin->getFile() != null) { $pValue['path'] = APPLICATION_PATH . "/../library/" . $plugin->getFile(); } $className = $pValue['class']; $path = @$pValue['path']; // se class non e' settato, il plugin nn e' valido if (!$className) { continue; } if ($path && substr($path, -4) == '.php' && file_exists($path)) { require_once $path; } if (class_exists($className) && is_subclass_of($className, 'X_VlcShares_Plugins_Abstract')) { $pValue['id'] = $pKey; // si auto referenzia //new $className(new Zend_Config($pValue)); // plugins system from // event-based -> function-based $plugin = new $className(); //X_Debug::i($pKey . ":\n".var_export($pValue, true)); $plugin->setConfigs(new Zend_Config($pValue)); self::$_pluginBroker->registerPlugin($pKey, $plugin, true); } } self::$_helperBroker = new X_VlcShares_Plugins_Helper_Broker($helpersOptions); X_Debug::i("Plugin system enabled"); $pluginlist = implode(', ', array_keys(self::$_pluginBroker->getPlugins())); X_Debug::i("Plugins registered: {$pluginlist}"); $helperlist = implode(', ', array_keys(self::$_helperBroker->getHelpers())); X_Debug::i("Helpers registered: {$helperlist}"); self::$_pluginBroker->gen_afterPluginsInitialized(self::$_pluginBroker); }