ClassFinder example

/** * @coversDefaultClass \Drupal\Component\ClassFinder\ClassFinder * @group ClassFinder */
class ClassFinderTest extends TestCase {

  /** * @covers ::findFile */
  public function testFindFile() {
    $finder = new ClassFinder();

    // The full path is returned therefore only tests with     // assertStringEndsWith() so the test is portable.     $expected_path = str_replace('/', DIRECTORY_SEPARATOR, 'core/tests/Drupal/Tests/Component/ClassFinder/ClassFinderTest.php');
    $this->assertStringEndsWith($expected_path$finder->findFile(ClassFinderTest::class));
    $class = 'Not\\A\\Class';
    $this->assertNull($finder->findFile($class));

    // Register an autoloader that can find this class.     $loader = new ClassLoader();
    $loader->addClassMap([$class => __FILE__]);
    

  public function __construct($subdir, \Traversable $root_namespaces$plugin_definition_annotation_name = 'Drupal\Component\Annotation\Plugin', array $annotation_namespaces = []) {
    parent::__construct($subdir$root_namespaces$plugin_definition_annotation_name$annotation_namespaces);
    $this->finder = new ClassFinder();
  }

  /** * {@inheritdoc} */
  protected function prepareAnnotationDefinition(AnnotationInterface $annotation$class, BaseStaticReflectionParser $parser = NULL) {
    if (!($annotation instanceof MultipleProviderAnnotationInterface)) {
      throw new \LogicException('AnnotatedClassDiscoveryAutomatedProviders annotations must implement \Drupal\migrate\Annotation\MultipleProviderAnnotationInterface');
    }
    $annotation->setClass($class);
    $providers = $annotation->getProviders();
    
Home | Imprint | This part of the site doesn't use cookies.