You are here

protected function AnnotatedClassDiscovery::getAnnotationReader in Rules 8.3

Gets the used doctrine annotation reader.

Return value

\Doctrine\Common\Annotations\Reader The annotation reader.

Overrides AnnotatedClassDiscovery::getAnnotationReader

File

src/Context/AnnotatedClassDiscovery.php, line 19

Class

AnnotatedClassDiscovery
Extends the annotation class discovery for usage with Rules context.

Namespace

Drupal\rules\Context

Code

protected function getAnnotationReader() {
  if (!isset($this->annotationReader)) {

    // Do not call out the parent, but re-configure the simple annotation
    // reader on our own, so we can control the order of namespaces.
    $this->annotationReader = new SimpleAnnotationReader();

    // Make sure to add our namespace first, so our ContextDefinition and
    // Condition annotations gets picked.
    $this->annotationReader
      ->addNamespace('Drupal\\rules\\Context\\Annotation');
    $this->annotationReader
      ->addNamespace('Drupal\\rules\\Core\\Annotation');

    // Add the namespaces from the main plugin annotation, like @EntityType.
    $namespace = substr($this->pluginDefinitionAnnotationName, 0, strrpos($this->pluginDefinitionAnnotationName, '\\'));
    $this->annotationReader
      ->addNamespace($namespace);

    // Add general core annotations like @Translation.
    $this->annotationReader
      ->addNamespace('Drupal\\Core\\Annotation');
  }
  return $this->annotationReader;
}