Test Setup Failed
Pull Request — develop (#13)
by eXeCUT
02:38
created

Module::getSitemap()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 12
rs 9.8666
c 0
b 0
f 0
cc 3
nc 3
nop 0
1
<?php
2
/**
3
 * Sitemap module
4
 *
5
 * @author Serge Larin <[email protected]>
6
 * @link http://assayer.pro/
7
 * @copyright 2015 Assayer Pro Company
8
 * @license http://opensource.org/licenses/LGPL-3.0
9
 */
10
11
12
namespace assayerpro\sitemap;
13
use yii\base\Exception;
14
use yii\console\Application;
15
16
/**
17
 * Class Module for sitemap
18
 *
19
 * @author Serge Larin <[email protected]>
20
 * @package app\modules\webmaster
21
 * @property Sitemap $sitemap
22
 */
23
class Module extends \yii\base\Module
24
{
25
    const CONSOLE_CONTROLLER_MAP = [
26
        'create' => [
27
            'class' => 'assayerpro\sitemap\console\CreateController',
28
        ],
29
    ];
30
31
    /**
32
     * sitemap
33
     *
34
     * @var mixed
35
     * @access private
36
     */
37
    private $_sitemap = null;
38
    /**
39
     * The namespace that controller classes are in.
40
     *
41
     * @var string
42
     * @access public
43
     */
44
    public $controllerNamespace = 'assayerpro\sitemap\controllers';
45
46
    public function init()
47
    {
48
        parent::init();
49
        if (\yii::$app instanceof Application) {
50
            $this->controllerMap = self::CONSOLE_CONTROLLER_MAP;
51
        }
52
    }
53
54
55
    /**
56
     * setSitemap
57
     *
58
     * @param mixed $sitemap
59
     * @access public
60
     * @return void
61
     */
62
    public function setSitemap($sitemap) {
63
        $this->_sitemap = $sitemap;
64
65
    }
66
67
    /**
68
     * getSitemap
69
     *
70
     * @access public
71
     * @return Sitemap
72
     */
73
    public function getSitemap() {
74
        if (!empty(\yii::$app->components['sitemap'])) {
75
            $result = \yii::$app->get('sitemap');
76
        } else if (!($result = $this->_sitemap)) {
77
            throw new Exception('Component for sitemap module is required. Define it via application components '
78
                . 'or module components');
79
        }
80
81
        $result->module = $this;
82
83
        return $result;
84
    }
85
}
86