Class luya\Boot

Inheritanceluya\Boot » luya\base\Boot
Available since version1.0.0

Boot LUYA Application.

The LUYA boot class to startup the application

Public Properties

Hide inherited properties

Property Type Description Defined By
$app luya\web\Application|luya\console\Application The application object. luya\base\Boot
$configFile string The path to the config file, which returns an array containing you configuration. luya\base\Boot
$mockOnly boolean When enabled the boot process will not return/echo something, but the variabled will contain the Application object. luya\base\Boot

Public Methods

Hide inherited methods

Method Description Defined By
applicationConsole() Run Cli-Application based on the provided config file. luya\base\Boot
applicationWeb() Run Web-Application based on the provided config file. luya\base\Boot
getBaseYiiFile() Getter method for Yii base file. luya\base\Boot
getConfigArray() Get the config array from the configFile path with the predefined values. luya\base\Boot
getCoreBasePath() Returns the path to luya core files luya\base\Boot
getIsCli() Getter method whether current request is cli or not. luya\base\Boot
getSapiName() Returns the current sapi name in lower case. luya\base\Boot
prependConfigArray() The prependConfigArray will be merged into the config, this way you can prepand config values for a custom Boot class. luya\base\Boot
run() Run the application based on the Sapi Name. luya\base\Boot
setBaseYiiFile() Setter method for the base Yii file. luya\base\Boot
setConfigArray() This method allows you to directly inject a configuration array instead of using the config file method. luya\base\Boot
setIsCli() Setter method for isCli. luya\base\Boot

Constants

Hide inherited constants

Constant Value Description Defined By
VERSION '2.2.1' luya\base\Boot

Method Details

Hide inherited methods

applicationConsole() public method

Defined in: luya\base\Boot::applicationConsole()

Run Cli-Application based on the provided config file.

public string|integer applicationConsole ( )

                public function applicationConsole()
{
    $this->setIsCli(true);
    $config = $this->getConfigArray();
    $config['defaultRoute'] = 'help';
    if (isset($config['components'])) {
        if (isset($config['components']['composition'])) {
            unset($config['components']['composition']);
        }
    }
    
    $this->includeYii();
    $baseUrl = null;
    if (isset($config['consoleBaseUrl'])) {
        $baseUrl = $config['consoleBaseUrl'];
    } elseif (isset($config['consoleHostInfo'])) {
        $baseUrl = '/';
    }
    
    $mergedConfig = ArrayHelper::merge($config, [
        'bootstrap' => ['luya\console\Bootstrap'],
        'components' => [
            'urlManager' => [
                'class' => 'yii\web\UrlManager',
                'enablePrettyUrl' => true,
                'showScriptName' => false,
                'baseUrl' => $baseUrl,
                'hostInfo' => isset($config['consoleHostInfo']) ? $config['consoleHostInfo'] : null,
            ],
        ],
    ]);
    $this->app = new ConsoleApplication($mergedConfig);
    if (!$this->mockOnly) {
        exit($this->app->run());
    }
}

            
applicationWeb() public method

Defined in: luya\base\Boot::applicationWeb()

Run Web-Application based on the provided config file.

public string applicationWeb ( )
return string

Returns the Yii Application run() method if mock is disabled. Otherwise returns void

                public function applicationWeb()
{
    $config = $this->getConfigArray();
    $this->includeYii();
    $mergedConfig = ArrayHelper::merge($config, ['bootstrap' => ['luya\web\Bootstrap']]);
    $this->app = new WebApplication($mergedConfig);
    if (!$this->mockOnly) {
        return $this->app->run();
    }
}

            
getBaseYiiFile() public method

Defined in: luya\base\Boot::getBaseYiiFile()

Getter method for Yii base file.

public string getBaseYiiFile ( )

                public function getBaseYiiFile()
{
    return $this->_baseYiiFile;
}

            
getConfigArray() public method

Defined in: luya\base\Boot::getConfigArray()

Get the config array from the configFile path with the predefined values.

public array getConfigArray ( )
return array

The array which will be injected into the Application Constructor.

throws luya\Exception

Throws exception if the config file does not exists.

                public function getConfigArray()
{
    if ($this->_configArray === null) {
        if (!file_exists($this->configFile)) {
            if (!$this->getIsCli()) {
                throw new Exception("Unable to load the config file '".$this->configFile."'.");
            }
            
            $config = ['id' => 'consoleapp', 'basePath' => dirname(__DIR__)];
        } else {
            $config = require $this->configFile;
        }

        if (!is_array($config)) {
            throw new Exception("config file '".$this->configFile."' found but no array returning.");
        }
        
        // preset the values from the defaultConfigArray
        if (!empty($this->prependConfigArray())) {
            $config = ArrayHelper::merge($config, $this->prependConfigArray());
        }
     
        $this->_configArray = $config;
    }
    return $this->_configArray;
}

            
getCoreBasePath() public method

Defined in: luya\base\Boot::getCoreBasePath()

Returns the path to luya core files

public string getCoreBasePath ( )
return string

The base path to the luya core folder.

                public function getCoreBasePath()
{
    $reflector = new ReflectionClass(get_class($this));
    return dirname($reflector->getFileName());
}

            
getIsCli() public method (available since version 1.0.12)

Defined in: luya\base\Boot::getIsCli()

Getter method whether current request is cli or not.

If not set via setIsCli() the value is determined trough php_sapi_name();

public boolean getIsCli ( )
return boolean

Whether current request is console env or not.

                public function getIsCli()
{
    if ($this->_isCli === null) {
        $this->_isCli = $this->getSapiName() === 'cli';
    }
    return $this->_isCli;
}

            
getSapiName() public method

Defined in: luya\base\Boot::getSapiName()

Returns the current sapi name in lower case.

public string getSapiName ( )
return string

E.g. cli or web

                public function getSapiName()
{
    return strtolower(php_sapi_name());
}

            
prependConfigArray() public method

Defined in: luya\base\Boot::prependConfigArray()

The prependConfigArray will be merged into the config, this way you can prepand config values for a custom Boot class.

When using prependConfig inside a custom boot class, the custom boot class will not used in the vendor bin file ./vendor/bin/luya, so make sure to generate your own bin file.

public array prependConfigArray ( )

                public function prependConfigArray()
{
    return [];
}

            
run() public method

Defined in: luya\base\Boot::run()

Run the application based on the Sapi Name.

public luya\web\Application|luya\console\Application run ( )
return luya\web\Application|luya\console\Application

Application objected based on the sapi name.

                public function run()
{
    if ($this->getIsCli()) {
        return $this->applicationConsole();
    }
    return $this->applicationWeb();
}

            
setBaseYiiFile() public method

Defined in: luya\base\Boot::setBaseYiiFile()

Setter method for the base Yii file.

Example path to the yii base file:

$boot->setYiiPath(__DIR__ . '/../vendor/yiisoft/yii2/Yii.php');
public void setBaseYiiFile ( $baseYiiFile )
$baseYiiFile string

The path to the Yii.php file.

                public function setBaseYiiFile($baseYiiFile)
{
    $this->_baseYiiFile = $baseYiiFile;
}

            
setConfigArray() public method

Defined in: luya\base\Boot::setConfigArray()

This method allows you to directly inject a configuration array instead of using the config file method.

This method is commonly used when running php unit tests which do not require an additional file.

$app = new Boot();
$app->setConfigArray([
    // ...
]);
public void setConfigArray ( array $config )
$config array

The configuration array for the application.

                public function setConfigArray(array $config)
{
    $this->_configArray = $config;
}

            
setIsCli() public method (available since version 1.0.12)

Defined in: luya\base\Boot::setIsCli()

Setter method for isCli.

public void setIsCli ( $isCli )
$isCli boolean

                public function setIsCli($isCli)
{
    $this->_isCli = $isCli;
}