YamlDirectoryDiscovery example

vfsStream::url('modules/test_2/subdir2'),
      ],
      // Directories that do not exist.       'test_3' => [
        vfsStream::url('modules/test_3/subdir1'),
        vfsStream::url('modules/test_3/subdir2'),
      ],
      // A single directory.       'test_4' => vfsStream::url('modules/test_4/subdir1'),
    ];

    $discovery = new YamlDirectoryDiscovery($directories, 'test');
    $data = $discovery->findAll();

    // The file path is dependent on the operating system, so we adjust the directory separator.     $this->assertSame(['id' => 'item1', 'name' => 'test1 item 1', YamlDirectoryDiscovery::FILE_KEY => 'vfs://modules/test_1/subdir1' . DIRECTORY_SEPARATOR . 'item_1.test.yml']$data['test_1']['item1']);
    $this->assertSame(['id' => 'item2', 'name' => 'test1 item 2', YamlDirectoryDiscovery::FILE_KEY => 'vfs://modules/test_1/subdir2' . DIRECTORY_SEPARATOR . 'item_2.test.yml']$data['test_1']['item2']);
    $this->assertCount(2, $data['test_1']);

    $this->assertSame(['id' => 'item3', 'name' => 'test2 item 3', YamlDirectoryDiscovery::FILE_KEY => 'vfs://modules/test_2/subdir1' . DIRECTORY_SEPARATOR . 'item_3.test.yml']$data['test_2']['item3']);
    $this->assertCount(1, $data['test_2']);

    $this->assertArrayNotHasKey('test_3', $data, 'test_3 provides 0 items');

    

  protected function getDiscovery() {
    if (!isset($this->discovery)) {
      $directories = array_map(function D$directory) {
        return [$directory . '/migrations'];
      }$this->moduleHandler->getModuleDirectories());

      $yaml_discovery = new YamlDirectoryDiscovery($directories, 'migrate');
      // This gets rid of migrations which try to use a non-existent source       // plugin. The common case for this is if the source plugin has, or       // specifies, a non-existent provider.       $only_with_source_discovery = new NoSourcePluginDecorator($yaml_discovery);
      // This gets rid of migrations with explicit providers set if one of the       // providers do not exist before we try to use a potentially non-existing       // deriver. This is a rare case.       $filtered_discovery = new ProviderFilterDecorator($only_with_source_discovery[$this->moduleHandler, 'moduleExists']);
      $this->discovery = new ContainerDerivativeDiscoveryDecorator($filtered_discovery);
    }
    return $this->discovery;
  }
$directories = [
      'module_a' => [
        vfsStream::url('modules/module_a/subdir1'),
        vfsStream::url('modules/module_a/subdir2'),
        // Empty directory.         vfsStream::url('modules/module_a/subdir3'),
        // Directory does not exist.         vfsStream::url('modules/module_a/subdir4'),
      ],
      'module_b' => vfsStream::url('modules/module_b/subdir1'),
    ];
    $discovery = new YamlDirectoryDiscovery($directories, 'test');

    $definitions = $discovery->getDefinitions();

    $this->assertIsArray($definitions);
    $this->assertCount(4, $definitions);

    foreach ($definitions as $id => $definition) {
      foreach (['id', 'provider', ComponentYamlDirectoryDiscovery::FILE_KEY] as $key) {
        $this->assertArrayHasKey($key$definition);
      }
      $this->assertEquals($id$definition['id']);
      
Home | Imprint | This part of the site doesn't use cookies.