Pulled hidden file logic out of the app config and into application code

This commit is contained in:
Chris Kankiewicz
2020-05-01 11:37:37 -07:00
parent 9e80d6a016
commit 411de8c104
2 changed files with 14 additions and 19 deletions

View File

@@ -76,32 +76,23 @@ return [
'reverse_sort' => Helpers::env('REVERSE_SORT', false),
/**
* File used by 'hidden_files' to define the list of hidden files.
* File containing hidden file definitions. Will be merged with definitions
* from the 'hidden_files' configuration option.
*
* Default value: '.hidden'
*/
'hidden_files_list' => Helpers::env('HIDDEN_FILES_LIST', '.hidden'),
/**
* Array of files that will be hidden from the listing. Supports glob
* patterns (e.g. *.txt, file.ya?ml, etc.).
* Array of hidden file definitions. Will be merged with definitions in the
* file definned in the 'hidden_files_list' configuration option. Supports
* glob patterns (e.g. *.txt, file.{yml,yaml}, etc.).
*
* By defualt this will look for a '.hidden' file in the app root directory.
* If found, each line of this file will be used as an ignore pattern.
*
* Default value: Array loaded from '.hidden' file if present, otherwise
* an empty array ([])
* Default value: []
*/
'hidden_files' => static function (ContainerInterface $container): array {
if (! is_readable($container->get('hidden_files_list'))) {
return [];
}
return file(
$container->get('hidden_files_list'),
FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES
);
},
'hidden_files' => [
// ...
],
/**
* Whether or not to hide application files/directories form the listing.

View File

@@ -84,7 +84,11 @@ class FinderFactory
{
return Collection::make(
$this->container->get('hidden_files')
)->when($this->container->get('hide_app_files'), static function (Collection $collection) {
)->when(is_readable($this->container->get('hidden_files_list')), function (Collection $collection) {
return $collection->merge(
file($this->container->get('hidden_files_list'), FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES)
);
})->when($this->container->get('hide_app_files'), static function (Collection $collection) {
return $collection->merge(self::APP_FILES);
})->unique();
}