System\Classes\PluginManager

Source: ~/modules/system/classes/PluginManager.php

Plugin manager

Public properties

public static boolean $noInit

Prevent all plugins from registering or booting

Protected properties

protected $app

The application instance, since Plugins are an extension of a Service Provider

protected $plugins

Container object used for storing plugin information objects.

protected array $pathMap

A map of plugins and their directory paths.

protected bool $registered

Check if all plugins have had the register() method called.

protected bool $booted

Check if all plugins have had the boot() method called.

protected string $metaFile

Path to the disarm file.

protected array $disabledPlugins

Collection of disabled plugins

protected array $registrationMethodCache

Cache of registration method results.

protected static $instance

Public methods

public void __clone()

public void __wakeup()

public void bindContainerObjects()

These objects are "soft singletons" and may be lost when the IoC container reboots. This provides a way to rebuild for the purposes of unit testing.

public void bootAll($force=false)

Runs the boot() method on all plugins. Can only be called once.

Parameters
  • $force

public void bootPlugin(PluginBase $plugin)

Registers a single plugin object.

Parameters
  • PluginBase $plugin

public void clearDisabledCache()

public void deletePlugin(string $id)

Completely roll back and delete a plugin from the system.

Parameters
  • string $id - Plugin code/namespace

public bool disablePlugin(string $id, bool $isUser=false)

Disables a single plugin in the system.

Parameters
  • string $id - Plugin code/namespace
  • bool $isUser - Set to true if disabled by the user

public bool enablePlugin(string $id, bool $isUser=false)

Enables a single plugin in the system.

Parameters
  • string $id - Plugin code/namespace
  • bool $isUser - Set to true if enabled by the user

public boolean exists(string $id)

Check if a plugin exists and is enabled.

Parameters
  • string $id - Plugin identifier, eg: Namespace.PluginName

public void findByIdentifier($identifier)

Returns a plugin registration class based on its identifier (Author.Plugin).

Parameters
  • $identifier

public void findByNamespace($namespace)

Returns a plugin registration class based on its namespace (Author\Plugin).

Parameters
  • $namespace

public array findMissingDependencies()

Scans the system plugins to locate any dependencies that are not currently installed. Returns an array of plugin codes that are needed.

PluginManager::instance()->findMissingDependencies();

public static void forgetInstance()

Forget this singleton's instance if it exists

public array getDependencies(string $plugin)

Returns the plugin identifiers that are required by the supplied plugin.

Parameters
  • string $plugin - Plugin identifier, object or class

public string getIdentifier(mixed $namespace)

Resolves a plugin identifier from a plugin class name or object.

Parameters
  • mixed $namespace - Plugin class name or object

public void getPluginNamespaces()

Returns a flat array of vendor plugin namespaces and their paths

public void getPluginPath($id)

Returns the directory path to a plugin

Parameters
  • $id

public void getPlugins()

Returns an array with all registered plugins The index is the plugin namespace, the value is the plugin information object.

public array getRegistrationMethodValues(string $methodName)

Spins over every plugin object and collects the results of a method call.

Parameters
  • string $methodName

public void getVendorAndPluginNames()

Returns a 2 dimensional array of vendors and their plugins.

public void hasPlugin($namespace)

Checks to see if a plugin has been registered.

Parameters
  • $namespace

public static void instance()

Create a new instance of this singleton.

public boolean isDisabled($id)

Determines if a plugin is disabled by looking at the meta information or the application configuration.

Parameters
  • $id

public void loadPlugin(string $namespace, string $path)

Loads a single plugin in to the manager.

Parameters
  • string $namespace - Eg: Acme\Blog
  • string $path - Eg: plugins_path().'/acme/blog';

public array loadPlugins()

Finds all available plugins and loads them in to the $plugins array.

public string normalizeIdentifier(string $id)

Takes a human plugin code (acme.blog) and makes it authentic (Acme.Blog)

Parameters
  • string $id

public void refreshPlugin(string $id)

Tears down a plugin's database tables and rebuilds them.

Parameters
  • string $id - Plugin code/namespace

public void registerAll($force=false)

Runs the register() method on all plugins. Can only be called once.

Parameters
  • $force

public void registerPlugin(PluginBase $plugin, string $pluginId=NULL)

Registers a single plugin object.

Parameters
  • PluginBase $plugin
  • string $pluginId

public array sortByDependencies(array $plugins=NULL)

Sorts a collection of plugins, in the order that they should be actioned, according to their given dependencies. Least dependent come first.

Parameters
  • array $plugins - Object collection to sort, or null to sort all.

public void unregisterAll()

Unregisters all plugins: the negative of registerAll().

Protected methods

protected void __construct()

Constructor.

protected void init()

Initializes the plugin manager

protected void loadDependencies()

Cross checks all plugins and their dependancies, if not met plugins are disabled and vice versa.

protected void loadDisabled()

Loads all disables plugins from the meta file.

protected void populateDisabledPluginsFromDb()

Populates information about disabled plugins from database

protected void writeDisabled()

Write the disabled plugins to a meta file.