function AttributeDiscoveryWithAnnotationsAutomatedProviders::parseClass

Overrides AttributeDiscoveryWithAnnotations::parseClass

File

core/modules/migrate/src/Plugin/Discovery/AttributeDiscoveryWithAnnotationsAutomatedProviders.php, line 57

Class

AttributeDiscoveryWithAnnotationsAutomatedProviders
Enables both attribute and annotation discovery for plugin definitions.

Namespace

Drupal\migrate\Plugin\Discovery

Code

protected function parseClass(string $class, \SplFileInfo $fileinfo) : array {
  // Parse using attributes first.
  $definition = $this->attributeDiscovery
    ->parseClass($class, $fileinfo);
  if (isset($definition['id'])) {
    return $definition;
  }
  // The filename is already known, so there is no need to find the
  // file. However, StaticReflectionParser needs a finder, so use a
  // mock version.
  $finder = MockFileFinder::create($fileinfo->getPathName());
  // The parser is instantiated here with FALSE as the last parameter. This is
  // needed so that the parser includes the 'extends' declaration and extracts
  // providers from ancestor classes.
  $parser = new BaseStaticReflectionParser($class, $finder, FALSE);
  $reflection_class = $parser->getReflectionClass();
  // @todo Handle deprecating definitions discovery via annotations in
  // https://www.drupal.org/project/drupal/issues/3522409.
  /** @var \Drupal\Component\Annotation\AnnotationInterface $annotation */
  if ($annotation = $this->getAnnotationReader()
    ->getClassAnnotation($reflection_class, $this->pluginDefinitionAnnotationName)) {
    $this->prepareAnnotationDefinition($annotation, $class, $parser);
    return [
      'id' => $annotation->getId(),
      'content' => $annotation->get(),
    ];
  }
  return [
    'id' => NULL,
    'content' => NULL,
  ];
}

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