Dispatches a pluggable application

@see Atomik::registerPluggableApplication()
@param string $plugin Plugin's name
@param string $uri Uri
@param array $config Configuration
@return bool Dispatch success
513147
public static function dispatchPluggableApplication($plugin, $uri = null, $config = array())
    {
        $plugin = ucfirst($plugin);
        $config = array_merge(array(
            'rootDir'             => '', 
            'pluginDir'           => null,
            'resetConfig'         => true, 
            'overwriteDirs'       => true, 
            'overwriteFiles'      => true, 
            'checkPluginIsLoaded' => true,
            'bootstrapFile'       => 'Application.php'
        ), $config);
        
        if ($config['checkPluginIsLoaded'] && !self::isPluginLoaded($plugin)) {
            return false;
        }
        
        $uri = $uri ?: '';
        $rootDir = rtrim('/' . trim($config['rootDir'], '/'), '/');
        if ($config['pluginDir'] === null) {
            $pluginDir = self::$plugins[$plugin];
        } else {
            $pluginDir = rtrim($config['pluginDir'], '/');
        }
        
        $appDir = $pluginDir . $rootDir;
        if (!is_dir($appDir)) {
            throw new AtomikException("To be used as an application, the plugin '$plugin' must use a directory");
        }
        
        $overrideDir = self::findFile($plugin . $rootDir, self::path(self::get('atomik.dirs.overrides')));
        if ($overrideDir === false) {
            $overrideDir = 'overrides/' . $plugin . $rootDir;
        }
        
        if (!self::has('app.running_plugin')) {
            // saves user configuration
            self::set('userapp', self::get('app'));
        }
        self::set('app.running_plugin', $plugin); 
        self::set('request_uri', $uri);
        
        // resets the configuration but keep the layout
        if ($config['resetConfig']) {
            $layout = self::get('app.layout');
            self::reset();
            self::set('app.layout', $layout);
            self::set('app.routes', array());
        }
        
        // rewrite dirs
        $dirs = self::get('atomik.dirs');
        $dirs['actions'] = array($overrideDir . '/actions', $appDir . '/actions');
        $dirs['views'] = array($overrideDir . '/views', $appDir . '/views');
        
        $overwritableDirs = array(
            'layouts'   => array($overrideDir . '/layouts', $overrideDir . '/views', 
                                    $appDir . '/layouts', $appDir . '/views')
        );
        
        if ($config['overwriteDirs']) {
            $dirs = array_merge($dirs, $overwritableDirs);
        } else {
            $dirs = array_merge_recursive($overwritableDirs, $dirs);
        }
        
        // do not overwrite helpers
        $dirs['helpers'] = array_merge(
            array($overrideDir . '/helpers', $appDir . '/helpers'),
            (array) $dirs['helpers']
        );
        
        self::set('atomik.dirs', $dirs);
        
        // rewrite files
        if ($config['overwriteFiles']) {
            $files = self::get('atomik.files');
            $files['pre_dispatch'] = $appDir . '/pre_dispatch.php';
            $files['post_dispatch'] = $appDir . '/post_dispatch.php';
            self::set('atomik.files', $files);
        }
        
        $cancel = false;
        self::fireEvent('Atomik::Dispatchpluginapplication::Ready', array($plugin, &$uri, $config, &$cancel));
        if ($cancel) {
            return true;
        }
        
        $bootstrapFile = $appDir . '/' . $config['bootstrapFile'];
        if (file_exists($bootstrapFile)) {
            $continue = include $bootstrapFile;
            if ($continue === false) {
                return true;
            }
        }
        
        $cancel = false;
        self::fireEvent('Atomik::Dispatchpluginapplication::Start', array($plugin, &$uri, $config, &$cancel));
        if ($cancel) {
            return true;
        }
        
        return self::dispatch($uri, false);
    }
462753
public function merge(Plugin $newPlugin)
    {
        if ($newPlugin->getNamespace() !== $this->getNamespace()) {
            throw new RuntimeException('Both plugins cannot be merged');
        }

        $this
            ->configuration
            ->merge($newPlugin->getConfiguration());

        return $this;
    }
441857
public static function registerRedactorPlugin(string $plugin)
    {
        if (isset(self::$_registeredPlugins[$plugin])) {
            return;
        }

        $paths = self::redactorPluginPaths();

        foreach ($paths as $registeredPath) {
            foreach (["{$registeredPath}/{$plugin}", $registeredPath] as $path) {
                if (file_exists("{$path}/{$plugin}.js")) {
                    $view = Craft::$app->getView();
                    $baseUrl = Craft::$app->getAssetManager()->getPublishedUrl($path, true);
                    $view->registerJsFile("{$baseUrl}/{$plugin}.js", [
                        'depends' => RedactorAsset::class
                    ]);
                    // CSS file too?
                    if (file_exists("{$path}/{$plugin}.css")) {
                        $view->registerCssFile("{$baseUrl}/{$plugin}.css");
                    }
                    // Don't do this twice
                    self::$_registeredPlugins[$plugin] = true;
                    return;
                }
            }
        }

        throw new InvalidConfigException('Redactor plugin not found: '.$plugin);
    }
365946
public function executePlugin($plugin, $options)
    {
        // Any plugin name without a namespace separator is a PHPCI built in plugin
        // if not we assume it's a fully name-spaced class name that implements the plugin interface.
        // If not the factory will throw an exception.
        if (strpos($plugin, '\\') === false) {
            $class = str_replace('_', ' ', $plugin);
            $class = ucwords($class);
            $class = 'PHPCI\\Plugin\\' . str_replace(' ', '', $class);
        } else {
            $class = $plugin;
        }

        if (!class_exists($class)) {
            $this->logger->logFailure(Lang::get('plugin_missing', $plugin));
            return false;
        }

        try {
            // Build and run it
            $obj = $this->pluginFactory->buildPlugin($class, $options);
            return $obj->execute();
        } catch (\Exception $ex) {
            $this->logger->logFailure(Lang::get('exception') . $ex->getMessage(), $ex);
            return false;
        }
    }
659110
public function registerRequestPlugins()
    {
        $callableRepository = $this->di()->get(CallableRepository::class);
        $this->registerPlugin(new CallableClass($callableRepository), 101);
        $this->registerPlugin(new CallableDir($callableRepository), 102);
        $this->registerPlugin(new UserFunction(), 103);
        $this->registerPlugin(new FileUpload(), 104);
    }
821823
public void addPlugin(SimonConsolePlugin plugin) {
		SimonConsolePlugin existingPlugin = getPluginById(plugin.getId());
		if (existingPlugin != null) {
			throw new IllegalArgumentException("Plugin " + plugin.getId() + " already registered");
		}
		plugins.add(plugin);
	}
692096
private void attemptPluginLoad(GrailsPlugin plugin) {
        if (areDependenciesResolved(plugin) && areNoneToLoadBefore(plugin)) {
            registerPlugin(plugin);
        }
        else {
            delayedLoadPlugins.add(plugin);
        }
    }
185215
public function setupPlugin(array $config = []): void
	{
		if (!$this->defaults) return;
		$this->setupConfig($this->defaults, $config);
	}
597666
public function enablePlugin($pluginName)
	{
		if (isset($this->pluginsConfig[$pluginName]))
		{
			$this->pluginsConfig[$pluginName]['isDisabled'] = false;
		}
	}
583551
public static function pluginUrl($plugin, $action, $params = array(), $useIndex = true)
    {
    	$plugin = ucfirst($plugin);
        if (!isset(self::$pluggableApplications[$plugin])) {
            throw new AtomikException("Plugin '$plugin' is not registered as a pluggable application");
        }
        
        $route = rtrim(self::$pluggableApplications[$plugin]['route'], '/*');
        return self::url($route . '/' . ltrim($action, '/'), $params, $useIndex, false);
    }
1015951
public function register(PluginBundleInterface $plugin)
    {
        $this->validate($plugin, false);

        return $this->dbWriter->insert($plugin, $this->validator->getPluginConfiguration());
    }
605443
public function registerPlugins()
    {
        $jsonFile = Environment::getJsonConfigFilename();
        if (!$jsonFile) {
            return;
        }

        $config = new Config;
        $var    = $config->validate($jsonFile);

        foreach ($var['plugins'] as $plugin) {
            if (class_exists($plugin['class'])) {
                if (isset($plugin['options'])) {
                    $options = $plugin['options'];
                    if (is_string($options)) {
                        if (class_exists($options)) {
                            $options = new $options;
                        } else {
                            $options = null;
                        }
                    }
                } else {
                    $options = null;
                }
                $plugin = new $plugin['class']($options);

                if ($plugin instanceof PluginInterface) {
                    $this->addPlugin($plugin);
                }
            }
        }
    }
1038679
private function registerPlugins(ConfigObject $config)
    {
        // antiflood
        if ($config->get('AntiFlood', false)) {
            $antiflood = new \Swift_Plugins_AntiFloodPlugin($config->get('AntiFlood.Threshold', 99),
                $config->get('AntiFlood.Sleep', 1));
            $this->mailer->registerPlugin($antiflood);
        }

        // array logger
        if ($config->get('Debug', false)) {
            $this->logger = new \Swift_Plugins_Loggers_ArrayLogger();
            $this->mailer->registerPlugin(new \Swift_Plugins_LoggerPlugin($this->logger));
        }
    }
553047
public static function load($plugin, array $config = [])
    {
        parent::load($plugin, $config);

        $plugin = (array) $plugin;
        foreach ($plugin as $name) {
            if ((bool) self::loaded($name)) {
                self::_addManifestCallback($name);
                Cms::mergeConfig('App.paths.locales', self::getLocalePath($name));
            }
        }
    }
194868
def register_plugin(self, plugin):
        
        if hasattr(plugin, 'initialise'):
            plugin.initialise()
        if self.valid_api_plugin(plugin):
            log.debug("Registering API plugin: {}".format(plugin))
            self._api_plugins[plugin.request] = plugin()
        elif self.valid_debugger_plugin(plugin):
            log.debug("Registering debugger plugin: {}".format(plugin))
            self._debugger_plugins[plugin.host] = plugin()
        elif self.valid_view_plugin(plugin):
            log.debug("Registering view plugin: {}".format(plugin))
            self._view_plugins[plugin.name] = plugin()
        elif self.valid_web_plugin(plugin):
            log.debug("Registering web plugin: {}".format(plugin))
            self._web_plugins[plugin.name] = plugin()
        elif self.valid_command_plugin(plugin):
            log.debug("Registering command plugin: {}".format(plugin))
            self._command_plugins[plugin.name] = plugin()
            if voltron.debugger:
                voltron.debugger.register_command_plugin(plugin.name, plugin.command_class)
        else:
            log.debug("Ignoring invalid plugin: {}".format(plugin))
898001
def register_plugin(self, name, plugin):
        
        if self.has_plugin(name):
            self.release_plugin(name)
        self._active_plugins[name] = plugin
        setattr(self, name, plugin)
        return plugin
1158488
protected function init(&$plugin, $autocreate = true, $dispatcher = null)
	{
		$plugin->type = preg_replace('/[^A-Z0-9_\.-]/i', '', $plugin->type);
		$plugin->name = preg_replace('/[^A-Z0-9_\.-]/i', '', $plugin->name);

		$classNameL = 'plg' . $plugin->type . $plugin->name;
		$classNameN = 'Plugins\\' . ucfirst($plugin->type) . '\\' . ucfirst($plugin->name);

		// If the class exists, the file was already loaded
		if (!class_exists($classNameL) && !class_exists($classNameN))
		{
			$path = $this->path($plugin->type, $plugin->name) . DS . $plugin->name . '.php';

			if (file_exists($path))
			{
				require_once $path;

				if ($autocreate)
				{
					foreach (array($classNameL, $classNameN) as $className)
					{
						if (!class_exists($className))
						{
							continue;
						}

						// Makes sure we have an event dispatcher
						if (!($dispatcher instanceof DispatcherInterface))
						{
							$dispatcher = new Dispatcher();
						}

						// Instantiate and register the plugin.
						return new $className($dispatcher, (array) $plugin);
					}
				}
			}
		}

		return null;
	}