symfony/filesystem
Symfony Filesystem provides basic utilities for working with files and directories: creating, copying, moving, and removing files, dumping content safely, making paths relative, and normalizing paths. It's a lightweight, standalone component usable in any PHP project.
symfony/console, symfony/finder), reducing friction for teams already using Symfony packages.atomicWrite()), critical for CLI/Artisan commands (e.g., backups, media processing) where partial writes could corrupt data.isAbsolute() logic, backslash handling in v8.0.9) that plague Laravel apps deploying on Azure/AWS Windows instances.tempnam() files are now kept private when a suffix is supplied (bug #65745) and source file mode is preserved on copy (bug #65726). These tighten the security posture of temp-file and mirror operations common in Artisan commands.Key Synergies with Laravel:
Storage facade for low-level filesystem tasks (e.g., recursive directory operations, temp file cleanup).artisan deploy:storage).str_replace('\\', '/', $path)). Example:
use Symfony\Component\Filesystem\Filesystem;
use Symfony\Component\Filesystem\Path;
$fs = new Filesystem();
$fs->mirror('/source', '/destination'); // Cross-platform copy
Path::isAbsolute('/tmp/file.txt'); // Fixed Windows/Linux logic
AppServiceProvider:
public function register()
{
$this->app->singleton(Filesystem::class, fn() => new Filesystem());
}
public function __construct(private Filesystem $filesystem) {}
Artisan::command() to use the component for CLI operations:
$this->filesystem->remove($this->laravel->storagePath('logs/old'));
Compatibility:
| Risk Area | Severity | Mitigation |
|---|---|---|
| PHP Version Lock | High | Requires PHP 8.4+ (Laravel 10+). Downgrade to Symfony 7.x for PHP 8.2. |
| Security Patch Lag | High | SECURITY release (v5.4.54): audit all pinned symfony/filesystem constraints and bump immediately; temp-file permission and copy-mode fixes affect deployments handling secrets. |
| Windows-Specific Bugs | Medium | Test on Windows Server 2022 + WSL2 to validate fixes (e.g., v8.0.9). |
| File-Mode Preservation | Medium | After upgrade, verify mirrored/copied assets retain expected permissions; the new mode-preserving behavior can surface previously-masked ACL assumptions. |
| Symfony Dependency Bloat | Low | Component is lightweight (~1MB). No runtime conflicts with Laravel. |
| Atomic Write Race Conditions | Medium | Use atomicWrite() for critical files (e.g., config, cache). |
| Path Injection Vulnerabilities | Medium | Validate paths before passing to the component (e.g., Path::makeAbsolute()). |
Critical Questions for TPM:
symfony/filesystem to <5.4.54, and what is the SLA for applying the SECURITY release?artisan backup:run) where partial writes occur?Security Impact:
tempnam() with a suffix or mirror()/copy() semantics where a temp file world-readable or mode-loss bug is currently exploitable?"composer.lock?"Business Impact:
Technical Debt:
Alternatives:
file_put_contents() with Filesystem::atomicWrite().storage_path('app')).Symfony\Component\Console commands with filesystem utilities.symfony/console, symfony/finder).file_exists(), mkdir()) can still be used, ensuring gradual adoption.Example Use Cases:
| Laravel Feature | Symfony Filesystem Integration |
|---|---|
| Artisan Commands | Replace File::copy() with Filesystem::mirror() for recursive directory syncs. |
| Media Processing | Use Filesystem::atomicWrite() for safe image uploads (avoid partial writes). |
| Deployment Scripts | Standardize paths in artisan deploy:storage with Path::makeAbsolute(). |
| Backup Utilities | Use Filesystem::remove() for cross-platform temp file cleanup. |
| CLI Tools | Integrate with Symfony\Component\Console for interactive filesystem operations. |
composer.lock and composer.json for symfony/filesystem pins; identify any <5.4.54 in the 5.4 LTS track and <8.1.x on the current track.composer update symfony/filesystem. Treat as a hotfix if temp-file or copy operations touch secrets.str_replace(), regex).file_put_contents(), File::copy()).mkdir(), file_exists()).artisan backup:run) or one service (e.g., media uploads).Symfony\Component\Filesystem\Path.isAbsolute() on Windows, backslash handling).Filesystem as a Laravel singleton in AppServiceProvider:$this->app->singleton(Filesystem::class, fn() => new Filesystem());
symfony/filesystem before enabling atomic-write and mirror paths broadly.composer constraints must reflect both to avoid drift.composer.lock across fleets.file_exists()/mkdir() show no material cost for typical Laravel workloads.tempnam() behavior (#65745) may break tests or tooling that assumed world-readable temp files.isAbsolute() bugs remain a latent failure source.composer constraints.How can I help you explore Laravel packages today?