Skip to content

Commit

Permalink
Do not display hidden files
Browse files Browse the repository at this point in the history
  • Loading branch information
loicsapone committed Aug 12, 2024
1 parent cf8e901 commit 7c8c4e2
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/Provider/Factory/LocalFilesystemProviderFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,13 @@ public function configureResolver(OptionsResolver $resolver): void

$resolver->setDefault('media_url', '');
$resolver->setAllowedTypes('media_url', 'string');

$resolver->setDefault('ignore_dot_files', true);
$resolver->setAllowedTypes('ignore_dot_files', 'bool');
}

public function create(array $options): ?ProviderInterface
{
return new LocalFilesystemProvider($options['path'], $options['media_url']);
return new LocalFilesystemProvider($options['path'], $options['media_url'], $options['ignore_dot_files']);
}
}
5 changes: 5 additions & 0 deletions src/Provider/LocalFilesystemProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
public function __construct(
string $location,
private string $mediaUrl = '',
private bool $ignoreDotFiles = true,
) {
$this->rootLocation = rtrim($location, '\\/').\DIRECTORY_SEPARATOR;
}
Expand Down Expand Up @@ -113,6 +114,10 @@ public function listDirectory(string $id, bool $recursive = false): \Generator
continue;
}

if ($this->ignoreDotFiles && str_starts_with($fileInfo->getBasename(), '.')) {
continue;
}

$path = $this->stripPrefix($fileInfo->getPathname());

yield new Node(
Expand Down
13 changes: 13 additions & 0 deletions tests/Provider/FilesystemProviderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,12 +89,25 @@ public function testListDirectory(): void
$provider = new LocalFilesystemProvider(self::ROOT);
$provider->write('directory/filename.txt', 'content');
$provider->write('filename.txt', 'content');
$provider->write('.hidden', 'content');

$contentIterator = $provider->listDirectory('/');
$contents = iterator_to_array($contentIterator);
$this->assertCount(2, $contents);
}

public function testListDirectoryWithDotFiles(): void
{
$provider = new LocalFilesystemProvider(self::ROOT, ignoreDotFiles: false);
$provider->write('directory/filename.txt', 'content');
$provider->write('filename.txt', 'content');
$provider->write('.hidden', 'content');

$contentIterator = $provider->listDirectory('/');
$contents = iterator_to_array($contentIterator);
$this->assertCount(3, $contents);
}

public function testNodeInfo(): void
{
$provider = new LocalFilesystemProvider(self::ROOT);
Expand Down

0 comments on commit 7c8c4e2

Please sign in to comment.