PluginManager
Plugin manager
class System\Classes\PluginManager
Traits
Trait | Description |
---|---|
Singleton
|
Singleton trait. |
Constants
Constant | Type | Value | Description |
---|---|---|---|
DISABLED_BY_CONFIG
|
string |
"disabled-config"
|
string
"disabled-config"
|
DISABLED_BY_USER
|
string |
"disabled-user"
|
string
"disabled-user"
|
DISABLED_MISSING
|
string |
"disabled-missing"
|
string
"disabled-missing"
|
DISABLED_MISSING_DEPENDENCIES
|
string |
"disabled-dependencies"
|
string
"disabled-dependencies"
|
DISABLED_REPLACED
|
string |
"disabled-replaced"
|
string
"disabled-replaced"
|
DISABLED_REPLACEMENT_FAILED
|
string |
"disabled-replacement-failed"
|
string
"disabled-replacement-failed"
|
DISABLED_REQUEST
|
string |
"disabled-request"
|
string
"disabled-request"
|
Properties
public
static
$noInit
:
bool
= false
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
= false
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
= false
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.
Property | Type | Description |
---|---|---|
$force | boolean |
boolean
Defaults to false, if true will force the re-booting of all plugins |
public bootPlugin (System\Classes\PluginBase $plugin) : void
Boots the provided plugin object.
Property | Type | Description |
---|---|---|
$plugin | System\Classes\PluginBase |
System\Classes\PluginBase
|
public clearFlagCache () : void
Reset the plugin flag cache
public deletePlugin (string $id) : void
Completely roll back and delete a plugin from the system.
Property | Type | Description |
---|---|---|
$id | string |
string
|
public disablePlugin (System\Classes\PluginBase | string $plugin, $flag) : bool
Disables the provided plugin using the provided flag (defaults to static::DISABLED_BY_USER)
Property | Type | Description |
---|---|---|
$plugin | System\Classes\PluginBase | string |
System\Classes\PluginBase | string
|
$flag | mixed |
mixed
|
public enablePlugin (System\Classes\PluginBase | string $plugin, $flag) : bool
Enables the provided plugin using the provided flag (defaults to static::DISABLED_BY_USER)
Property | Type | Description |
---|---|---|
$plugin | System\Classes\PluginBase | string |
System\Classes\PluginBase | string
|
$flag | mixed |
mixed
|
public exists (System\Classes\PluginBase | string $plugin) : bool
Check if a plugin exists and is enabled.
Property | Type | Description |
---|---|---|
$plugin | System\Classes\PluginBase | string |
System\Classes\PluginBase | string
|
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).
Property | Type | Description |
---|---|---|
$identifier | System\Classes\PluginBase | string |
System\Classes\PluginBase | string
|
$ignoreReplacements | boolean |
boolean
|
public findByNamespace (string $namespace) : System\Classes\PluginBase | null
Returns a plugin registration class based on its namespace (Author\Plugin).
Property | Type | Description |
---|---|---|
$namespace | string |
string
|
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();
public freezePlugin (System\Classes\PluginBase | string $plugin) : void
Flags the provided plugin as "frozen" (updates cannot be downloaded / installed)
Property | Type | Description |
---|---|---|
$plugin | System\Classes\PluginBase | string |
System\Classes\PluginBase | string
|
public
getActiveReplacementMap ($plugin = null
)
: array | string | null
Returns the actively replaced plugins defined in $this->activeReplacementMap
Property | Type | Description |
---|---|---|
$plugin | mixed |
mixed
|
public getAllPlugins () : array
Returns an array will all plugins detected on the filesystem
[$code => $pluginObj]
public getDependencies (System\Classes\PluginBase | string $plugin) : array
Returns the plugin identifiers that are required by the supplied plugin.
Property | Type | Description |
---|---|---|
$plugin | System\Classes\PluginBase | string |
System\Classes\PluginBase | string
|
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.
Property | Type | Description |
---|---|---|
$plugin | System\Classes\PluginBase | string |
System\Classes\PluginBase | string
|
$lower | boolean |
boolean
|
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.
Property | Type | Description |
---|---|---|
$plugin | System\Classes\PluginBase | string |
System\Classes\PluginBase | 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.
Property | Type | Description |
---|---|---|
$plugin | System\Classes\PluginBase | string |
System\Classes\PluginBase | string
|
$lower | boolean |
boolean
|
public getPluginFlags (System\Classes\PluginBase | string $plugin) : array
Property | Type | Description |
---|---|---|
$plugin | System\Classes\PluginBase | string |
System\Classes\PluginBase | string
|
public getPluginNamespaces () : array
Returns a flat array of vendor plugin namespaces and their paths ['Author\Plugin' => 'plugins/author/plugin']
public getPluginPath (System\Classes\PluginBase | string $plugin) : string | null
Returns the directory path to a plugin
Property | Type | Description |
---|---|---|
$plugin | System\Classes\PluginBase | string |
System\Classes\PluginBase | string
|
public getPlugins () : array
Returns an array with all enabled plugins
[$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.
Property | Type | Description |
---|---|---|
$methodName | string |
string
|
public getReplacementMap () : array
Returns the plugin replacements defined in $this->replacementMap
public getVendorAndPluginNames () : array
Returns a 2 dimensional array of vendors and their plugins.
['vendor' => ['author' => 'plugins/author/plugin']]
public hasPlugin (System\Classes\PluginBase | string $plugin) : bool
Checks to see if a plugin has been registered.
Property | Type | Description |
---|---|---|
$plugin | System\Classes\PluginBase | string |
System\Classes\PluginBase | string
|
public isDisabled (System\Classes\PluginBase | string $plugin) : bool
Determines if a plugin is disabled by looking at the meta information or the application configuration.
Property | Type | Description |
---|---|---|
$plugin | System\Classes\PluginBase | string |
System\Classes\PluginBase | string
|
public loadPlugin (string $namespace, string $path) : System\Classes\PluginBase | null
Loads a single plugin into the manager.
Property | Type | Description |
---|---|---|
$namespace | string |
string
Eg: Acme\Blog |
$path | string |
string
Eg: plugins_path().'/acme/blog'; |
public loadPluginFlags () : void
Loads the plugin flags (disabled & replacement states) from the cache regenerating them if required.
public loadPlugins () : array
Finds all available plugins and loads them in to the $this->plugins 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
Property | Type | Description |
---|---|---|
$code | string |
string
|
public refreshPlugin (string $id) : void
Tears down a plugin's database tables and rebuilds them.
Property | Type | Description |
---|---|---|
$id | string |
string
|
public
registerAll (boolean $force = false
)
: void
Runs the register() method on all plugins. Can only be called once.
Property | Type | Description |
---|---|---|
$force | boolean |
boolean
Defaults to false, if true will force the re-registration of all plugins. Use unregisterAll() instead. |
public
registerPlugin (System\Classes\PluginBase $plugin, $pluginId = null
)
: void
Registers a single plugin object.
Property | Type | Description |
---|---|---|
$plugin | System\Classes\PluginBase |
System\Classes\PluginBase
|
$pluginId | mixed |
mixed
|
public unfreezePlugin (System\Classes\PluginBase | string $plugin) : void
"Unfreezes" the provided plugin, allowing for updates to be performed
Property | Type | Description |
---|---|---|
$plugin | System\Classes\PluginBase | string |
System\Classes\PluginBase | string
|
public unregisterAll () : void
Unregisters all plugins: the inverse of registerAll().
protected aliasPluginAs (string $namespace, string $alias) : void
Registers namespace aliasing for multiple subsystems
Property | Type | Description |
---|---|---|
$namespace | string |
string
|
$alias | string |
string
|
protected detectPluginReplacements () : void
Evaluates the replacement map to determine which replacements can actually take effect
protected flagPlugin (System\Classes\PluginBase | string $plugin, string $flag) : void
Sets the provided flag on the provided plugin
Property | Type | Description |
---|---|---|
$plugin | System\Classes\PluginBase | string |
System\Classes\PluginBase | string
|
$flag | string |
string
|
protected getFlagCacheKey () : string
Get the cache key for the current plugin manager state
protected getPluginRecord (System\Classes\PluginBase | string $plugin) : System\Models\PluginVersion
Get the PluginVersion record for the provided plugin
Property | Type | Description |
---|---|---|
$plugin | System\Classes\PluginBase | string |
System\Classes\PluginBase | string
|
protected init () : void
Initializes the plugin manager
protected loadDependencies () : void
Checks plugin dependencies and flags plugins with missing dependencies as disabled
protected loadDisabled () : void
Loads all disabled plugins from the cached JSON file.
protected registerPluginReplacements () : void
Executes the plugin replacements defined in the activeReplacementMap property
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.
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
Property | Type | Description |
---|---|---|
$plugin | System\Classes\PluginBase | string |
System\Classes\PluginBase | string
|
$flag | string |
string
|
inherited public __clone ()
inherited public __wakeup ()
inherited
public
static
final
forgetInstance ($container = null
)
: void
Forget this singleton's instance if it exists
Property | Type | Description |
---|---|---|
$container | mixed |
mixed
|
inherited
public
static
final
instance ($container = null
)
: static
Create a new instance of this singleton.
Property | Type | Description |
---|---|---|
$container | mixed |
mixed
|
inherited protected final __construct ()
Constructor.