innmind / s3
4.1.2
2024-06-17 12:46 UTC
Requires
- php: ~8.2
- innmind/filesystem: ~7.5
- innmind/hash: ^1.1
- innmind/http: ~7.0
- innmind/http-transport: ~7.0
- innmind/immutable: ~4.15|~5.0
- innmind/operating-system: ~4.0|~5.0
- innmind/time-continuum: ~3.1
- innmind/url: ~4.1
- innmind/xml: ^7.2
Requires (Dev)
- innmind/black-box: ~5.5
- innmind/coding-standard: ~2.0
- symfony/dotenv: ^7.0
- symfony/filesystem: ~6.2
- symfony/process: ~6.2
- vimeo/psalm: ~5.15
This package is auto-updated.
Last update: 2024-09-17 13:24:35 UTC
README
对任何S3桶进行操作的极简抽象。
安装
composer require innmind/s3
使用
use Innmind\S3\{ Factory, Region, }; use Innmind\OperatingSystem\Factory as OSFactory; use Innmind\Filesystem\File\Content; use Innmind\Url\{ Url, Path, }; $os = OSFactory::build(); $bucket = Factory::of($os)->build( Url::of('https://acces_key:acces_secret@bucket-name.s3.region-name.scw.cloud/'), Region::of('region-name'), ); $file = $bucket->get(Path::of('some-file.txt'))->match( static fn(Content $file) => $file, static fn() => throw new \RuntimeException('File does not exist'), ); $bucket->upload(Path::of('some-other-name.txt'), $file)->match( // essentially this will copy the file static fn() => null, // everything ok static fn() => throw new \RuntimeException('Failed to upload file'), );
为了简化某些使用,您可以在桶接口之上使用文件系统适配器。以下是一个将目录上传到桶的示例:
use Innmind\S3\Filesystem; use Innmind\Filesystem\Name; $data = $os->filsystem()->mount(Path::of('/var/data')); $s3 = Filesystem\Adapter::of($bucket); $data ->get(Name::of('images')) ->match( $s3->add(...), static fn() => null, // do something if there is no images );
警告
一个桶可以包含具有相同名称的文件和目录。这不支持innmind/filesystem
适配器。这意味着,如果在包含具有相同名称的文件和目录的桶上使用Innmind\S3\Filesystem\Adapter
,可能会导致意外的行为或异常。