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

LocalAdapter   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 41
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
dl 0
loc 41
rs 10
c 0
b 0
f 0
wmc 5

4 Methods

Rating   Name   Duplication   Size   Complexity  
A prepareAdapter() 0 3 1
A init() 0 7 2
A displayName() 0 3 1
A getRootPath() 0 3 1
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 Yii;
11
use yii\base\InvalidConfigException;
12
use yuncms\filesystem\Adapter;
13
use League\Flysystem\Adapter\Local;
14
use yuncms\helpers\FileHelper;
15
16
/**
17
 * Class Local
18
 *
19
 * @author Tongle Xu <[email protected]>
20
 * @since 3.0
21
 */
22
class LocalAdapter extends Adapter
23
{
24
    /**
25
     * @var string
26
     */
27
    public $path;
28
29
    /**
30
     * @inheritdoc
31
     */
32
    public static function displayName(): string
33
    {
34
        return Yii::t('yuncms', 'Local Folder');
35
    }
36
37
    /**
38
     * @inheritdoc
39
     */
40
    public function init()
41
    {
42
        if ($this->path === null) {
43
            throw new InvalidConfigException('The "path" property must be set.');
44
        }
45
        $this->path = Yii::getAlias($this->path);
46
        parent::init();
47
    }
48
49
    /**
50
     * @return Local
51
     */
52
    protected function prepareAdapter()
53
    {
54
        return new Local($this->path);
55
    }
56
57
    /**
58
     * @inheritdoc
59
     */
60
    public function getRootPath(): string
61
    {
62
        return FileHelper::normalizePath($this->path);
63
    }
64
}