Completed
Pull Request — master (#1)
by
unknown
04:06
created

Module::getMetadata()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 0
cts 4
cp 0
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
crap 2
1
<?php
2
/**
3
 * Yii2 Pages Module
4
 *
5
 * @link      https://github.com/hiqdev/yii2-module-pages
6
 * @package   yii2-module-pages
7
 * @license   BSD-3-Clause
8
 * @copyright Copyright (c) 2016-2017, HiQDev (http://hiqdev.com/)
9
 */
10
11
namespace hiqdev\yii2\modules\pages;
12
13
use hiqdev\yii2\modules\pages\models\AbstractPage;
14
use hiqdev\yii2\modules\pages\storage\StorageInterface;
15
use Yii;
16
17
class Module extends \yii\base\Module
18
{
19
    /** @var array|StorageInterface */
20
    protected $_storage;
21
22
    public static function getInstance(): Module
23
    {
24
        return Yii::$app->getModule('pages');
25
    }
26
27
    /**
28
     * This to use standard app pathes for views and layouts.
29
     * @return string
30
     */
31
    public function getViewPath()
32
    {
33
        return Yii::$app->getViewPath();
34
    }
35
36
    /**
37
     * @param string $pageName
38
     * @return AbstractPage|null
39
     */
40
    public function find(string $pageName): ?AbstractPage
41
    {
42
        $page = $this->getStorage()->getPage($pageName);
43
44
        return $page;
45
    }
46
47
    public function findList()
48
    {
49
        $list = $this->getStorage()->getList();
50
51
        return $list;
52
    }
53
54
    public function setStorage($value)
55
    {
56
        $this->_storage = $value;
57
    }
58
59
    public function getStorage()
60
    {
61
        if (!is_object($this->_storage)) {
62
            $this->_storage = Yii::createObject($this->_storage);
63
        }
64
65
        return $this->_storage;
66
    }
67
}
68