* $plugins_list = array(); * $plugins_list[] = array( * 'name' => 'plugin_name', // Obligatory value * 'dependences' => array( // Dependences of the plugin * 'another_plugin_name' * ), * 'config' => array( // Pass to plugin constructor * 'weight' => 100, * 'some_configurable_value' => 'value' * ) * ) * * * @see Plugin::registerEvents() * @see Plugin::registerListeners() */ public static function loadPlugins($plugins_list){ // Add include path $include_path = get_include_path(); $include_path .= empty($include_path) ? '' : PATH_SEPARATOR ; set_include_path($include_path . realpath(dirname(__FILE__) . "/../../plugins/")); // Load plugins $loading_queue = array(); $offset = 0; foreach ($plugins_list as $plugin) { if (empty($plugin['name'])) { trigger_error("Plugin name undefined!", E_USER_WARNING); continue; } $plugin_name = $plugin['name']; $plugin_config = isset($plugin['config']) ? $plugin['config'] : array(); $plugin_dependences = isset($plugin['dependences']) ? $plugin['dependences'] : array(); $plugin_classname = ucfirst($plugin_name) . "Plugin"; // Check plugin dependences foreach ($plugin_dependences as $dependence) { if (empty(self::$loaded_plugins[$dependence])) { trigger_error( "Plugin '{$dependence}' not loaded yet, but " . "exists in '{$plugin_name}' dependences list!", E_USER_WARNING ); continue 2; } } // Try to load plugin file if (! (include_once $plugin_name."/".$plugin_name."_plugin.php")) { trigger_error("Cannot load plugin file!", E_USER_ERROR); } // Check plugin class name if (! class_exists($plugin_classname)) { trigger_error( "Plugin class '{$plugin_classname}' does not defined!", E_USER_WARNING ); continue; } // Check if plugin extends abstract 'Plugin' class if ('Plugin' != get_parent_class($plugin_classname)) { trigger_error( "Plugin class '{$plugin_classname}' does not extend " . "abstract 'Plugin' class!", E_USER_WARNING ); continue; } // Add plugin to loading queue $plugin_instance = new $plugin_classname($plugin_config); if ($plugin_instance->initialized) { // Store plugin instance self::$loaded_plugins[$plugin_name] = $plugin_instance; $loading_queue[$plugin_instance->getWeight() . "_" . $offset] = $plugin_instance; $offset++; } else { trigger_error( "Plugin '{$plugin_name}' does not initialized correctly!", E_USER_WARNING ); } } // Sort queue in order to plugins' weights uksort($loading_queue, 'strnatcmp'); // Add events and listeners foreach ($loading_queue as $plugin) { $plugin->registerEvents(); $plugin->registerListeners(); } } } ?>