innmind / filesystem
文件系统抽象层
7.5.1
2024-03-27 15:14 UTC
Requires
- php: ~8.2
- innmind/immutable: ~4.15|~5.0
- innmind/io: ~2.2
- innmind/media-type: ~2.1
- innmind/stream: ~4.1
- innmind/time-continuum: ~3.4
- innmind/url: ~4.2
- psr/log: ~3.0
- symfony/filesystem: ~6.0|~7.0
Requires (Dev)
- innmind/black-box: ^5.5.1
- innmind/coding-standard: ~2.0
- phpunit/phpunit: ~10.2
- ramsey/uuid: ^4.6
- vimeo/psalm: ~5.13
Suggests
- innmind/black-box: For property based testing
Provides
Conflicts
- innmind/black-box: <5.0|~6.0
- dev-develop
- 7.5.1
- 7.5.0
- 7.4.0
- 7.3.0
- 7.2.0
- 7.1.0
- 7.0.0
- 6.6.0
- 6.5.1
- 6.5.0
- 6.4.0
- 6.3.2
- 6.3.1
- 6.3.0
- 6.2.0
- 6.1.0
- 6.0.0
- 5.2.0
- 5.1.0
- 5.0.0
- 4.2.2
- 4.2.1
- 4.2.0
- 4.1.0
- 4.0.7
- 4.0.6
- 4.0.5
- 4.0.4
- 4.0.3
- 4.0.2
- 4.0.1
- 4.0.0
- 3.4.0
- 3.3.1
- 3.3.0
- 3.2.0
- 3.1.0
- 3.0.1
- 3.0.0
- 2.2.0
- 2.1.1
- 2.1.0
- 2.0.0
- 1.5.1
- 1.5.0
- 1.4.0
- 1.3.0
- 1.2.0
- 1.1.2
- 1.1.1
- 1.1.0
- 1.0.0
- dev-master
- dev-close-once-read
This package is auto-updated.
Last update: 2024-09-21 12:06:57 UTC
README
文件系统抽象层的目标是提供一个模型,在该模型中,你可以设计如何将文件放入目录,而无需担心它们将持久化到何处。
安装
composer install innmind/filesystem
使用
整个模型围绕文件、目录、内容和适配器构建。 File
, Directory
和 Content
是不可变对象。
示例
use Innmind\Filesystem\{ File, File\Content, Directory, Adapter\Filesystem, }; use Innmind\Url\Path; $directory = Directory::named('uploads')->add( File::named( $_FILES['my_upload']['name'], Content::ofString(\file_get_contents($_FILES['my_upload']['tmp_name'])), ), ); $adapter = Filesystem::mount(Path::of('/var/www/web/')); $adapter->add($directory);
以下示例展示了如何在文件系统中创建一个名为 uploads
的新目录,并将其放置在 /var/www/web/
文件夹中,并创建一个上传的文件。
注意:出于性能考虑,文件系统适配器仅将已更改的文件持久化到磁盘(通过文件对象的不可变性质实现)。
所有适配器都实现了 Adapter
,因此您可以轻松地替换它们;特别是对于单元测试,这就是为什么该库附带了一个 InMemory
适配器,它仅在内存中保留文件,这样您就不会弄乱文件系统。