Skip to content

Commit a053364

Browse files
committed
feat: add r2 convenience config
1 parent e0d986d commit a053364

File tree

2 files changed

+75
-12
lines changed

2 files changed

+75
-12
lines changed
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
<?php
2+
3+
namespace Tempest\Storage\Config;
4+
5+
use League\Flysystem\AwsS3V3\AwsS3V3Adapter;
6+
use League\Flysystem\FilesystemAdapter;
7+
8+
final class R2StorageConfig implements StorageConfig
9+
{
10+
public string $adapter = AwsS3V3Adapter::class;
11+
12+
public function __construct(
13+
/**
14+
* Name of the bucket.
15+
*/
16+
public string $bucket,
17+
18+
/**
19+
* Endpoint to your S3 storage, without the bucket suffix.
20+
*/
21+
public string $endpoint,
22+
23+
/**
24+
* Access key ID, found in the S3 client compatibility section.
25+
*/
26+
public string $accessKeyId,
27+
28+
/**
29+
* Secret access key, found in the S3 client compatibility section.
30+
*/
31+
public string $secretAccessKey,
32+
33+
/**
34+
* If specified, scope operations to that path.
35+
*/
36+
public ?string $prefix = null,
37+
38+
/**
39+
* Whether the storage is read-only.
40+
*/
41+
public bool $readonly = false,
42+
43+
/**
44+
* Other options.
45+
*/
46+
public array $options = [],
47+
) {}
48+
49+
public function createAdapter(): FilesystemAdapter
50+
{
51+
return new S3StorageConfig(
52+
bucket: $this->bucket,
53+
region: 'auto',
54+
endpoint: $this->endpoint,
55+
accessKeyId: $this->accessKeyId,
56+
secretAccessKey: $this->secretAccessKey,
57+
sessionToken: null,
58+
prefix: $this->prefix,
59+
readonly: $this->readonly,
60+
usePathStyleEndpoint: true,
61+
options: $this->options,
62+
)->createAdapter();
63+
}
64+
}

src/Tempest/Storage/src/Config/S3StorageConfig.php

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -21,16 +21,6 @@ public function __construct(
2121
*/
2222
public string $region,
2323

24-
/**
25-
* If specified, scope operations to the that path.
26-
*/
27-
public ?string $prefix = null,
28-
29-
/**
30-
* Whether the storage is read-only.
31-
*/
32-
public bool $readonly = false,
33-
3424
/**
3525
* AWS access key ID. If null, the SDK will attempt to use the default credential provider chain (env vars, config files, IAM role).
3626
*/
@@ -46,6 +36,16 @@ public function __construct(
4636
*/
4737
public ?string $sessionToken = null,
4838

39+
/**
40+
* If specified, scope operations to that path.
41+
*/
42+
public ?string $prefix = null,
43+
44+
/**
45+
* Whether the storage is read-only.
46+
*/
47+
public bool $readonly = false,
48+
4949
/**
5050
* Optional custom endpoint URL (e.g., for S3-compatible storage like R2).
5151
*/
@@ -60,8 +60,7 @@ public function __construct(
6060
* Other options.
6161
*/
6262
public array $options = [],
63-
) {
64-
}
63+
) {}
6564

6665
public function createAdapter(): FilesystemAdapter
6766
{

0 commit comments

Comments
 (0)