function AttributeDiscoveryWithAnnotations::getAnnotationReader

Same name in other branches
  1. 11.x core/lib/Drupal/Core/Plugin/Discovery/AttributeDiscoveryWithAnnotations.php \Drupal\Core\Plugin\Discovery\AttributeDiscoveryWithAnnotations::getAnnotationReader()

Gets the used doctrine annotation reader.

This is a copy of the getAnnotationReader method from annotated class discovery.

Return value

\Drupal\Component\Annotation\Doctrine\SimpleAnnotationReader The annotation reader.

See also

\Drupal\Component\Annotation\Plugin\Discovery\AnnotatedClassDiscovery::getAnnotationReader()

\Drupal\Core\Plugin\Discovery\AnnotatedClassDiscovery::getAnnotationReader()

File

core/lib/Drupal/Core/Plugin/Discovery/AttributeDiscoveryWithAnnotations.php, line 139

Class

AttributeDiscoveryWithAnnotations
Enables both attribute and annotation discovery for plugin definitions.

Namespace

Drupal\Core\Plugin\Discovery

Code

private function getAnnotationReader() : SimpleAnnotationReader {
    if (!isset($this->annotationReader)) {
        $this->annotationReader = new SimpleAnnotationReader();
        // Add the namespaces from the main plugin annotation, like @EntityType.
        $namespace = substr($this->pluginDefinitionAnnotationName, 0, strrpos($this->pluginDefinitionAnnotationName, '\\'));
        $this->annotationReader
            ->addNamespace($namespace);
        // Register additional namespaces to be scanned for annotations.
        foreach ($this->additionalNamespaces as $namespace) {
            $this->annotationReader
                ->addNamespace($namespace);
        }
        // Add the Core annotation classes like @Translation.
        $this->annotationReader
            ->addNamespace('Drupal\\Core\\Annotation');
    }
    return $this->annotationReader;
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.