diff --git a/app/Controllers/DirectoryController.php b/app/Controllers/DirectoryController.php index 716f771..325b3b2 100644 --- a/app/Controllers/DirectoryController.php +++ b/app/Controllers/DirectoryController.php @@ -7,6 +7,7 @@ use Slim\Psr7\Request; use Slim\Psr7\Response; use Slim\Views\Twig; use Symfony\Component\Finder\Finder; +use Symfony\Component\Finder\SplFileInfo; use Tightenco\Collect\Support\Collection; class DirectoryController @@ -17,6 +18,9 @@ class DirectoryController /** @var Twig Twig templating component */ protected $view; + /** @var Collection Collection of hidden file paths */ + protected $hiddenFiles; + /** * Create a new DirectoryController object. * @@ -27,6 +31,14 @@ class DirectoryController { $this->config = $config; $this->view = $view; + + $this->hiddenFiles = Collection::make( + $this->config->get('hidden_files', []) + )->map(function (string $file) { + return glob($file, GLOB_BRACE | GLOB_NOSORT); + })->flatten()->map(function (string $file) { + return realpath($file); + }); } /** @@ -42,7 +54,9 @@ class DirectoryController { $files = Finder::create()->in($path)->depth(0)->followLinks(); $files->ignoreVCS($this->config->get('ignore_vcs_files', false)); - $files->notPath($this->config->get('hidden_files', [])); + $files->filter(function (SplFileInfo $file) { + return ! $this->hiddenFiles->contains($file->getRealPath()); + }); $files->sortByName(true)->sortByType(); return $this->view->render($response, 'index.twig', [