symfony/finder
Symfony Finder provides a fluent API to locate files and directories. Filter by name, path, size, dates, contents, and more; traverse recursively and iterate results easily—ideal for CLI tools, installers, and build scripts.
Strengths:
files(), in(), name(), size(), etc.) align with Laravel’s idiomatic style.symfony/console for Artisan, symfony/http-client), this package integrates seamlessly, reducing friction in hybrid stacks.IteratorAggregate), critical for Laravel applications handling media, logs, or backups.DateComparator, SizeComparator) and iterators, enabling domain-specific extensions (e.g., MIME-type filtering, Laravel-specific metadata).Weaknesses:
Storage facade (e.g., S3, FTP), requiring wrapper logic for cloud storage use cases.->getIterator()->count()) can consume significant memory for millions of files. Laravel’s queue system could mitigate this but isn’t native.Laravel Compatibility:
// app/Providers/AppServiceProvider.php
public function register()
{
$this->app->singleton('finder', function () {
return new \Symfony\Component\Finder\Finder();
});
}
php artisan optimize:assets using Finder to locate unoptimized files).Potential Conflicts:
Symfony\Component\Finder.laravel/framework depends on Symfony components).\InvalidArgumentException for invalid paths), unlike some Laravel helpers./storage/app/public with millions of files) may require tuning (e.g., ->depth(0) to limit depth).glob() + manual filtering) or augment Laravel’s Storage facade for cloud files?FilesystemManager, Vite, or Laravel Forge)?spatie/laravel-medialibrary) that could conflict?Mockery, Laravel’s filesystem testing)?FileFinderService) for easier future swaps?php artisan media:optimize).@daily log cleanup).Finder::files()->in('path')) to mimic Laravel’s Storage facade.Iterator and Comparator interfaces, enabling reuse of other Symfony components (e.g., symfony/process for file operations).spatie/laravel-activitylog, laravel/sanctum).Storage facade) will require custom logic.glob(), DirectoryIterator, custom scripts) for replacement candidates.glob() calls with Finder’s fluent API in new features.
// Before
$files = glob(storage_path('app/public/*.jpg'));
// After
$finder = Finder::create()->files()->in(storage_path('app/public'))->name('*.jpg');
app/Services/FileFinder.php) to abstract Finder and add Laravel features (e.g., generateUrl() for found files).Laravel\Filesystem\Filesystem::fake()).laravel/framework, spatie/laravel-package-tools).fileinfo for MIME types is optional).Storage facade:
$finder = Finder::create()->in(storage_path('app/local'));
$storage = Storage::disk('s3');
foreach ($finder as $file) {
$storage->put("s3/path/{$file->getFilename()}", file_get_contents($file));
}
composer.json and publish a facade/service provider.glob()/DirectoryIterator usage in new features.FileFinder service to encapsulate Finder logic and add Laravel integrations (e.g., URL generation).How can I help you explore Laravel packages today?