From d66e6a3c37730cd371a34e2c960426f46a68b3f3 Mon Sep 17 00:00:00 2001 From: Basil Suter Date: Fri, 21 Sep 2018 11:27:33 +0200 Subject: [PATCH] force cli env when applicationConsole is called #1856 --- core/CHANGELOG.md | 1 + core/base/Boot.php | 53 +++++++++++++++++++++++++++++++++++++++++++--- 2 files changed, 51 insertions(+), 3 deletions(-) diff --git a/core/CHANGELOG.md b/core/CHANGELOG.md index 2f35f5dcf..3c6a95f99 100644 --- a/core/CHANGELOG.md +++ b/core/CHANGELOG.md @@ -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. diff --git a/core/base/Boot.php b/core/base/Boot.php index 067839d68..58a814eec 100644 --- a/core/base/Boot.php +++ b/core/base/Boot.php @@ -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 * @since 1.0.0 */ @@ -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; } /** @@ -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."'."); } @@ -158,7 +204,7 @@ public function getConfigArray() */ public function run() { - if ($this->isCli()) { + if ($this->isCli) { return $this->applicationConsole(); } @@ -172,6 +218,7 @@ public function run() */ public function applicationConsole() { + $this->setIsCli(true); $config = $this->getConfigArray(); $config['defaultRoute'] = 'help'; if (isset($config['components'])) {