innmind / filesystem
Filesystem abstraction layer
Requires
- php: ~8.1
- innmind/immutable: ~4.0
- innmind/media-type: ~2.0
- innmind/stream: ~3.0
- innmind/url: ~4.0
- psr/log: ~3.0
- symfony/filesystem: ~6.0
Requires (Dev)
- innmind/black-box: ^4.17
- innmind/coding-standard: ~2.0
- phpunit/phpunit: ~9.0
- vimeo/psalm: ~4.9
Suggests
- innmind/black-box: For property based testing
Provides
- innmind/black-box-sets: 4.7.0
Conflicts
- innmind/black-box: <4.7|~5.0
This package is auto-updated.
Last update: 2022-07-22 15:25:14 UTC
README
Filesystem abstraction layer, the goal is to provide a model where you design how you put your files into directories without worrying where it will be persisted.
Installation
composer install innmind/filesystem
Usage
The whole model is structured around files, directories, contents and adapters. File
, Directory
and Content
are immutable objects.
Example:
use Innmind\Filesystem\{ File\File, File\Content, Directory\Directory, Adapter\Filesystem, }; use Innmind\Url\Path; $directory = Directory::named('uploads')->add( File::named( $_FILES['my_upload']['name'], Content\AtPath::of(Path::of($_FILES['my_upload']['tmp_name'])), ), ); $adapter = Filesystem::mount(Path::of('/var/www/web/')); $adapter->add($directory);
This example show you how you can create a new directory uploads
in the folder /var/www/web/
of your filesystem and create the uploaded file into it.
Note: For performance reasons the filesystem adapter only persist to disk the files that have changed (achievable via the immutable nature of file objects).
All adapters implements Adapter
, so you can easily replace them; especially for unit tests, that's why the library comes with an InMemory
adapter that only keeps the files into memory so you won't mess up your file system.