System\Classes\PluginManager

PluginManager

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()

bindContainerObjects rebinds to the container because 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)

exists checks if a plugin exists and is enabled

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

public void findByIdentifier($identifier)

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

Parameters
  • $identifier

public void findByNamespace($namespace)

findByNamespace 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 void getAllPlugins()

getAllPlugins regardless of enabled state

public void getComposerCode($id)

getComposerCode finds the composer code for a plugin

Parameters
  • $id

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)

getPluginPath returns the directory path to a plugin

Parameters
  • $id

public void getPlugins()

getPlugins 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)

hasPlugin 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($namespace, $path)

loadPlugin loads a single plugin in to the manager where a namespace is Acme\Blog and the path is somewhere on the disk

Parameters
  • $namespace
  • $path

public void loadPlugins()

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)

registerAll runs the register() method on all plugins and 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 void sortByDependencies($plugins=NULL)
Parameters
  • $plugins

public void unregisterAll()

unregisterAll unregisters all plugins: the negative of registerAll()

Protected methods

protected void __construct()

Constructor.

protected void init()

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 array sortDependencies()

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

protected void writeDisabled()

Write the disabled plugins to a meta file.