class AnnotatedClassDiscovery implements DiscoveryInterface (View source)

Defines a discovery mechanism to find annotated plugins in PSR-4 namespaces.

Traits

Properties

protected string[] $pluginNamespaces

The namespaces within which to find plugin classes.

protected string $pluginDefinitionAnnotationName

The name of the annotation that contains the plugin definition.

protected Reader $annotationReader

The doctrine annotation reader.

protected string[] $annotationNamespaces

Additional namespaces to be scanned for annotation classes.

protected FileCacheInterface $fileCache

The file cache object.

Methods

array
getDefinitions()

Gets the definition of all plugins for this type.

getDefinition($plugin_id, $exception_on_invalid = TRUE)

{@inheritdoc}

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

Gets a specific plugin definition.

hasDefinition($plugin_id)

{@inheritdoc}

__construct(string[] $plugin_namespaces = [], string $plugin_definition_annotation_name = 'Drupal\\Component\\Annotation\\Plugin', array $annotation_namespaces = [])

Constructs a new instance.

Reader
getAnnotationReader()

Gets the used doctrine annotation reader.

prepareAnnotationDefinition(AnnotationInterface $annotation, string $class)

Prepares the annotation definition.

string[]
getPluginNamespaces()

Gets an array of PSR-4 namespaces to search for plugin classes.

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.

getDefinition($plugin_id, $exception_on_invalid = TRUE)

{@inheritdoc}

Parameters

$plugin_id
$exception_on_invalid

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

__construct(string[] $plugin_namespaces = [], string $plugin_definition_annotation_name = 'Drupal\\Component\\Annotation\\Plugin', array $annotation_namespaces = [])

Constructs a new instance.

Parameters

string[] $plugin_namespaces

(optional) An array of namespace that may contain plugin implementations. Defaults to an empty array.

string $plugin_definition_annotation_name

(optional) The name of the annotation that contains the plugin definition. Defaults to 'Drupal\Component\Annotation\Plugin'.

array $annotation_namespaces

(optional) Additional namespaces to be scanned for annotation classes.

protected Reader getAnnotationReader()

Gets the used doctrine annotation reader.

Return Value

Reader

The annotation reader.

protected prepareAnnotationDefinition(AnnotationInterface $annotation, string $class)

Prepares the annotation definition.

Parameters

AnnotationInterface $annotation

The annotation derived from the plugin.

string $class

The class used for the plugin.

protected string[] getPluginNamespaces()

Gets an array of PSR-4 namespaces to search for plugin classes.

Return Value

string[]