Completed
Push — master ( 5289b1...66334b )
by Xu
06:18
created

RackspaceAdapter::init()   B

Complexity

Conditions 6
Paths 6

Size

Total Lines 23
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 6
eloc 11
nc 6
nop 0
dl 0
loc 23
rs 8.5906
c 0
b 0
f 0
1
<?php
2
/**
3
 * @link http://www.tintsoft.com/
4
 * @copyright Copyright (c) 2012 TintSoft Technology Co. Ltd.
5
 * @license http://www.tintsoft.com/license/
6
 */
7
8
namespace yuncms\filesystem\adapters;
9
10
use OpenCloud\Rackspace;
11
use Yii;
12
use yii\base\InvalidConfigException;
13
use yuncms\filesystem\Adapter;
14
15
/**
16
 * Class RackspaceAdapter
17
 *
18
 * @author Tongle Xu <[email protected]>
19
 * @since 3.0
20
 */
21
class RackspaceAdapter extends Adapter
22
{
23
    /**
24
     * @var string
25
     */
26
    public $endpoint;
27
    /**
28
     * @var string
29
     */
30
    public $username;
31
    /**
32
     * @var string
33
     */
34
    public $apiKey;
35
    /**
36
     * @var string
37
     */
38
    public $region;
39
    /**
40
     * @var string
41
     */
42
    public $container;
43
    /**
44
     * @var string|null
45
     */
46
    public $prefix;
47
48
    /**
49
     * @inheritdoc
50
     */
51
    public function init()
52
    {
53
        if ($this->endpoint === null) {
54
            throw new InvalidConfigException('The "endpoint" property must be set.');
55
        }
56
57
        if ($this->username === null) {
58
            throw new InvalidConfigException('The "username" property must be set.');
59
        }
60
61
        if ($this->apiKey === null) {
62
            throw new InvalidConfigException('The "apiKey" property must be set.');
63
        }
64
65
        if ($this->region === null) {
66
            throw new InvalidConfigException('The "region" property must be set.');
67
        }
68
69
        if ($this->container === null) {
70
            throw new InvalidConfigException('The "container" property must be set.');
71
        }
72
73
        parent::init();
74
    }
75
76
    /**
77
     * @inheritdoc
78
     */
79
    public static function displayName(): string
80
    {
81
        return Yii::t('yuncms', 'Rackspace');
82
    }
83
84
    /**
85
     * @return \League\Flysystem\Rackspace\RackspaceAdapter
86
     */
87
    protected function prepareAdapter()
88
    {
89
        return new \League\Flysystem\Rackspace\RackspaceAdapter(
90
            (new Rackspace($this->endpoint, [
91
                    'username' => $this->username,
92
                    'apiKey' => $this->apiKey]
93
            ))->objectStoreService('cloudFiles', $this->region)->getContainer($this->container),
0 ignored issues
show
Bug introduced by
$this->container of type string is incompatible with the type stdClass expected by parameter $data of OpenCloud\ObjectStore\Service::getContainer(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

93
            ))->objectStoreService('cloudFiles', $this->region)->getContainer(/** @scrutinizer ignore-type */ $this->container),
Loading history...
94
            $this->prefix
95
        );
96
    }
97
}