Completed
Pull Request — develop (#13)
by eXeCUT
02:50 queued 56s
created

Module::getComponent()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 12
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 12
rs 9.4285
c 0
b 0
f 0
cc 3
eloc 8
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
 */
22
class Module extends \yii\base\Module
23
{
24
    const CONSOLE_CONTROLLER_MAP = [
25
        'create' => [
26
            'class' => 'assayerpro\sitemap\console\CreateController',
27
        ],
28
    ];
29
    /**
30
     * The namespace that controller classes are in.
31
     *
32
     * @var string
33
     * @access public
34
     */
35
    public $controllerNamespace = 'assayerpro\sitemap\controllers';
36
37
    public function init()
38
    {
39
        parent::init();
40
        if (\yii::$app instanceof Application) {
41
            $this->controllerMap = self::CONSOLE_CONTROLLER_MAP;
42
        }
43
    }
44
45
    public function getComponent() {
46
        if (!empty(\yii::$app->components['sitemap'])) {
47
            $component = \yii::$app->components['sitemap'];
48
        } else if (!($component = $this->get('sitemap', false))) {
49
            throw new Exception('Component for sitemap module is required. Define it via application components '
50
                . 'or module components');
51
        }
52
53
        $component->moduleId = $this->uniqueId;
54
55
        return $component;
56
    }
57
}
58