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

GridFSAdapter::displayName()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

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