From ba90b51025a65109b5e1e35e228840ed1885224f Mon Sep 17 00:00:00 2001 From: Chris Kankiewicz Date: Mon, 20 Apr 2020 20:38:05 -0700 Subject: [PATCH] Fixed all files being hidden when no hidden files are defined (oops!) --- app/src/Factories/FinderFactory.php | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/app/src/Factories/FinderFactory.php b/app/src/Factories/FinderFactory.php index aa1d7c3..8099837 100644 --- a/app/src/Factories/FinderFactory.php +++ b/app/src/Factories/FinderFactory.php @@ -48,9 +48,14 @@ class FinderFactory { $finder = Finder::create()->followLinks(); $finder->ignoreVCS($this->container->get('hide_vcs_files')); - $finder->filter(function (SplFileInfo $file): bool { - return (bool) ! preg_match($this->hiddenPattern(), $file->getRealPath()); - }); + + if ($this->hiddenFiles()->isNotEmpty()) { + $finder->filter(function (SplFileInfo $file): bool { + return (bool) ! preg_match(Glob::toRegex( + sprintf('%s/{%s}', $this->container->get('base_path'), $this->hiddenFiles()->implode(',')) + ), $file->getRealPath()); + }); + } $sortOrder = $this->container->get('sort_order'); if ($sortOrder instanceof Closure) { @@ -71,20 +76,16 @@ class FinderFactory } /** - * Get the regular expression patern for hidden files. + * Get a collection of hidden file paths. * - * @return string + * @return \Illuminate\Support\Collection */ - protected function hiddenPattern(): string + protected function hiddenFiles(): Collection { - $collection = Collection::make( + return Collection::make( $this->container->get('hidden_files') )->when($this->container->get('hide_app_files'), static function (Collection $collection) { return $collection->merge(self::APP_FILES); })->unique(); - - return Glob::toRegex( - sprintf('%s/{%s}', $this->container->get('base_path'), $collection->implode(',')) - ); } }