Skip to content

Commit

Permalink
Implement the new file finder method
Browse files Browse the repository at this point in the history
  • Loading branch information
caendesilva committed Dec 13, 2024
1 parent 57c8b9e commit 3bc3b7c
Showing 1 changed file with 28 additions and 1 deletion.
29 changes: 28 additions & 1 deletion packages/framework/src/Foundation/Kernel/Filesystem.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use Hyde\Foundation\HydeKernel;
use Hyde\Foundation\PharSupport;
use Illuminate\Support\Collection;
use Symfony\Component\Finder\Finder;

use function collect;
use function Hyde\normalize_slashes;
Expand Down Expand Up @@ -187,6 +188,32 @@ public function smartGlob(string $pattern, int $flags = 0): Collection
/** @return \Illuminate\Support\Collection<int, string> */
public function findFiles(string $directory, string|false $matchExtension = false, bool $recursive = false): Collection
{
// Todo: Implement this method
// Resolve the full directory path based on the project root
$directory = $this->path($directory);

// Create a Symfony Finder instance
$finder = new Finder();

// Configure Finder to look in the directory
$finder->files()->in($directory);

// Configure Finder for recursive or non-recursive search
if (! $recursive) {
$finder->depth('== 0');
}

// Optionally match file extensions
if ($matchExtension !== false) {
$finder->name('*.'.$matchExtension);
}

// Collect relative paths
$files = collect();

foreach ($finder as $file) {
$files->push(str_replace($directory . DIRECTORY_SEPARATOR, '', $file->getRealPath()));
}

return $files;
}
}

0 comments on commit 3bc3b7c

Please sign in to comment.