Completed
Push — master ( b4d6a5...352f6d )
by Basil
02:42
created

Bootstrap   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 38
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 4

Importance

Changes 0
Metric Value
wmc 6
lcom 0
cbo 4
dl 0
loc 38
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A beforeRun() 0 5 1
A run() 0 17 5
1
<?php
2
3
namespace luya\console;
4
5
use Yii;
6
use luya\base\BaseBootstrap;
7
use luya\helpers\FileHelper;
8
use yii\helpers\Inflector;
9
10
/**
11
 * Luya CLI Bootsrap.
12
 *
13
 * @author Basil Suter <[email protected]>
14
 * @since 1.0.0
15
 */
16
class Bootstrap extends BaseBootstrap
17
{
18
    /**
19
     * Add missing alias names @web and @webroot.
20
     *
21
     * @param object $app Luya CLI Application Object
22
     *
23
     * @see \luya\base\BaseBootstrap::beforeRun()
24
     */
25
    public function beforeRun($app)
26
    {
27
        Yii::setAlias('@web', $app->basePath);
28
        Yii::setAlias('@webroot', $app->webroot);
29
    }
30
31
    /**
32
     * The run method must be implemented by defintion.
33
     *
34
     * @see \luya\base\BaseBootstrap::run()
35
     */
36
    public function run($app)
37
    {
38
        foreach ($app->getApplicationModules() as $id => $module) {
39
            $folder = $module->basePath . DIRECTORY_SEPARATOR . 'commands';
40
            if (file_exists($folder) && is_dir($folder)) {
41
                foreach (FileHelper::findFiles($folder) as $file) {
42
                    $module->controllerNamespace = $module->namespace . '\commands';
43
                    
44
                    $className = '\\'.$module->getNamespace().'\\commands\\' . pathinfo($file, PATHINFO_FILENAME);
45
46
                    $command = str_replace('-controller', '', $module->id . '/' . Inflector::camel2id(pathinfo($file, PATHINFO_FILENAME)));
47
                    
48
                    Yii::$app->controllerMap[$command] = ['class' => $className];
49
                }
50
            }
51
        }
52
    }
53
}
54