Completed
Push — master ( 30d3de...6bbfea )
by Xu
29:18 queued 23:02
created

FtpAdapter::init()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 11
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
eloc 5
nc 3
nop 0
dl 0
loc 11
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
9
namespace yuncms\filesystem\adapters;
10
11
use Yii;
12
use yii\base\InvalidConfigException;
13
use yuncms\filesystem\Adapter;
14
use League\Flysystem\Adapter\Ftp;
15
16
/**
17
 * Class Ftp
18
 *
19
 * @author Tongle Xu <[email protected]>
20
 * @since 3.0
21
 */
22
class FtpAdapter extends Adapter
23
{
24
    /**
25
     * @var string
26
     */
27
    public $host;
28
    /**
29
     * @var integer
30
     */
31
    public $port;
32
    /**
33
     * @var string
34
     */
35
    public $username;
36
    /**
37
     * @var string
38
     */
39
    public $password;
40
    /**
41
     * @var boolean
42
     */
43
    public $ssl;
44
    /**
45
     * @var integer
46
     */
47
    public $timeout;
48
    /**
49
     * @var string
50
     */
51
    public $root;
52
    /**
53
     * @var integer
54
     */
55
    public $permPrivate;
56
    /**
57
     * @var integer
58
     */
59
    public $permPublic;
60
    /**
61
     * @var boolean
62
     */
63
    public $passive;
64
    /**
65
     * @var integer
66
     */
67
    public $transferMode;
68
69
    /**
70
     * @inheritdoc
71
     */
72
    public function init()
73
    {
74
        if ($this->host === null) {
75
            throw new InvalidConfigException('The "host" property must be set.');
76
        }
77
78
        if ($this->root !== null) {
79
            $this->root = Yii::getAlias($this->root);
80
        }
81
82
        parent::init();
83
    }
84
85
    /**
86
     * @return  Ftp
87
     */
88
    protected function prepareAdapter()
89
    {
90
        $config = [];
91
        foreach ([
92
                     'host',
93
                     'port',
94
                     'username',
95
                     'password',
96
                     'ssl',
97
                     'timeout',
98
                     'root',
99
                     'permPrivate',
100
                     'permPublic',
101
                     'passive',
102
                     'transferMode',
103
                 ] as $name) {
104
            if ($this->$name !== null) {
105
                $config[$name] = $this->$name;
106
            }
107
        }
108
109
        return new Ftp($config);
110
    }
111
}