Improvements to hidden file handling

This commit is contained in:
Chris Kankiewicz
2019-12-06 00:15:52 -07:00
parent 5d3eb78dea
commit 58e6489bba

View File

@@ -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', [