From 411de8c104443e78ed6a157465aa800a18563ed5 Mon Sep 17 00:00:00 2001 From: Chris Kankiewicz Date: Fri, 1 May 2020 11:37:37 -0700 Subject: [PATCH] Pulled hidden file logic out of the app config and into application code --- app/config/app.php | 27 +++++++++------------------ app/src/Factories/FinderFactory.php | 6 +++++- 2 files changed, 14 insertions(+), 19 deletions(-) diff --git a/app/config/app.php b/app/config/app.php index c319c21..5f7d122 100644 --- a/app/config/app.php +++ b/app/config/app.php @@ -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. diff --git a/app/src/Factories/FinderFactory.php b/app/src/Factories/FinderFactory.php index 2b6d14d..ef32876 100644 --- a/app/src/Factories/FinderFactory.php +++ b/app/src/Factories/FinderFactory.php @@ -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(); }