| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Name | Name | Last commit date | ||
|---|---|---|---|---|
The package to manage files on the local storage.
It is the implementation behind quillstack/storage-interface, and its whole job is to make an interface out of four PHP functions so that everything above it can be tested without a disk.
The cache, the logger and dotenv all read and write through that interface. In a test they are handed something that keeps files in an array; in production they are handed this. Neither knows the difference, and neither calls file_put_contents itself.
Nothing here does anything clever. Reading it should take a minute and finding a bug in it should be hard, which is the point of a package this small.
To install this package, run the standard command using Composer:
composer require quillstack/local-storage
Create a class or inject it as a dependency:
use Quillstack\LocalStorage\LocalStorage;
$storage = new LocalStorage();
$storage->save('var/cache/token.txt', 'muHaloosPps23sKkdsaaBBcei');If you want to use it as a dependency:
use Quillstack\LocalStorage\LocalStorage;
public function __construct(private LocalStorage $storage)
{
//
}
public function getTokenFromCache()
{
$this->storage->get('var/cache/token.txt');
}This package implements quillstack/storage-interface:
https://github.com/quillstack/storage-interface
with methods:
Measured with quillstack/benchmark on a thousand write-and-read pairs of a small file. Runs are interleaved and unconcurrent, each figure is the median of five, and PHP is 8.5.7.
| Version | |
|---|---|
| quillstack/local-storage | 0.6.0 |
| league/flysystem | 3.35.3 |
| Per write and read | Relative | |
|---|---|---|
| quillstack/local-storage | 83.6 µs | — |
| league/flysystem | 85.7 µs | 1.02× |
These are the same number. Both call the same kernel, and two per cent between them is the filesystem rather than either library. A benchmark of two thin wrappers over file_put_contents was never going to say anything else, and it is here because the alternative is leaving a reader to wonder.
The difference is what they reach. league/flysystem writes to S3, FTP, SFTP, Azure, Google Cloud, in-memory and a dozen more, with stream support, visibility, MIME detection and directory listings. This writes to the disk it is running on. Where you need one of those, use Flysystem — and where you need a StorageInterface implementation that does not bring an ecosystem with it, that is what this is.
Run tests using a command:
phpdbg -qrr ./vendor/bin/unit-tests
This is one component of Quillstack, a PHP framework which is as simple to use as it is strict about what it does.
MIT — see LICENSE.
| Back | FazBrowse Home | New Git URL |