symfony/filesystem
Symfony Filesystem component offers convenient, robust filesystem utilities for PHP: create, copy, move, remove, chmod, and mirror files/directories, with error handling and cross-platform support. Ideal for safe file operations in Symfony and beyond.
bug #64179), directly addressing a long-standing limitation in Laravel deployments where copied files lose permissions (e.g., chmod attributes) on Windows/Linux. This is particularly valuable for:
Storage facade when copying files between local/disk drivers.storage:link, cache:clear) where permission mismatches cause silent failures..env, config/).artisan, composer.phar).copy() logic (e.g., file_put_contents + chmod), replacing it with a batteries-included solution.Filesystem helpers (e.g., copyDirectory()).CopyFilesystem (if used for cross-platform operations).Filesystem methods are renamed in v9.x).laravel/framework).Storage facade, Flysystem) to ensure consistent permission handling?chmod attributes post-copy on Windows/Linux)?stat() checks in PHPUnit) to automate permission validation?Filesystem helpers do not duplicate this logic?Filesystem and future-proof against API changes?Filesystem helpers (reducing dependency on Symfony)?laravel-permission) that already handle file modes and could replace this?Storage facade, Flysystem, and custom file operations where permissions matter (e.g., artisan, backups).Console or HttpKernel, this package reinforces consistency.Storage::copy(), file_copy(), Flysystem).artisan commands, deployments).storage:link).
use Symfony\Component\Filesystem\Filesystem;
$fs = new Filesystem();
$fs->copy('/source/file.txt', '/destination/file.txt'); // Preserves mode!
copy() helpers with Symfony’s Filesystem.stat() mode matches post-copy (e.g., 0755 for executables).Filesystem for mode-preserving copies.Storage Facade: Can extend with a custom macro:
Storage::macro('copyWithMode', function ($source, $destination) {
$fs = new Filesystem();
$fs->copy($source, $destination);
});
How can I help you explore Laravel packages today?