|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace BsbFlysystem\Adapter\Factory; |
|
4
|
|
|
|
|
5
|
|
|
use Aws\S3\S3Client; |
|
6
|
|
|
use BsbFlysystem\Exception\RequirementsException; |
|
7
|
|
|
use BsbFlysystem\Exception\UnexpectedValueException; |
|
8
|
|
|
use League\Flysystem\AwsS3v2\AwsS3Adapter as Adapter; |
|
9
|
|
|
use Zend\ServiceManager\ServiceLocatorInterface; |
|
10
|
|
|
|
|
11
|
|
|
class AwsS3AdapterFactory extends AbstractAdapterFactory |
|
12
|
|
|
{ |
|
13
|
|
|
|
|
14
|
|
|
/** |
|
15
|
|
|
* @inheritdoc |
|
16
|
|
|
*/ |
|
17
|
|
|
public function doCreateService(ServiceLocatorInterface $serviceLocator) |
|
18
|
|
|
{ |
|
19
|
|
|
if (!class_exists(\League\Flysystem\AwsS3v2\AwsS3Adapter::class)) { |
|
20
|
|
|
throw new RequirementsException( |
|
21
|
|
|
['league/flysystem-aws-s3-v2'], |
|
22
|
|
|
'AwsS3' |
|
23
|
|
|
); |
|
24
|
|
|
} |
|
25
|
|
|
|
|
26
|
|
|
$client = S3Client::factory([ |
|
|
|
|
|
|
27
|
|
|
'key' => $this->options['key'], |
|
28
|
|
|
'secret' => $this->options['secret'], |
|
29
|
|
|
'region' => $this->options['region'], |
|
30
|
|
|
'request.options' => $this->options['request.options'], |
|
31
|
|
|
]); |
|
32
|
|
|
|
|
33
|
|
|
$adapter = new Adapter($client, $this->options['bucket'], $this->options['prefix']); |
|
34
|
|
|
|
|
35
|
|
|
return $adapter; |
|
36
|
|
|
} |
|
37
|
|
|
|
|
38
|
|
|
/** |
|
39
|
|
|
* @inheritdoc |
|
40
|
|
|
*/ |
|
41
|
5 |
|
protected function validateConfig() |
|
42
|
|
|
{ |
|
43
|
5 |
|
if (!isset($this->options['key'])) { |
|
44
|
1 |
|
throw new UnexpectedValueException("Missing 'key' as option"); |
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
4 |
|
if (!isset($this->options['secret'])) { |
|
48
|
1 |
|
throw new UnexpectedValueException("Missing 'secret' as option"); |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
3 |
|
if (!isset($this->options['region'])) { |
|
52
|
1 |
|
throw new UnexpectedValueException("Missing 'region' as option"); |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
2 |
|
if (!isset($this->options['bucket'])) { |
|
56
|
1 |
|
throw new UnexpectedValueException("Missing 'bucket' as option"); |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
1 |
|
if (!isset($this->options['prefix'])) { |
|
60
|
1 |
|
$this->options['prefix'] = null; |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
1 |
|
if (!isset($this->options['request.options'])) { |
|
64
|
1 |
|
$this->options['request.options'] = []; |
|
65
|
|
|
} |
|
66
|
1 |
|
} |
|
67
|
|
|
} |
|
68
|
|
|
|
This method has been deprecated.