/** * Load a plugin (and make sure the plugin API is available). * * To be loaded, the plugin must be installed, active, and not have a newer * version. If loaded, the plugin will attempt to first load all plugins, * both required and optional, that the plugin uses. However, it will not * load a plugin that it uses if that plugin is not installed and activated. * * @param Plugin $plugin * @param boolean $force If true, throws exceptions if a plugin can't be * loaded. * @param array $pluginsWaitingToLoad Plugins waiting to be loaded * @throws Omeka_Plugin_Loader_Exception * @return void */ public function load(Plugin $plugin, $force = false, $pluginsWaitingToLoad = array()) { $this->registerPlugin($plugin); $this->_iniReader->load($plugin); $pluginDirName = $plugin->getDirectoryName(); if (!$this->_canLoad($plugin, $force)) { if ($force) { throw new Omeka_Plugin_Loader_Exception(__("The %s plugin could not be loaded.", $pluginDirName)); } else { return; } } // If the current plugin is already on the waiting list, don't load it. if (array_key_exists(spl_object_hash($plugin), $pluginsWaitingToLoad)) { return; } else { // Otherwise add the current plugin to the waiting list. $pluginsWaitingToLoad[spl_object_hash($plugin)] = $plugin; } // Load the required plugins $requiredPluginDirNames = $plugin->getRequiredPlugins(); foreach ($requiredPluginDirNames as $requiredPluginDirName) { if (!($requiredPlugin = $this->getPlugin($requiredPluginDirName))) { // If we can't find one of the required plugins, loading should // fail. if ($force) { throw new Omeka_Plugin_Loader_Exception(__("The required plugin '%s' could not be found.", $requiredPluginDirName)); } else { return; } } // If the required plugin is already loaded, do not attempt to load // it a second time. if ($requiredPlugin->isLoaded()) { continue; } $this->load($requiredPlugin, $force, $pluginsWaitingToLoad); // make sure the required plugin is loaded. // if a required plugin of the plugin cannot be loaded, // then do not load the plugin if (!$requiredPlugin->isLoaded()) { return; } } // Load the optional plugins $optionalPluginDirNames = $plugin->getOptionalPlugins(); foreach ($optionalPluginDirNames as $optionalPluginDirName) { if (!($optionalPlugin = $this->getPlugin($optionalPluginDirName))) { // If we can't find one of the optional plugins, it should skip it and try to load the next one. continue; } // If the optional plugin is already loaded, do not attempt to load // it a second time. if ($optionalPlugin->isLoaded()) { continue; } // If the optional plugin cannot load, then fail silently $this->load($optionalPlugin, false, $pluginsWaitingToLoad); } // add the plugin dir paths and require the plugin files $this->_mvc->addApplicationDirs($pluginDirName); $this->_loadPluginBootstrap($plugin); // This won't work unless the plugin has already been loaded. $plugin->setHasConfig((bool) $this->_broker->getHook($plugin->getDirectoryName(), 'config')); // remember that the plugin is loaded $plugin->setLoaded(true); }