codementality / flysystem-streamwrapper
Forked from M2MTech/flysystem-stream-wrapper, a stream wrapper for Flysystem V3.
Package info
github.com/codementality/flysystem-streamwrapper
pkg:composer/codementality/flysystem-streamwrapper
Requires
- php: >=8.4
- league/flysystem: ^2.3|^3.0
- symfony/lock: ^5.3|^6.0|^7.0|^8.0
Requires (Dev)
- ext-intl: *
- ext-pcntl: *
- ext-shmop: *
- ext-sysvmsg: *
- amphp/amp: ^3.1
- amphp/parallel: ^v2.4
- amphp/parallel-functions: ^2.0
- amphp/sync: ^2.3
- fakerphp/faker: ^1.19|^2.0@dev
- phpstan/phpstan: ^2.3
- phpunit/php-invoker: ^5.0|^6.0|^7.0
- phpunit/phpunit: ^11.5 || ^12.0
Suggests
None
Provides
None
Conflicts
None
Replaces
README
This package provides a stream wrapper for Flysystem V3.
This package is a fork and update of m2mtech/flysystem-stream-wrapper
The updates that were made have been recorded in [CHANGELOG.md], and are summarized below:
- Update application for compatibility with PHP 8.4+ (PHP 8.4 and 8.5)
- Update tests for compatibility with PHPUnit 11.5+ (PHPUnit 11.5 and 12.0)
- Refactoring of tests to make them more efficient, and to replace some libraries with some better suited for testing purposes.
- Expanded test coverage (coverage was excellent before, and stands at about 98% currently (excluding trivial Exception classes))
This package is intended to be a drop-in replacement for m2mtech/flysystem-stream-wrapper, and Usage below remains unchanged.
Flysystem V1
If you're looking for Flysystem 1.x support, check out the twistor/flysystem-stream-wrapper.
Installation
composer require m2mtech/flysystem-stream-wrapper
Usage
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');
The stream wrapper implements symfony/lock due to Flysystem V2 not supporting locking. By default, file locking using /tmp is used, but you can adjust this through configuration:
FlysystemStreamWrapper::register('fly', $filesystem, [ FlysystemStreamWrapper::LOCK_STORE => 'flock:///tmp', FlysystemStreamWrapper::LOCK_TTL => 300, ]);
Handling Visibility Issues
Some adaptors might throw exceptions when dealing with visibility. If you encounter such issues, configure the stream wrapper to bypass them:
FlysystemStreamWrapper::register('fly', $filesystem, [ FlysystemStreamWrapper::IGNORE_VISIBILITY_ERRORS => true, ]);
Addressing Directory Issues (file_exists / is_dir)
Some adaptors might not return dates for the last modified attribute for directories. In such cases, you can enable emulation to achieve the desired behavior:
FlysystemStreamWrapper::register('fly', $filesystem, [ FlysystemStreamWrapper::EMULATE_DIRECTORY_LAST_MODIFIED => true, ]);
Dealing with is_readable / is_writable
Some filesystem functions depend on the uid and gid of the user executing PHP. Since a reliable cross-platform method to derive these values isn't available, the wrapper attempts to estimate them. If this fails, set them manually:
FlysystemStreamWrapper::register('fly', $filesystem, [ FlysystemStreamWrapper::UID => 1000, FlysystemStreamWrapper::GID => 1000, ]);
Alternatively, access the parameters for PortableVisibilityConverter directly:
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, ]);
Testing
This package was developed using PHP 8.4 and has been tested for compatibility with PHP versions 8.4 through 8.5.
To test:
- With PHP installed:
composer test
Changelog
For information on recent changes, refer to the CHANGELOG. For historical changes from the original package, refer to CHANGELOG_M2MTECH.
Credits
- Forked from [m2mtech/flysystem-stream-wrapper]. Much appreciation extended to Martin Mandl, for an excellently written application.
- This package was inspired by twistor/flysystem-stream-wrapper. Many thanks to Chris Leppanen.
License
Licensed under the MIT License. See the License File for more details.