mirror of
https://github.com/DirectoryLister/DirectoryLister.git
synced 2025-09-01 18:03:29 +02:00
Improvements to hidden file handling
This commit is contained in:
@@ -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', [
|
||||
|
Reference in New Issue
Block a user