This package provides a stream wrapper for Flysystem V2 & V3.
If you're looking for Flysystem 1.x support, check out the twistor/flysystem-stream-wrapper.
composer require m2mtech/flysystem-stream-wrapper
use League\Flysystem\Filesystem;
use League\Flysystem\Local\LocalFilesystemAdapter;
use M2MTech\FlysystemStreamWrapper\FlysystemStreamWrapper;
$filesystem = new Filesystem(new LocalFilesystemAdapter('/some/path'));
FlysystemStreamWrapper::register('fly', $filesystem);
file_put_contents('fly://filename.txt', $content);
mkdir('fly://happy_thoughts');
FlysystemStreamWrapper::unregister('fly');
Because locking is not supported by Flysystem V2, the stream wrapper implements symfony/lock
. As default, it uses file locking using /tmp
, which you can adjust via the configuration:
FlysystemStreamWrapper::register('fly', $filesystem, [
FlysystemStreamWrapper::LOCK_STORE => 'flock:///tmp',
FlysystemStreamWrapper::LOCK_TTL => 300,
]);
Some adaptors seem to throw an exception when visibility is used. To be able to use such adaptors, tell the stream wrapper to ignore them, e.g.:
FlysystemStreamWrapper::register('fly', $filesystem, [
FlysystemStreamWrapper::IGNORE_VISIBILITY_ERRORS => true,
]);
A couple of filesystem functions use uid
and gid
of the user running php. Unfortunately there is no straight forward cross-plattform usable method available to derive those values. The wrapper tries to guess them. But depending on your system settings it might fail.
In such cases you can set them manually, e.g.:
FlysystemStreamWrapper::register('fly', $filesystem, [
FlysystemStreamWrapper::UID => 1000,
FlysystemStreamWrapper::GID => 1000,
]);
or go haywire accessing the parameters for PortableVisibilityConverter
directly via:
FlysystemStreamWrapper::register('fly', $filesystem, [
FlysystemStreamWrapper::VISIBILITY_FILE_PUBLIC => 0644,
FlysystemStreamWrapper::VISIBILITY_FILE_PRIVATE => 0600,
FlysystemStreamWrapper::VISIBILITY_DIRECTORY_PUBLIC => 0755,
FlysystemStreamWrapper::VISIBILITY_DIRECTORY_PRIVATE => 0700,
FlysystemStreamWrapper::VISIBILITY_DEFAULT_FOR_DIRECTORIES => Visibility::PRIVATE,
]);
This package has been developed for php 7.4 with compatibility tested for php 7.2 to 8.2.
# with php installed
composer test
# or inside docker e.g. for php 7.4
docker-compose run php74 composer test
# note that phpunit v10 used stating php 8.1 will require to use a different config file:
docker-compose run php81 vendor/bin/phpunit -c phpunit.10.xml
Please see CHANGELOG for more information about recent changes.
Please see CONTRIBUTING for details.
Please review our security policy on how to report security vulnerabilities.
- This package is based on [twistor/flysystem-stream-wrapper]. Kudos and thanks to Chris Leppanen.
- All Contributors
The MIT License (MIT). Please see License File for more information.