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

ZipArchiveAdapter::init()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 4
nc 2
nop 0
dl 0
loc 9
rs 9.6666
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 Yii;
11
use yii\base\InvalidConfigException;
12
use yuncms\filesystem\Adapter;
13
14
/**
15
 * Class ZipArchiveAdapter
16
 *
17
 * @author Tongle Xu <[email protected]>
18
 * @since 3.0
19
 */
20
class ZipArchiveAdapter extends Adapter
21
{
22
    /**
23
     * @var string
24
     */
25
    public $path;
26
    /**
27
     * @var string|null
28
     */
29
    public $prefix;
30
31
    /**
32
     * @inheritdoc
33
     */
34
    public function init()
35
    {
36
        if ($this->path === null) {
37
            throw new InvalidConfigException('The "path" property must be set.');
38
        }
39
40
        $this->path = Yii::getAlias($this->path);
41
42
        parent::init();
43
    }
44
45
    /**
46
     * @inheritdoc
47
     */
48
    public static function displayName(): string
49
    {
50
        return Yii::t('yuncms', 'Zip Archive');
51
    }
52
53
    /**
54
     * @return \League\Flysystem\ZipArchive\ZipArchiveAdapter
55
     */
56
    protected function prepareAdapter()
57
    {
58
        return new \League\Flysystem\ZipArchive\ZipArchiveAdapter(
59
            $this->path,
60
            null,
61
            $this->prefix
62
        );
63
    }
64
}