pluginInstances = array(); } /** * gives access to the singleton * @return Amfphp_Core_PluginManager */ public static function getInstance() { if (self::$instance == NULL) { self::$instance = new Amfphp_Core_PluginManager(); } return self::$instance; } /** * load the plugins * @param array $pluginFolders where to load the plugins from. Absolute paths. For example Amfphp/Plugins/ * @param array $pluginsConfig optional. an array containing the plugin configuration, using the plugin name as key. * @param array $sharedConfig optional. if both a specific config and a shared config are available, concatenate them to create the plugin config. * Otherwise use whatever is not null * @param array $disabledPlugins optional. an array of names of plugins to disable */ public function loadPlugins($pluginFolders, array $pluginsConfig = null, array $sharedConfig = null, array $disabledPlugins = null) { foreach ($pluginFolders as $pluginsFolderRootPath) { if (!is_dir($pluginsFolderRootPath)) { throw new Amfphp_Core_Exception('invalid path for loading plugins at ' . $pluginsFolderRootPath); } $folderContent = scandir($pluginsFolderRootPath); foreach ($folderContent as $pluginName) { if (!is_dir($pluginsFolderRootPath . '/' . $pluginName)) { continue; } //avoid system folders if ($pluginName[0] == '.') { continue; } //check first if plugin is disabled $shouldLoadPlugin = true; if ($disabledPlugins) { foreach ($disabledPlugins as $disabledPlugin) { if ($disabledPlugin == $pluginName) { $shouldLoadPlugin = false; } } } if (!$shouldLoadPlugin) { continue; } if (!class_exists($pluginName, false)) { require_once $pluginsFolderRootPath . '/' . $pluginName . '/' . $pluginName . '.php'; } $pluginConfig = array(); if ($pluginsConfig && isset($pluginsConfig[$pluginName])) { $pluginConfig = $pluginsConfig[$pluginName]; } if ($sharedConfig) { $pluginConfig += $sharedConfig; } $pluginInstance = new $pluginName($pluginConfig); $this->pluginInstances[] = $pluginInstance; } } } } ?>