diff --git a/.env.example b/.env.example index d9bc415..b66bd4c 100644 --- a/.env.example +++ b/.env.example @@ -1,5 +1,5 @@ # Here you can control Directory Lister configuration through environment -# varaibles. See the configuration documentation for additional information: +# variables. See the configuration documentation for additional information: # https://docs.directorylister.com/configuration APP_DEBUG=false @@ -8,6 +8,7 @@ APP_LANGUAGE=en DISPLAY_READMES=true READMES_FIRST=false ZIP_DOWNLOADS=true +HIDE_DOT_FILES=true GOOGLE_ANALYTICS_ID=false diff --git a/app/config/app.php b/app/config/app.php index 1d411ff..ae594a8 100644 --- a/app/config/app.php +++ b/app/config/app.php @@ -122,7 +122,7 @@ return [ ], /** - * Whether or not to hide application files/directories form the listing. + * Whether or not to hide application files/directories from the listing. * * Default value: true */ @@ -159,4 +159,12 @@ return [ * Default value: 1000000000 */ 'max_hash_size' => DI\env('MAX_HASH_SIZE', 1000000000), + + /** + * Whether or not to hide dot files/directories from the listing. + * Like '.env' or '.ssh/'. + * + * Default value: true + */ + 'hide_dot_files' => DI\env('HIDE_DOT_FILES', true), ]; diff --git a/app/config/container.php b/app/config/container.php index 6cfdee3..b1026b5 100644 --- a/app/config/container.php +++ b/app/config/container.php @@ -17,7 +17,7 @@ return [ 'views_path' => DI\string('{app_path}/views'), /** Array of application files (to be hidden) */ - 'app_files' => ['app', 'index.php', '.hidden'], + 'app_files' => ['app', 'index.php', '.hidden', '.env', '.env.example'], /** Array of application middlewares */ 'middlewares' => function (): array { diff --git a/app/src/Factories/FinderFactory.php b/app/src/Factories/FinderFactory.php index 5a9956d..27c4482 100644 --- a/app/src/Factories/FinderFactory.php +++ b/app/src/Factories/FinderFactory.php @@ -42,6 +42,7 @@ class FinderFactory { $finder = Finder::create()->followLinks(); $finder->ignoreVCS($this->config->get('hide_vcs_files')); + $finder->ignoreDotFiles($this->config->get('hide_dot_files')); if ($this->hiddenFiles->isNotEmpty()) { $finder->filter(function (SplFileInfo $file): bool { diff --git a/tests/Factories/FinderFactoryTest.php b/tests/Factories/FinderFactoryTest.php index 16c3129..891a695 100644 --- a/tests/Factories/FinderFactoryTest.php +++ b/tests/Factories/FinderFactoryTest.php @@ -97,6 +97,46 @@ class FinderFactoryTest extends TestCase ], $this->getFilesArray($finder)); } + public function test_dot_files_are_returned(): void + { + $this->container->set('hidden_files', []); + $this->container->set('hide_dot_files', FALSE); + + $finder = (new FinderFactory( + $this->container, + $this->config, + HiddenFiles::fromConfig($this->config) + ))(); + $finder->in($this->filePath('subdir'))->depth(0); + + $this->assertInstanceOf(Finder::class, $finder); + $this->assertEquals([ + '.dot_dir', + '.dot_file', + 'alpha.scss', + 'bravo.js', + 'charlie.bash', + 'delta.html', + 'echo.yaml', + ], $this->getFilesArray($finder)); + } + + public function test_dot_directory_contents_are_returned(): void + { + $this->container->set('hidden_files', []); + $this->container->set('hide_dot_files', FALSE); + + $finder = (new FinderFactory( + $this->container, + $this->config, + HiddenFiles::fromConfig($this->config) + ))(); + $finder->in($this->filePath('subdir/.dot_dir'))->depth(0); + + $this->assertInstanceOf(Finder::class, $finder); + $this->assertEquals(['.dot_file'], $this->getFilesArray($finder)); + } + public function test_it_throws_a_runtime_exception_with_an_invalid_sort_order(): void { $this->container->set('sort_order', 'invalid'); diff --git a/tests/HiddenFilesTest.php b/tests/HiddenFilesTest.php index fc2bdd5..2e687dc 100644 --- a/tests/HiddenFilesTest.php +++ b/tests/HiddenFilesTest.php @@ -50,11 +50,14 @@ class HiddenFilesTest extends TestCase [], $this->filePath('.hidden'), false, ['alpha', 'bravo'], ], 'App files' => [ - [], 'NOT_A_REAL_FILE', true, ['app', 'index.php', '.hidden'], + [], 'NOT_A_REAL_FILE', true, [ + 'app', 'index.php', '.hidden', '.env', '.env.example', + ], ], 'All' => [ ['foo', 'alpha'], $this->filePath('.hidden'), true, [ - 'foo', 'alpha', 'bravo', 'app', 'index.php', '.hidden', + 'foo', 'alpha', 'bravo', 'app', 'index.php', '.hidden', '.env', + '.env.example', ], ], ];