symfony/finder
Symfony Finder is a fluent API for locating files and directories. Filter by name, size, date, depth, permissions, and content; include/exclude paths; sort results; and iterate efficiently across local filesystems.
Strengths:
Finder::create()->files()->in($dir)->name('*.log')->sortByModifiedTime() mirrors Laravel’s query builder patterns.symfony/console, symfony/http-client). Reduces context-switching for teams familiar with both ecosystems.Laravel-Specific Synergies:
File::allFiles() loops with fluent queries (e.g., php artisan optimize:media).Storage facade to add advanced filtering (e.g., Storage::finder()->files()->size('>10MB')).filesystem.analyzed) during file traversal for real-time processing pipelines.Potential Gaps:
Storage disk drivers (S3, FTP, etc.).hasMany for file attachments).asset() helper integration).File facade, it doesn’t auto-populate database records or handle soft deletes.Low-Coupling Design:
composer require symfony/finder with no conflicts.Symfony-Laravel Bridge:
Finder::files()) to abstract Symfony’s Finder and add Laravel-specific methods (e.g., url(), storagePath()).Finder as a singleton in AppServiceProvider with Laravel’s container binding:
$this->app->singleton('finder', function () {
return new \Symfony\Component\Finder\Finder();
});
Backward Compatibility:
symfony/console) minimize breaking-change risks.Minimal Risk:
File methods for complex queries (e.g., recursive searches with multiple filters).spatie/laravel-medialibrary).Mitigation Strategies:
Finder to add Laravel-specific functionality (e.g., Storage integration, URL generation).filesystem tests.File facade with symfony/finder for new features, maintaining backward compatibility.File facade entirely, or supplement it for specific workflows (e.g., asset compilation, log analysis)?Finder with Laravel’s Storage interfaces.File::allFiles()?Collection-based file handling (e.g., File::files()->filter())?File facade be deprecated in favor of symfony/finder for consistency, or kept for backward compatibility?filesystem.analyzed) during file traversal?symfony/finder with reactphp/event-loop or symfony/lock.Laravel Core Integration:
File::allFiles() in CLI tools (e.g., php artisan optimize:media) with fluent queries:
$finder = app('finder')->files()->in(storage_path('app/media'))->size('>10MB');
foreach ($finder as $file) { ... }
Finder as a singleton in AppServiceProvider:
$this->app->singleton('finder', function () {
return new \Symfony\Component\Finder\Finder();
});
public function handle($request, Closure $next) {
$files = app('finder')->files()->in(public_path('assets'))->name('*.js');
// Cache or process files...
return $next($request);
}
Third-Party Package Synergy:
spatie/laravel-medialibrary's file-finding logic with Finder for advanced queries (e.g., Finder::create()->files()->mimeType('image/jpeg')).laravel-mix or vite for optimized file watching during development:
$finder = app('finder')->files()->in(resource_path('js'))->name('*.js');
mix->js($finder->getIterator()->current()->getPathname());
meilisearch/laravel-scout-driver) with Finder for dynamic file metadata.Event-Driven Extensions:
$finder = app('finder')->files()->in(storage_path('logs'));
foreach ($finder as $file) {
event(new FileAnalyzed($file));
}
Phase 1: Pilot Integration
FinderService class to wrap Symfony’s Finder and add Laravel-specific methods.File::allFiles() in a single Artisan command (e.g., php artisan logs:clean).File methods.Phase 2: Core Integration
Finder as a Laravel service provider singleton.File::allFiles() in favor of app('finder')->files() in new code.FinderService (e.g., storagePath(), url()).filesystem tests and benchmark against File facade.Phase 3: Full Adoption
File facade usage with symfony/finder.File facade in favor of FinderService (with backward-compatibility aliases).spatie/laravel-medialibrary) to use Finder.filesystem drivers (local, S3, FTP) via wrapper logic.^8.0 for Laravel 10+ or `^7.How can I help you explore Laravel packages today?