neutron/temporary-filesystem
TemporaryFilesystem provides a simple PHP API to create temporary directories and files using Symfony’s Filesystem component. Generate single or multiple empty temp files with custom prefixes, suffixes, and extensions—handy for concurrent processes and libraries relying on file extensions.
Filesystem component, which is a well-established, dependency-injection-friendly library. This aligns well with Laravel’s ecosystem, as Symfony components are widely used and supported in Laravel via packages like symfony/filesystem (v6.x).sys_get_temp_dir(), tmpfile(), or manual cleanup). Fits use cases like:
Storage facade (e.g., Storage::disk('local')->put()) handles persistent files, but this package excels for ephemeral needs. Could complement Laravel’s Filesystem or TemporaryUploadedFile (for HTTP uploads).symfony/filesystem (≥5.0, ≤6.x). Laravel already includes this via illuminate/filesystem (Symfony v5), so no new dependencies are needed if using Laravel ≥8.x.Mockery or Laravel’s Storage mocks).Storage::fake() (for testing).League\Flysystem (for cloud storage + temp files).tmpfile() or sys_get_temp_dir().Storage::disk('local') + tmpfile()?createTemporaryFiles(20))./mnt/ssd/tmp)?__destruct() or cleanup hooks.)illuminate/filesystem), so no new dependencies are added.TemporaryFilesystem as a singleton or context-bound service.TempFilesystem::create()) for consistency.Storage::fake() alternative).require-dev dependency.tmpfile(), Storage::fake()).// app/Providers/AppServiceProvider.php
public function register()
{
$this->app->singleton(TemporaryFilesystem::class, function () {
return TemporaryFilesystem::create();
});
}
// app/Facades/TempFilesystem.php
public static function createTemporaryFiles(int $count, ?string $prefix = null): array
{
return app(TemporaryFilesystem::class)->createTemporaryFiles($count, $prefix);
}
registerShutdownFunction).tmpfile() if the package fails.Filesystem::createTemporaryFile()./tmp, sys_get_temp_dir()).chmod adjustments (e.g., 0755 mode).event:terminating listener).monolog channel).StorageException).register_shutdown_function or a Laravel event listener).symfony/filesystem as a direct dependency (though Laravel already includes it)./tmp/phpXYZ123).mkdir() permissions).tmpfile() or Storage::fake() if the package becomes unmaintainable.fopen('php://temp')./mnt/ssd/tmp) with auto-cleanup cron jobs.createTemporaryFiles(100) max).| Failure Scenario | Impact | Mitigation |
|---|---|---|
| Temp dir full/permission denied | Silent failures, broken workflows | Fallback to sys_get_temp_dir() + retries |
| Process crash | Orphaned temp files | Shutdown hook or Laravel terminating event |
| Package incompatibility | Breaks on PHP/Symfony updates | Fork or replace with native methods |
| Security vulnerability | Temp files exposed to attackers | Use secure_tmpfile() or chmod 600 |
createTemporaryFile()).tmpfile(), this package requires manual deletionHow can I help you explore Laravel packages today?