public function AnnotatedClassDiscovery::getDefinitions in Drupal 10        
                          
                  
                        Same name and namespace in other branches
- 8 core/lib/Drupal/Component/Annotation/Plugin/Discovery/AnnotatedClassDiscovery.php \Drupal\Component\Annotation\Plugin\Discovery\AnnotatedClassDiscovery::getDefinitions()
- 9 core/lib/Drupal/Component/Annotation/Plugin/Discovery/AnnotatedClassDiscovery.php \Drupal\Component\Annotation\Plugin\Discovery\AnnotatedClassDiscovery::getDefinitions()
File
 
   - core/lib/Drupal/Component/Annotation/Plugin/Discovery/AnnotatedClassDiscovery.php, line 107
Class
  
  - AnnotatedClassDiscovery 
- Defines a discovery mechanism to find annotated plugins in PSR-4 namespaces.
Namespace
  Drupal\Component\Annotation\Plugin\Discovery
Code
public function getDefinitions() {
  $definitions = [];
  $reader = $this
    ->getAnnotationReader();
  
  AnnotationRegistry::reset();
  
  AnnotationRegistry::registerLoader('class_exists');
  
  foreach ($this
    ->getPluginNamespaces() as $namespace => $dirs) {
    foreach ($dirs as $dir) {
      if (file_exists($dir)) {
        $iterator = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($dir, \RecursiveDirectoryIterator::SKIP_DOTS));
        foreach ($iterator as $fileinfo) {
          if ($fileinfo
            ->getExtension() == 'php') {
            if ($cached = $this->fileCache
              ->get($fileinfo
              ->getPathName())) {
              if (isset($cached['id'])) {
                
                $definitions[$cached['id']] = unserialize($cached['content']);
              }
              continue;
            }
            $sub_path = $iterator
              ->getSubIterator()
              ->getSubPath();
            $sub_path = $sub_path ? str_replace(DIRECTORY_SEPARATOR, '\\', $sub_path) . '\\' : '';
            $class = $namespace . '\\' . $sub_path . $fileinfo
              ->getBasename('.php');
            
            $finder = MockFileFinder::create($fileinfo
              ->getPathName());
            $parser = new StaticReflectionParser($class, $finder, TRUE);
            
            if ($annotation = $reader
              ->getClassAnnotation($parser
              ->getReflectionClass(), $this->pluginDefinitionAnnotationName)) {
              $this
                ->prepareAnnotationDefinition($annotation, $class);
              $id = $annotation
                ->getId();
              $content = $annotation
                ->get();
              $definitions[$id] = $content;
              
              $this->fileCache
                ->set($fileinfo
                ->getPathName(), [
                'id' => $id,
                'content' => serialize($content),
              ]);
            }
            else {
              
              $this->fileCache
                ->set($fileinfo
                ->getPathName(), [
                NULL,
              ]);
            }
          }
        }
      }
    }
  }
  
  AnnotationRegistry::reset();
  return $definitions;
}