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

WebDAVAdapter::init()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 3
nc 2
nop 0
dl 0
loc 7
rs 9.4285
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 Sabre\DAV\Client;
11
use Yii;
12
use yii\base\InvalidConfigException;
13
use yuncms\filesystem\Adapter;
14
15
/**
16
 * Class WebDAVAdapter
17
 *
18
 * @author Tongle Xu <[email protected]>
19
 * @since 3.0
20
 */
21
class WebDAVAdapter extends Adapter
22
{
23
    /**
24
     * @var string
25
     */
26
    public $baseUri;
27
    /**
28
     * @var string
29
     */
30
    public $userName;
31
    /**
32
     * @var string
33
     */
34
    public $password;
35
    /**
36
     * @var string
37
     */
38
    public $proxy;
39
    /**
40
     * @var integer
41
     */
42
    public $authType;
43
    /**
44
     * @var integer
45
     */
46
    public $encoding;
47
    /**
48
     * @var string|null
49
     */
50
    public $prefix;
51
52
    /**
53
     * @inheritdoc
54
     */
55
    public function init()
56
    {
57
        if ($this->baseUri === null) {
58
            throw new InvalidConfigException('The "baseUri" property must be set.');
59
        }
60
61
        parent::init();
62
    }
63
64
    /**
65
     * @inheritdoc
66
     */
67
    public static function displayName(): string
68
    {
69
        return Yii::t('yuncms', 'WebDAV');
70
    }
71
72
    /**
73
     * @return \League\Flysystem\WebDAV\WebDAVAdapter
74
     */
75
    protected function prepareAdapter()
76
    {
77
        $config = [];
78
79
        foreach ([
80
                     'baseUri',
81
                     'userName',
82
                     'password',
83
                     'proxy',
84
                     'authType',
85
                     'encoding',
86
                 ] as $name) {
87
            if ($this->$name !== null) {
88
                $config[$name] = $this->$name;
89
            }
90
        }
91
92
        return new \League\Flysystem\WebDAV\WebDAVAdapter(
93
            new Client($config),
94
            $this->prefix
95
        );
96
    }
97
}