Back to PluginHelper class

Method import

protected static void
import
(mixed $plugin, mixed $autocreate = true, \Joomla\Event\DispatcherInterface $dispatcher = null)
Loads the plugin file.
Parameters
  • object $plugin The plugin.
  • bool $autocreate True to autocreate.
  • \Joomla\Event\DispatcherInterface $dispatcher Optionally allows the plugin to use a different dispatcher.
Returns
  • void
Since
  • 3.2
Class: PluginHelper
Project: Joomla

Method import - Source code

/**
 * Loads the plugin file.
 *
 * @param   object               $plugin      The plugin.
 * @param   boolean              $autocreate  True to autocreate.
 * @param   DispatcherInterface  $dispatcher  Optionally allows the plugin to use a different dispatcher.
 *
 * @return  void
 *
 * @since   3.2
 */
protected static function import($plugin, $autocreate = true, DispatcherInterface $dispatcher = null)
{
    static $plugins = [];
    // Get the dispatcher's hash to allow paths to be tracked against unique dispatchers
    $hash = spl_object_hash($dispatcher) . $plugin->type . $plugin->name;
    if (\array_key_exists($hash, $plugins)) {
        return;
    }
    $plugins[$hash] = true;
    $plugin = Factory::getApplication()->bootPlugin($plugin->name, $plugin->type);
    if ($dispatcher && $plugin instanceof DispatcherAwareInterface) {
        $plugin->setDispatcher($dispatcher);
    }
    if (!$autocreate) {
        return;
    }
    $plugin->registerListeners();
}