Class luya\console\Bootstrap

Inheritanceluya\console\Bootstrap » luya\base\BaseBootstrap
Implementsyii\base\BootstrapInterface
Available since version1.0.0

Luya CLI Bootsrap.

Public Methods

Hide inherited methods

Method Description Defined By
beforeRun() Add missing alias names @web and @webroot. luya\console\Bootstrap
bootstrap() Boostrap method will be invoken by Yii Application bootrapping proccess containing the Application ($app) Object to get/set data. luya\base\BaseBootstrap
extractModules() Extract and load all modules from the Application-Object. luya\base\BaseBootstrap
getModules() Return all modules prepared by extractModules() method. luya\base\BaseBootstrap
hasModule() Check if a Module exists in the module list getModules(). luya\base\BaseBootstrap
run() The run method must be implemented by defintion. luya\console\Bootstrap

Method Details

Hide inherited methods

beforeRun() public method

Add missing alias names @web and @webroot.

See also luya\base\BaseBootstrap::beforeRun().

public void beforeRun ( $app )
$app object

Luya CLI Application Object

                public function beforeRun($app)
{
    Yii::setAlias('@web', $app->basePath);
    Yii::setAlias('@webroot', $app->webroot);
}

            
bootstrap() public method

Defined in: luya\base\BaseBootstrap::bootstrap()

Boostrap method will be invoken by Yii Application bootrapping proccess containing the Application ($app) Object to get/set data.

public void bootstrap ( $app )
$app object

Luya Application luya\base\Application.

                public function bootstrap($app)
{
    // add trace
    Yii::beginProfile('LUYA Boostrap process profiling', __METHOD__);
    
    // register luya core translation message source
    if (!isset($app->i18n->translations['luya'])) {
        $app->i18n->translations['luya'] = [
            'class' => 'yii\i18n\PhpMessageSource',
            'basePath' => '@luya/messages',
        ];
    }
    
    $this->extractModules($app);
    $this->beforeRun($app);
    $this->startModules($app);
    $this->run($app);
    
    // end trace
    Yii::debug('End of the LUYA bootstraping process', __METHOD__);
    Yii::endProfile('LUYA Boostrap process profiling');
}

            
extractModules() public method

Defined in: luya\base\BaseBootstrap::extractModules()

Extract and load all modules from the Application-Object.

public void extractModules ( $app )
$app object

Luya Application luya\base\Application.

                public function extractModules($app)
{
    if ($this->_modules === null) {
        foreach ($app->getModules() as $id => $obj) {
            // create module object
            $moduleObject = Yii::$app->getModule($id);
            // see if the module is a luya base module, otherwise ignore
            if ($moduleObject instanceof \luya\base\Module) {
                $this->_modules[$id] = $moduleObject;
            }
        }
        // when no luya modules are registered an empty array will be returned.
        if ($this->_modules === null) {
            $this->_modules = [];
        }
    }
}

            
getModules() public method

Defined in: luya\base\BaseBootstrap::getModules()

Return all modules prepared by extractModules() method.

public array getModules ( )
return array

An array containg all modules where the key is the module name and the value is the Module Object luya\base\Module.

                public function getModules()
{
    return $this->_modules;
}

            
hasModule() public method

Defined in: luya\base\BaseBootstrap::hasModule()

Check if a Module exists in the module list getModules().

public boolean hasModule ( $module )
$module string

The name of the Module

                public function hasModule($module)
{
    return array_key_exists($module, $this->_modules);
}

            
run() public method

The run method must be implemented by defintion.

See also luya\base\BaseBootstrap::run().

public void run ( $app )
$app

                public function run($app)
{
    foreach ($app->getApplicationModules() as $id => $module) {
        $folder = $module->basePath . DIRECTORY_SEPARATOR . 'commands';
        if (file_exists($folder) && is_dir($folder)) {
            foreach (FileHelper::findFiles($folder) as $file) {
                $module->controllerNamespace = $module->namespace . '\commands';
                
                $className = '\\'.$module->getNamespace().'\\commands\\' . pathinfo($file, PATHINFO_FILENAME);
                $command = str_replace('-controller', '', $module->id . '/' . Inflector::camel2id(pathinfo($file, PATHINFO_FILENAME)));
                
                Yii::$app->controllerMap[$command] = ['class' => $className];
            }
        }
    }
}