AwsS3FsComponent   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 83
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 0
Metric Value
wmc 6
lcom 1
cbo 4
dl 0
loc 83
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A init() 0 20 5
A initAdapter() 0 20 1
1
<?php
2
/**
3
 * This file is part of the 2amigos/yii2-flysystem-component project.
4
 *
5
 * (c) 2amigOS! <http://2amigos.us/>
6
 *
7
 * For the full copyright and license information, please view
8
 * the LICENSE file that was distributed with this source code.
9
 */
10
namespace dosamigos\flysystem;
11
12
use Aws\S3\S3Client;
13
use League\Flysystem\AwsS3v3\AwsS3Adapter;
14
use yii\base\InvalidConfigException;
15
16
class AwsS3FsComponent extends AbstractFsComponent
17
{
18
    /**
19
     * @var string
20
     */
21
    public $key;
22
    /**
23
     * @var string
24
     */
25
    public $secret;
26
    /**
27
     * @var string
28
     */
29
    public $region;
30
    /**
31
     * @var string
32
     */
33
    public $bucket;
34
    /**
35
     * @var string|null
36
     */
37
    public $prefix;
38
    /**
39
     * @var string
40
     */
41
    public $version = "latest";
42
    /**
43
     * @var string for custom endpoints
44
     */
45
    public $endpoint;
46
    /**
47
     * @var array
48
     */
49
    public $options = [];
50
51
    /**
52
     * @inheritdoc
53
     */
54
    public function init()
55
    {
56
        if ($this->key === null) {
57
            throw new InvalidConfigException('The "key" property must be set.');
58
        }
59
60
        if ($this->secret === null) {
61
            throw new InvalidConfigException('The "secret" property must be set.');
62
        }
63
64
        if ($this->bucket === null) {
65
            throw new InvalidConfigException('The "bucket" property must be set.');
66
        }
67
68
        if ($this->region === null) {
69
            throw new InvalidConfigException('The "region" property must be set.');
70
        }
71
72
        parent::init();
73
    }
74
75
    /**
76
     * @return AwsS3Adapter
77
     */
78
    protected function initAdapter()
79
    {
80
        $config = array_filter(
81
            [
82
                'credentials' => [
83
                    'key' => $this->key,
84
                    'secret' => $this->secret
85
                ],
86
                'region' => $this->region,
87
                'version' => $this->version,
88
                'endpoint' => $this->endpoint
89
            ]
90
        );
91
92
        return new AwsS3Adapter(
93
            new S3Client($config),
94
            $this->bucket,
95
            $this->prefix
96
        );
97
    }
98
}
99