class ReflectionFactory extends DefaultFactory (View source)

A plugin factory that maps instance configuration to constructor arguments.

Provides logic for any basic plugin type that needs to provide individual plugins based upon some basic logic.

Properties

protected DiscoveryInterface $discovery

The object that retrieves the definitions of the plugins that this factory instantiates.

from  DefaultFactory
protected string|null $interface

Defines an interface each plugin should implement.

from  DefaultFactory

Methods

__construct(DiscoveryInterface $discovery, string|null $plugin_interface = NULL)

Constructs a Drupal\Component\Plugin\Factory\DefaultFactory object.

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

Creates a pre-configured instance of a plugin.

static string
getPluginClass(string $plugin_id, PluginDefinitionInterface|array $plugin_definition = NULL, string $required_interface = NULL)

Finds the class relevant for a given plugin.

array
getInstanceArguments(ReflectionClass $reflector, string $plugin_id, mixed $plugin_definition, array $configuration)

Inspects the plugin class and build a list of arguments for the constructor.

Details

__construct(DiscoveryInterface $discovery, string|null $plugin_interface = NULL)

Constructs a Drupal\Component\Plugin\Factory\DefaultFactory object.

Parameters

DiscoveryInterface $discovery

The plugin discovery.

string|null $plugin_interface

(optional) The interface each plugin should implement.

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

static string getPluginClass(string $plugin_id, PluginDefinitionInterface|array $plugin_definition = NULL, string $required_interface = NULL)

Finds the class relevant for a given plugin.

Parameters

string $plugin_id

The id of a plugin.

PluginDefinitionInterface|array $plugin_definition

The plugin definition associated with the plugin ID.

string $required_interface

(optional) The required plugin interface.

Return Value

string

The appropriate class name.

Exceptions

PluginException

protected array getInstanceArguments(ReflectionClass $reflector, string $plugin_id, mixed $plugin_definition, array $configuration)

Inspects the plugin class and build a list of arguments for the constructor.

This is provided as a helper method so factories extending this class can replace this and insert their own reflection logic.

Parameters

ReflectionClass $reflector

The reflector object being used to inspect the plugin class.

string $plugin_id

The identifier of the plugin implementation.

mixed $plugin_definition

The definition associated with the plugin_id.

array $configuration

An array of configuration that may be passed to the instance.

Return Value

array

An array of arguments to be passed to the constructor.