Documentation

PluginManager
in package
Uses Singleton

Plugin manager

Tags
author

Alexey Bobkov, Samuel Georges

Table of Contents

$noInit  : bool
$app  : mixed
The application instance, since Plugins are an extension of a Service Provider
$booted  : bool
$disabledPlugins  : array<string|int, mixed>
$instance  : mixed
$metaFile  : string
$normalizedMap  : array<string|int, mixed>
$pathMap  : array<string|int, mixed>
$plugins  : array<string|int, mixed>
$registered  : bool
$registrationMethodCache  : array<string|int, mixed>
__clone()  : mixed
__wakeup()  : mixed
bindContainerObjects()  : mixed
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.
bootAll()  : void
Runs the boot() method on all plugins. Can only be called once.
bootPlugin()  : void
Boots the provided plugin object.
clearDisabledCache()  : void
Clears the disabled plugins cache file
deletePlugin()  : void
Completely roll back and delete a plugin from the system.
disablePlugin()  : bool
Disables a single plugin in the system.
enablePlugin()  : bool
Enables a single plugin in the system.
exists()  : bool
Check if a plugin exists and is enabled.
findByIdentifier()  : PluginBase|null
Returns a plugin registration class based on its identifier (Author.Plugin).
findByNamespace()  : PluginBase|null
Returns a plugin registration class based on its namespace (Author\Plugin).
findMissingDependencies()  : array<string|int, mixed>
Scans the system plugins to locate any dependencies that are not currently installed. Returns an array of missing plugin codes keyed by the plugin that requires them.
forgetInstance()  : mixed
Forget this singleton's instance if it exists
getDependencies()  : array<string|int, mixed>
Returns the plugin identifiers that are required by the supplied plugin.
getIdentifier()  : string
Resolves a plugin identifier (Author.Plugin) from a plugin class name or object.
getPluginNamespaces()  : array<string|int, mixed>
Returns a flat array of vendor plugin namespaces and their paths
getPluginPath()  : string|null
Returns the directory path to a plugin
getPlugins()  : array<string|int, mixed>
Returns an array with all enabled plugins The index is the plugin namespace, the value is the plugin information object.
getRegistrationMethodValues()  : array<string|int, mixed>
Spins over every plugin object and collects the results of a method call. Results are cached in memory.
getVendorAndPluginNames()  : array<string|int, mixed>
Returns a 2 dimensional array of vendors and their plugins.
hasPlugin()  : bool
Checks to see if a plugin has been registered.
instance()  : mixed
Create a new instance of this singleton.
isDisabled()  : bool
Determines if a plugin is disabled by looking at the meta information or the application configuration.
loadPlugin()  : void
Loads a single plugin into the manager.
loadPlugins()  : array<string|int, mixed>
Finds all available plugins and loads them in to the $this->plugins array.
normalizeIdentifier()  : string
Takes a human plugin code (acme.blog) and makes it authentic (Acme.Blog) Returns the provided identifier if a match isn't found
refreshPlugin()  : void
Tears down a plugin's database tables and rebuilds them.
registerAll()  : void
Runs the register() method on all plugins. Can only be called once.
registerPlugin()  : void
Registers a single plugin object.
sortByDependencies()  : mixed
unregisterAll()  : void
Unregisters all plugins: the inverse of registerAll().
__construct()  : mixed
Constructor.
init()  : mixed
Initializes the plugin manager
loadDependencies()  : void
Cross checks all plugins and their dependancies, if not met plugins are disabled and vice versa.
loadDisabled()  : void
Loads all disabled plugins from the cached JSON file.
populateDisabledPluginsFromDb()  : void
Populates information about disabled plugins from database
sortDependencies()  : array<string|int, mixed>
Sorts a collection of plugins, in the order that they should be actioned, according to their given dependencies. Least dependent come first.
writeDisabled()  : void
Write the disabled plugins to a meta file.

Properties

$noInit

public static bool $noInit = false

Prevent all plugins from registering or booting

$app

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

protected mixed $app

$booted

protected bool $booted = false

Flag to indicate that all plugins have had the boot() method called by bootAll() being called on this class.

$disabledPlugins

protected array<string|int, mixed> $disabledPlugins = []

Array of disabled plugins

$metaFile

protected string $metaFile

Path to the JSON encoded file containing the disabled plugins.

$normalizedMap

protected array<string|int, mixed> $normalizedMap = []

A map of normalized plugin identifiers [lowercase.identifier => Normalized.Identifier]

$pathMap

protected array<string|int, mixed> $pathMap = []

A map of plugins and their directory paths.

$plugins

protected array<string|int, mixed> $plugins

Container array used for storing plugin information objects.

$registered

protected bool $registered = false

Flag to indicate that all plugins have had the register() method called by registerAll() being called on this class.

$registrationMethodCache

protected array<string|int, mixed> $registrationMethodCache = []

Cache of registration method results.

Methods

__clone()

public __clone() : mixed
Return values
mixed

__wakeup()

public __wakeup() : mixed
Return values
mixed

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 bindContainerObjects() : mixed
Return values
mixed

bootAll()

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

public bootAll([bool $force = false ]) : void
Parameters
$force : bool = false

Defaults to false, if true will force the re-booting of all plugins

Return values
void

clearDisabledCache()

Clears the disabled plugins cache file

public clearDisabledCache() : void
Return values
void

deletePlugin()

Completely roll back and delete a plugin from the system.

public deletePlugin(string $id) : void
Parameters
$id : string

Plugin code/namespace

Return values
void

disablePlugin()

Disables a single plugin in the system.

public disablePlugin(string|PluginBase $id[, bool $isUser = false ]) : bool
Parameters
$id : string|PluginBase

Plugin code/namespace

$isUser : bool = false

Set to true if disabled by the user, false by default

Return values
bool

Returns false if the plugin was already disabled, true otherwise

enablePlugin()

Enables a single plugin in the system.

public enablePlugin(string|PluginBase $id[, bool $isUser = false ]) : bool
Parameters
$id : string|PluginBase

Plugin code/namespace

$isUser : bool = false

Set to true if enabled by the user, false by default

Return values
bool

Returns false if the plugin wasn't already disabled or if the user disabled a plugin that the system is trying to re-enable, true otherwise

exists()

Check if a plugin exists and is enabled.

public exists(string $id) : bool
Parameters
$id : string

Plugin identifier, eg: Namespace.PluginName

Return values
bool

findByNamespace()

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

public findByNamespace(string $namespace) : PluginBase|null
Parameters
$namespace : string
Return values
PluginBase|null

findMissingDependencies()

Scans the system plugins to locate any dependencies that are not currently installed. Returns an array of missing plugin codes keyed by the plugin that requires them.

public findMissingDependencies() : array<string|int, mixed>

['Author.Plugin' => ['Required.Plugin1', 'Required.Plugin2']

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

Return values
array<string|int, mixed>

forgetInstance()

Forget this singleton's instance if it exists

public final static forgetInstance() : mixed
Return values
mixed

getDependencies()

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

public getDependencies(string $plugin) : array<string|int, mixed>
Parameters
$plugin : string

Plugin identifier, object or class

Return values
array<string|int, mixed>

getIdentifier()

Resolves a plugin identifier (Author.Plugin) from a plugin class name or object.

public getIdentifier(mixed $namespace) : string
Parameters
$namespace : mixed
Return values
string

Identifier in format of Author.Plugin

getPluginNamespaces()

Returns a flat array of vendor plugin namespaces and their paths

public getPluginNamespaces() : array<string|int, mixed>
Return values
array<string|int, mixed>

['Author\Plugin' => 'plugins/author/plugin']

getPluginPath()

Returns the directory path to a plugin

public getPluginPath(PluginBase|string $id) : string|null
Parameters
$id : PluginBase|string

The plugin to get the path for

Return values
string|null

getPlugins()

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

public getPlugins() : array<string|int, mixed>
Return values
array<string|int, mixed>

getRegistrationMethodValues()

Spins over every plugin object and collects the results of a method call. Results are cached in memory.

public getRegistrationMethodValues(string $methodName) : array<string|int, mixed>
Parameters
$methodName : string
Return values
array<string|int, mixed>

getVendorAndPluginNames()

Returns a 2 dimensional array of vendors and their plugins.

public getVendorAndPluginNames() : array<string|int, mixed>
Return values
array<string|int, mixed>

['vendor' => ['author' => 'plugins/author/plugin']]

hasPlugin()

Checks to see if a plugin has been registered.

public hasPlugin(mixed $namespace) : bool
Parameters
$namespace : mixed
Return values
bool

instance()

Create a new instance of this singleton.

public final static instance() : mixed
Return values
mixed

isDisabled()

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

public isDisabled(string|PluginBase $id) : bool
Parameters
$id : string|PluginBase
Return values
bool

loadPlugin()

Loads a single plugin into the manager.

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

Eg: Acme\Blog

$path : string

Eg: plugins_path().'/acme/blog';

Return values
void

loadPlugins()

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

public loadPlugins() : array<string|int, mixed>
Return values
array<string|int, mixed>

normalizeIdentifier()

Takes a human plugin code (acme.blog) and makes it authentic (Acme.Blog) Returns the provided identifier if a match isn't found

public normalizeIdentifier(string $identifier) : string
Parameters
$identifier : string
Return values
string

refreshPlugin()

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

public refreshPlugin(string $id) : void
Parameters
$id : string

Plugin code/namespace

Return values
void

registerAll()

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

public registerAll([bool $force = false ]) : void
Parameters
$force : bool = false

Defaults to false, if true will force the re-registration of all plugins. Use unregisterAll() instead.

Return values
void

registerPlugin()

Registers a single plugin object.

public registerPlugin(PluginBase $plugin[, string $pluginId = null ]) : void
Parameters
$plugin : PluginBase

The instantiated Plugin object

$pluginId : string = null

The string identifier for the plugin

Return values
void

sortByDependencies()

public sortByDependencies([mixed $plugins = null ]) : mixed
Parameters
$plugins : mixed = null
Tags
deprecated

Plugins are now sorted by default. See getPlugins() Remove if year >= 2022

Return values
mixed

unregisterAll()

Unregisters all plugins: the inverse of registerAll().

public unregisterAll() : void
Return values
void

__construct()

Constructor.

protected final __construct() : mixed
Return values
mixed

init()

Initializes the plugin manager

protected init() : mixed
Return values
mixed

loadDependencies()

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

protected loadDependencies() : void
Return values
void

loadDisabled()

Loads all disabled plugins from the cached JSON file.

protected loadDisabled() : void
Return values
void

populateDisabledPluginsFromDb()

Populates information about disabled plugins from database

protected populateDisabledPluginsFromDb() : void
Return values
void

sortDependencies()

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

protected sortDependencies() : array<string|int, mixed>
Tags
throws
SystemException

If a possible circular dependency is detected

Return values
array<string|int, mixed>

Array of sorted plugin identifiers and instantiated classes ['Author.Plugin' => PluginBase]

writeDisabled()

Write the disabled plugins to a meta file.

protected writeDisabled() : void
Return values
void

Search results