-
Notifications
You must be signed in to change notification settings - Fork 554
/
Aws.php
56 lines (39 loc) · 1.33 KB
/
Aws.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
<?php
namespace A17\Twill\Services\Cloud;
use Aws\S3\S3Client;
use Illuminate\Support\Str;
use League\Flysystem\AwsS3V3\AwsS3V3Adapter;
use League\Flysystem\Filesystem;
class Aws
{
public function filesystemFactory($source): Filesystem
{
$config = $this->getConfigFor($source);
$client = new S3Client($config);
$adapter = new AwsS3V3Adapter($client, $config['bucket'], $config['root']);
return new Filesystem($adapter);
}
public function getConfigFor($disk): array
{
return [
'credentials' => [
'key' => $this->config($disk, 'key'),
'secret' => $this->config($disk, 'secret'),
],
'region' => $this->config($disk, 'region'),
'root' => $this->config($disk, 'root', ''),
'bucket' => $this->config($disk, 'bucket'),
'version' => $this->config($disk, 'version', 'latest'),
];
}
public function config($disk, $key, $default = null)
{
$env1 = Str::upper(Str::snake($disk));
$env2 = $env1 === 'AWS' ? 'S3' : 'AWS';
$envSuffix = Str::upper($key);
if (filled($value = config("filesystems.disks.{$disk}.{$key}"))) {
return $value;
}
return env("{$env1}_{$envSuffix}", env("{$env2}_{$envSuffix}", $default));
}
}