php-standard-library/filesystem
Type-safe filesystem helpers for PHP with consistent exception handling. Provides safer wrappers for common file and directory operations, aiming for clearer intent and fewer runtime surprises. Part of the PHP Standard Library ecosystem.
DIRECTORY_SEPARATOR and permission-related bugs.FileNotFoundException) and safe defaults (auto-directory creation), critical for high-stakes operations like cache invalidation or log rotation.FilesystemEvent dispatcher enables reactive architectures (e.g., audit logs, cache invalidation) without coupling to Laravel’s event system, supporting future serverless/Lambda integrations.Storage facade for standalone services (e.g., background workers, API-less utilities), reducing monolith bloat.DIRECTORY_SEPARATOR or environment-specific hacks.file_exists() checks) and need a standardized approach.symfony/filesystem or league/flysystem.Storage facade for all filesystem needs (this package is a complement, not a replacement).flysystem or Laravel’s Storage facade with adapters).*"This package eliminates a major source of technical debt and developer frustration by standardizing filesystem operations across our Laravel ecosystem. Key impacts:
Ask: Approve this as a team-wide standard for new filesystem-heavy projects, with budget for minor onboarding (documentation, internal examples). The payoff is fewer fires, faster iterations, and more reusable code."*
This package replaces 80% of filesystem boilerplate with a type-safe, exception-driven API. Key wins:
DIRECTORY_SEPARATOR hacks. Use:
$path = (new PathResolver())->resolveRelativeToProjectRoot('storage/app/temp');
try {
$content = File::read($path);
} catch (FileNotFoundException $e) {
// Handle gracefully
}
Directory::ensure('/tmp/upload')->create();
$filesystem->on('fileCreated', fn($event) => Log::info('File created:', [$event->getPath()]));
$batch = new BatchProcessor();
$batch->process($files, 20, fn($file) => process($file));
✅ New projects/modules needing filesystem ops. ✅ CLI tools/scripts (e.g., data migrations, log processors). ✅ Queue workers processing files in bulk. ✅ Cross-platform reliability (Windows/Linux/macOS).
❌ Cloud storage (use flysystem or Laravel’s Storage).
❌ Legacy codebases where refactoring isn’t feasible.
❌ High-performance needs (e.g., real-time file streaming).
app/Helpers/PathHelper.php).symfony/event-dispatcher for events.FilesystemEvent dispatcher is opt-in but may conflict with Laravel’s event system. Mitigation:
\App\Listeners\Filesystem\LogFileCreation).$filesystem->on('fileCreated', fn($event) =>
Event::dispatch(new \App\Events\FileCreated($event->getPath()))
);
// Before
foreach (Storage::allFiles('public/uploads') as $file) {
ProcessFileJob::dispatch($file);
}
// After
$batch->process(Storage::allFiles('public/uploads'), 20, fn($file) =>
ProcessFileJob::dispatch($file)
);
// Before
$path = base_path("storage/app/{$id}.txt");
// After
$path = (new PathResolver())->resolveRelativeToProjectRoot("storage/app/{$id}.txt");
FilesystemEvent to specific services (e.g., audit logging).BatchProcessor against manual loops for >10K files.symfony/event-dispatcher to composer.json with an alias to avoid conflicts:
"extra": {
"laravel": {
"alias": {
"symfony/event-dispatcher": "Illuminate/Events"
}
}
}
How can I help you explore Laravel packages today?