PluginManager

Plugin manager

 class System\Classes\PluginManager

Traits

Trait Description
Singleton

Singleton trait.

Constants

Constant Description
DISABLED_BY_CONFIG
string "disabled-config"
DISABLED_BY_USER
string "disabled-user"
DISABLED_MISSING
string "disabled-missing"
DISABLED_MISSING_DEPENDENCIES
string "disabled-dependencies"
DISABLED_REPLACED
string "disabled-replaced"
DISABLED_REPLACEMENT_FAILED
string "disabled-replacement-failed"
DISABLED_REQUEST
string "disabled-request"

Properties

public static $noInit : bool

Prevent all plugins from registering or booting

protected $activeReplacementMap : array

A map of plugins that are currently replaced [Original.Plugin => Replacement.Plugin]

protected $app : Winter\Storm\Foundation\Application

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

protected $booted : bool

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

protected $normalizedMap : array

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

protected $pluginFlags : array

Array of plugin codes that contain any flags currently associated with the plugin

protected $pluginRecords : \PluginVersion[]

Local cache of loaded PluginVersion records keyed by plugin code

protected $plugins : \PluginBase[]

Container array used for storing plugin information objects.

protected $registered : bool

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

protected $registrationMethodCache : array

Cache of registration method results.

protected $replacementMap : array

A map of plugin identifiers with their replacements [Original.Plugin => Replacement.Plugin]

Methods

public bootAll (boolean $force = false) : void

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

Parameters
Property Description
$force
boolean

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

Returns
void

public bootPlugin (System\Classes\PluginBase $plugin) : void

Boots the provided plugin object.

Parameters
Property Description
$plugin
System\Classes\PluginBase
Returns
void

public clearFlagCache () : void

Reset the plugin flag cache

Returns
void

public deletePlugin (string $id) : void

Completely roll back and delete a plugin from the system.

Parameters
Property Description
$id
string
Returns
void

public disablePlugin (System\Classes\PluginBase | string $plugin, $flag) : bool

Disables the provided plugin using the provided flag (defaults to static::DISABLED_BY_USER)

Parameters
Property Description
$plugin
System\Classes\PluginBase | string
$flag
mixed
Returns
bool

public enablePlugin (System\Classes\PluginBase | string $plugin, $flag) : bool

Enables the provided plugin using the provided flag (defaults to static::DISABLED_BY_USER)

Parameters
Property Description
$plugin
System\Classes\PluginBase | string
$flag
mixed
Returns
bool

public exists (System\Classes\PluginBase | string $plugin) : bool

Check if a plugin exists and is enabled.

Parameters
Property Description
$plugin
System\Classes\PluginBase | string
Returns
bool

public findByIdentifier (System\Classes\PluginBase | string $identifier, boolean $ignoreReplacements = false) : System\Classes\PluginBase | null

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

Parameters
Property Description
$identifier
System\Classes\PluginBase | string
$ignoreReplacements
boolean
Returns
System\Classes\PluginBase | null

public findByNamespace (string $namespace) : System\Classes\PluginBase | null

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

Parameters
Property Description
$namespace
string
Returns
System\Classes\PluginBase | null

public findMissingDependencies () : array

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.

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

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

Returns
array

public freezePlugin (System\Classes\PluginBase | string $plugin) : void

Flags the provided plugin as "frozen" (updates cannot be downloaded / installed)

Parameters
Property Description
$plugin
System\Classes\PluginBase | string
Returns
void

public getActiveReplacementMap ($plugin = null) : array | string | null

Returns the actively replaced plugins defined in $this->activeReplacementMap

Parameters
Property Description
$plugin
mixed
Returns
array | string | null

public getAllPlugins () : array

Returns an array will all plugins detected on the filesystem

Returns
array

[$code => $pluginObj]

public getDependencies (System\Classes\PluginBase | string $plugin) : array

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

Parameters
Property Description
$plugin
System\Classes\PluginBase | string
Returns
array

public getIdentifier (System\Classes\PluginBase | string $plugin, boolean $lower = false) : string

Resolves a plugin identifier (Author.Plugin) from a plugin class name (Author\Plugin) or PluginBase instance.

Parameters
Property Description
$plugin
System\Classes\PluginBase | string
$lower
boolean
Returns
string

public getNamespace (System\Classes\PluginBase | string $plugin) : string

Resolves a plugin namespace (Author\Plugin) from a plugin class name (Author\Plugin\Classes\Example), identifier (Author.Plugin), or PluginBase instance.

Parameters
Property Description
$plugin
System\Classes\PluginBase | string
Returns
string

public getNormalizedIdentifier (System\Classes\PluginBase | string $plugin, boolean $lower = false) : string

Returns the normalized identifier (i.e. Winter.Blog) from the provided string or PluginBase instance.

Parameters
Property Description
$plugin
System\Classes\PluginBase | string
$lower
boolean
Returns
string

public getPluginFlags (System\Classes\PluginBase | string $plugin) : array

Parameters
Property Description
$plugin
System\Classes\PluginBase | string
Returns
array

public getPluginNamespaces () : array

Returns a flat array of vendor plugin namespaces and their paths ['Author\Plugin' => 'plugins/author/plugin']

Returns
array

public getPluginPath (System\Classes\PluginBase | string $plugin) : string | null

Returns the directory path to a plugin

Parameters
Property Description
$plugin
System\Classes\PluginBase | string
Returns
string | null

public getPlugins () : array

Returns an array with all enabled plugins

Returns
array

[$code => $pluginObj]

public getRegistrationMethodValues (string $methodName) : array

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

Parameters
Property Description
$methodName
string
Returns
array

public getReplacementMap () : array

Returns the plugin replacements defined in $this->replacementMap

Returns
array

public getVendorAndPluginNames () : array

Returns a 2 dimensional array of vendors and their plugins.

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

Returns
array

public hasPlugin (System\Classes\PluginBase | string $plugin) : bool

Checks to see if a plugin has been registered.

Parameters
Property Description
$plugin
System\Classes\PluginBase | string
Returns
bool

public isDisabled (System\Classes\PluginBase | string $plugin) : bool

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

Parameters
Property Description
$plugin
System\Classes\PluginBase | string
Returns
bool

public loadPlugin (string $namespace, string $path) : System\Classes\PluginBase | null

Loads a single plugin into the manager.

Parameters
Property Description
$namespace
string

Eg: Acme\Blog

$path
string

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

Returns
System\Classes\PluginBase | null

public loadPluginFlags () : void

Loads the plugin flags (disabled & replacement states) from the cache regenerating them if required.

Returns
void

public loadPlugins () : array

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

Returns
array

public normalizeIdentifier (string $code) : string

Normalizes the provided plugin identifier (author.plugin) and resolves it case-insensitively to the normalized identifier (Author.Plugin) Returns the provided identifier if a match isn't found

Parameters
Property Description
$code
string
Returns
string

public refreshPlugin (string $id) : void

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

Parameters
Property Description
$id
string
Returns
void

public registerAll (boolean $force = false) : void

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

Parameters
Property Description
$force
boolean

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

Returns
void

public registerPlugin (System\Classes\PluginBase $plugin, $pluginId = null) : void

Registers a single plugin object.

Parameters
Property Description
$plugin
System\Classes\PluginBase
$pluginId
mixed
Returns
void

public unfreezePlugin (System\Classes\PluginBase | string $plugin) : void

"Unfreezes" the provided plugin, allowing for updates to be performed

Parameters
Property Description
$plugin
System\Classes\PluginBase | string
Returns
void

public unregisterAll () : void

Unregisters all plugins: the inverse of registerAll().

Returns
void

protected aliasPluginAs (string $namespace, string $alias) : void

Registers namespace aliasing for multiple subsystems

Parameters
Property Description
$namespace
string
$alias
string
Returns
void

protected detectPluginReplacements () : void

Evaluates the replacement map to determine which replacements can actually take effect

Returns
void

protected flagPlugin (System\Classes\PluginBase | string $plugin, string $flag) : void

Sets the provided flag on the provided plugin

Parameters
Property Description
$plugin
System\Classes\PluginBase | string
$flag
string
Returns
void

protected getFlagCacheKey () : string

Get the cache key for the current plugin manager state

Returns
string

protected getPluginRecord (System\Classes\PluginBase | string $plugin) : System\Models\PluginVersion

Get the PluginVersion record for the provided plugin

Parameters
Property Description
$plugin
System\Classes\PluginBase | string
Returns
System\Models\PluginVersion

protected init () : void

Initializes the plugin manager

Returns
void

protected loadDependencies () : void

Checks plugin dependencies and flags plugins with missing dependencies as disabled

Returns
void

protected loadDisabled () : void

Loads all disabled plugins from the cached JSON file.

Returns
void

protected registerPluginReplacements () : void

Executes the plugin replacements defined in the activeReplacementMap property

Returns
void

protected sortByDependencies () : array

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

Returns
array

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

protected unflagPlugin (System\Classes\PluginBase | string $plugin, string $flag) : void

Removes the provided flag from the provided plugin

Parameters
Property Description
$plugin
System\Classes\PluginBase | string
$flag
string
Returns
void

inherited public __clone ()

Inherited from Singleton
Returns
mixed

inherited public __wakeup ()

Inherited from Singleton
Returns
mixed

inherited public static final forgetInstance ($container = null) : void

Inherited from Singleton

Forget this singleton's instance if it exists

Parameters
Property Description
$container
mixed
Returns
void

inherited public static final instance ($container = null) : static

Inherited from Singleton

Create a new instance of this singleton.

Parameters
Property Description
$container
mixed
Returns
static

inherited protected final __construct ()

Inherited from Singleton

Constructor.

Returns
mixed
Copyright © 2024 Winter CMS