StaticReflectionParser example

$classmap = $this->findAllClassFiles($extension);

    // Prevent expensive class loader lookups for each reflected test class by     // registering the complete classmap of test classes to the class loader.     // This also ensures that test classes are loaded from the discovered     // pathnames; a namespace/classname mismatch will throw an exception.     $this->classLoader->addClassMap($classmap);

    foreach ($classmap as $classname => $pathname) {
      $finder = MockFileFinder::create($pathname);
      $parser = new StaticReflectionParser($classname$finder, TRUE);
      try {
        $info = static::getTestInfo($classname$parser->getDocComment());
      }
      catch (MissingGroupException $e) {
        // If the class name ends in Test and is not a migrate table dump.         if (preg_match('/Test$/', $classname) && !str_contains($classname, 'migrate_drupal\Tests\Table')) {
          throw $e;
        }
        // If the class is @group annotation just skip it. Most likely it is an         // abstract class, trait or test fixture.         continue;
      }
continue;
              }

              $sub_path = $iterator->getSubIterator()->getSubPath();
              $sub_path = $sub_path ? str_replace(DIRECTORY_SEPARATOR, '\\', $sub_path) . '\\' : '';
              $class = $namespace . '\\' . $sub_path . $fileinfo->getBasename('.php');

              // 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());
              $parser = new StaticReflectionParser($class$finder, TRUE);

              /** @var \Drupal\Component\Annotation\AnnotationInterface $annotation */
              if ($annotation = $reader->getClassAnnotation($parser->getReflectionClass()$this->pluginDefinitionAnnotationName)) {
                $this->prepareAnnotationDefinition($annotation$class);

                $id = $annotation->getId();
                $content = $annotation->get();
                $definitions[$id] = $content;
                // Explicitly serialize this to create a new object instance.                 $this->fileCache->set($fileinfo->getPathName()['id' => $id, 'content' => serialize($content)]);
              }
              
Home | Imprint | This part of the site doesn't use cookies.