Download the PHP package brianhenryie/bh-php-flysystem-readonly without Composer
On this page you can find all versions of the php package brianhenryie/bh-php-flysystem-readonly. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download brianhenryie/bh-php-flysystem-readonly
More information about brianhenryie/bh-php-flysystem-readonly
Files in brianhenryie/bh-php-flysystem-readonly
Package bh-php-flysystem-readonly
Short Description A League Flysystem adapter which wraps another adapter: reads pass through, writes and deletes are captured in memory so nothing ever touches the underlying filesystem. For --dry-run modes.
License MIT
Informations about the package bh-php-flysystem-readonly
Flysystem Read-Only Adapter
A League Flysystem adapter which wraps another adapter: reads pass through to it, writes and deletes are captured in memory. The underlying filesystem is never modified, but code running on top of it sees its own changes as though they had been written. Uses league/flysystem-memory to store changes.
Created to use for --dry-run mode needs: the whole program runs normally – writing files, deleting them, listing directories, reading back what it just wrote – and nothing reaches the disk. This was extracted from Strauss, where it implements
strauss --dry-run.
Install
Use
How it works
Three layers are consulted, in order:
| Layer | Contents |
|---|---|
| deleted files | tombstones written by delete(); directory tombstones recorded by deleteDirectory() |
| modified files | everything written during this session, in an in-memory adapter |
| delegate | the real filesystem, read-only |
So read() throws if the path was deleted, returns the in-memory copy if it was written, and otherwise
reads from the delegate. listContents() merges the delegate's listing with the in-memory one, removing
deleted paths and preferring the in-memory version of any path present in both.
Mutating operations only ever touch the in-memory layers. setVisibility() on a file which exists only on
the delegate filesystem first copies that file into memory – so the whole file is read into memory, as it
also is for copy() and move().
Path normalization
A PathNormalizer may be injected; it defaults to League's WhitespacePathNormalizer (which, among other
things, strips the leading / so paths match those returned by the adapters' directory listings).
The normalizer is applied by this adapter and again by the in-memory layers it delegates to, so an
injected normalizer must be idempotent: normalize(normalize($path)) === normalize($path).
Flysystem 2 and 3
league/flysystem 3 added directoryExists() to FilesystemAdapter and FilesystemReader, and has() to
FilesystemReader. Two traits back-fill them, calling the genuine parent implementation when it exists:
FlysystemAdapterBackCompatTrait– for yourFilesystemAdapterimplementationsFlysystemReaderBackCompatTrait– for yourFilesystemReader/Filesystemimplementations
These require the class using the trait to implement ::normalizePath().
| PHP | Flysystem 2 | Flysystem 3 |
|---|---|---|
| 7.4 | ✅ | – (requires PHP 8.0.2) |
| 8.0 – 8.4 | ✅ | ✅ |
Known limitations
deleteDirectory()records the directory as deleted, but files inside it which exist only on the delegate filesystem are not individually tombstoned, so they remain readable by their full path. Writing a file into a deleted directory, or creating it again, restores it.- Files are held in memory in full. This is a dry-run tool, not a caching layer.
visibility()of a directory defaults topublicunless a visibility was set on it during the session.mimeType()of an in-memory file is detected from the path and contents byleague/mime-type-detection, which may disagree with what the delegate filesystem would report.
Tests
Credits
Handwritten by Brian Henry for Strauss then extracted by Claude.
All versions of bh-php-flysystem-readonly with dependencies
ext-fileinfo Version *
league/flysystem Version ^2.5 || ^3.0
league/flysystem-memory Version ^2.0 || ^3.0