Skip to content

Commit

Permalink
force cli env when applicationConsole is called #1856
Browse files Browse the repository at this point in the history
  • Loading branch information
nadar committed Aug 27, 2019
1 parent 396754f commit d66e6a3
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 3 deletions.
1 change: 1 addition & 0 deletions core/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ All notable changes to this project will be documented in this file. This projec

## 1.0.12 (in progress)

+ [#1856](https://github.com/luyadev/luya/issues/1856) If application console method is runing, the cli determination should be forced.
+ [#1853](https://github.com/luyadev/luya/issues/1853) Add option to lazy load mocked arguments.
+ [#1852](https://github.com/luyadev/luya/pull/1852) Updated Svg widget to enable usage of symbols (svg sprite) via svg > use implementation
+ [#1851](https://github.com/luyadev/luya/issues/1851) Add string helper method highlightWord() to highlight a given word withing a string.
Expand Down
53 changes: 50 additions & 3 deletions core/base/Boot.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@
* a config file with custom Luya/Yii configuration must be provided via `$configFile` property. By default luya will try to find
* the default config `../configs/env.php`.
*
* @property boolean $isCli Whether current request is runing in cli env or not.
* @property string $baseYiiFile Returns the path to the yii base file.
*
* @author Basil Suter <[email protected]>
* @since 1.0.0
*/
Expand Down Expand Up @@ -62,14 +65,57 @@ public function setBaseYiiFile($baseYiiFile)
$this->_baseYiiFile = $baseYiiFile;
}

/**
* Getter method for Yii base file.
*
* @return string
*/
public function getBaseYiiFile()
{
return $this->_baseYiiFile;
}

/**
* Whether current request is runing in cli env or not.
*
* This is determined by php_sapi_name().
*
* @return boolean
* @deprecated Depreacted since 1.0.12 use getisCli() or $isCli instead.
*/
public function isCli()
{
return $this->getSapiName() === 'cli';
return $this->getIsCli();
}

private $_isCli;

/**
* Getter method whether current request is cli or not.
*
* If not set via setIsCli() the value is determined trough php_sapi_name();
*
* @return boolean Whether current request is console env or not.
* @since 1.0.12
*/
public function getIsCli()
{
if ($this->_isCli === null) {
$this->_isCli = $this->getSapiName() === 'cli';
}

return $this->_isCli;
}

/**
* Setter method for isCli.
*
* @param boolean $isCli
* @since 1.0.12
*/
public function setIsCli($isCli)
{
$this->_isCli = $isCli;
}

/**
Expand Down Expand Up @@ -127,7 +173,7 @@ public function getConfigArray()
{
if ($this->_configArray === null) {
if (!file_exists($this->configFile)) {
if (!$this->isCli()) {
if (!$this->isCli) {
throw new Exception("Unable to load the config file '".$this->configFile."'.");
}

Expand Down Expand Up @@ -158,7 +204,7 @@ public function getConfigArray()
*/
public function run()
{
if ($this->isCli()) {
if ($this->isCli) {
return $this->applicationConsole();
}

Expand All @@ -172,6 +218,7 @@ public function run()
*/
public function applicationConsole()
{
$this->setIsCli(true);
$config = $this->getConfigArray();
$config['defaultRoute'] = 'help';
if (isset($config['components'])) {
Expand Down

0 comments on commit d66e6a3

Please sign in to comment.