abstract class PluginManagerBase implements PluginManagerInterface (View source)

Base class for plugin managers.

Traits

Properties

protected DiscoveryInterface $discovery

The object that discovers plugins managed by this manager.

protected FactoryInterface $factory

The object that instantiates plugins managed by this manager.

protected MapperInterface|null $mapper

The object that returns the preconfigured plugin instance appropriate for a particular runtime condition.

Methods

array
getDefinitions()

Gets the definition of all plugins for this type.

mixed
getDefinition(string $plugin_id, bool $exception_on_invalid = TRUE)

Gets a specific plugin definition.

array|null
doGetDefinition(array $definitions, string $plugin_id, bool $exception_on_invalid)

Gets a specific plugin definition.

hasDefinition($plugin_id)

{@inheritdoc}

getDiscovery()

Gets the plugin discovery.

getFactory()

Gets the plugin factory.

object
createInstance(string $plugin_id, array $configuration = [])

Creates a pre-configured instance of a plugin.

object
handlePluginNotFound(string $plugin_id, array $configuration)

Allows plugin managers to specify custom behavior if a plugin is not found.

object|false
getInstance(array $options)

Gets a preconfigured instance of a plugin.

Details

array getDefinitions()

Gets the definition of all plugins for this type.

Return Value

array

An array of plugin definitions (empty array if no definitions were found). Keys are plugin IDs.

mixed getDefinition(string $plugin_id, bool $exception_on_invalid = TRUE)

Gets a specific plugin definition.

Parameters

string $plugin_id

A plugin id.

bool $exception_on_invalid

(optional) If TRUE, an invalid plugin ID will throw an exception.

Return Value

mixed

A plugin definition, or NULL if the plugin ID is invalid and $exception_on_invalid is FALSE.

Exceptions

PluginNotFoundException

protected array|null doGetDefinition(array $definitions, string $plugin_id, bool $exception_on_invalid)

Gets a specific plugin definition.

Parameters

array $definitions

An array of the available plugin definitions.

string $plugin_id

A plugin id.

bool $exception_on_invalid

If TRUE, an invalid plugin ID will cause an exception to be thrown; if FALSE, NULL will be returned.

Return Value

array|null

A plugin definition, or NULL if the plugin ID is invalid and $exception_on_invalid is TRUE.

Exceptions

PluginNotFoundException

hasDefinition($plugin_id)

{@inheritdoc}

Parameters

$plugin_id

protected DiscoveryInterface getDiscovery()

Gets the plugin discovery.

Return Value

DiscoveryInterface

protected FactoryInterface getFactory()

Gets the plugin factory.

Return Value

FactoryInterface

object createInstance(string $plugin_id, array $configuration = [])

Creates a pre-configured instance of a plugin.

Parameters

string $plugin_id

The ID of the plugin being instantiated.

array $configuration

An array of configuration relevant to the plugin instance.

Return Value

object

A fully configured plugin instance.

Exceptions

PluginException

protected object handlePluginNotFound(string $plugin_id, array $configuration)

Allows plugin managers to specify custom behavior if a plugin is not found.

Parameters

string $plugin_id

The ID of the missing requested plugin.

array $configuration

An array of configuration relevant to the plugin instance.

Return Value

object

A fallback plugin instance.

object|false getInstance(array $options)

Gets a preconfigured instance of a plugin.

Parameters

array $options

An array of options that can be used to determine a suitable plugin to instantiate and how to configure it.

Return Value

object|false

A fully configured plugin instance. The interface of the plugin instance will depend on the plugin type. If no instance can be retrieved, FALSE will be returned.