From aa21244593c0127248edf2a57fa62ef585f587dc Mon Sep 17 00:00:00 2001 From: Val Bancer Date: Tue, 8 Nov 2016 00:40:46 +0100 Subject: [PATCH] accept webroot shell parameter --- lib/Cake/Console/Command/CommandListShell.php | 1 + lib/Cake/Console/ShellDispatcher.php | 21 +++++++++++++++---- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/lib/Cake/Console/Command/CommandListShell.php b/lib/Cake/Console/Command/CommandListShell.php index ca6620a5b..2962fa526 100644 --- a/lib/Cake/Console/Command/CommandListShell.php +++ b/lib/Cake/Console/Command/CommandListShell.php @@ -54,6 +54,7 @@ class CommandListShell extends AppShell { $this->out(" -working: " . rtrim(APP, DS)); $this->out(" -root: " . rtrim(ROOT, DS)); $this->out(" -core: " . rtrim(CORE_PATH, DS)); + $this->out(" -webroot: " . WWW_ROOT); $this->out(""); $this->out(__d('cake_console', "Changing Paths:"), 2); $this->out(__d('cake_console', "Your working path should be the same as your application path. To change your path use the '-app' param.")); diff --git a/lib/Cake/Console/ShellDispatcher.php b/lib/Cake/Console/ShellDispatcher.php index 37aa30037..b33714684 100644 --- a/lib/Cake/Console/ShellDispatcher.php +++ b/lib/Cake/Console/ShellDispatcher.php @@ -129,7 +129,7 @@ class ShellDispatcher { define('APP', $this->params['working'] . DS); } if (!defined('WWW_ROOT')) { - define('WWW_ROOT', APP . $this->params['webroot'] . DS); + define('WWW_ROOT', $this->params['webroot'] . DS); } if (!defined('TMP') && !is_dir(APP . 'tmp')) { define('TMP', CAKE_CORE_INCLUDE_PATH . DS . 'Cake' . DS . 'Console' . DS . 'Templates' . DS . 'skel' . DS . 'tmp' . DS); @@ -305,7 +305,7 @@ class ShellDispatcher { } } - if ($params['app'][0] === '/' || preg_match('/([a-z])(:)/i', $params['app'], $matches)) { + if ($this->_isAbsolutePath($params['app'])) { $params['root'] = dirname($params['app']); } elseif (strpos($params['app'], '/')) { $params['root'] .= '/' . dirname($params['app']); @@ -316,14 +316,27 @@ class ShellDispatcher { if (!$isWin || !preg_match('/^[A-Z]:$/i', $params['app'])) { $params['working'] .= '/' . $params['app']; } + if (!$this->_isAbsolutePath($params['webroot'])) { + $params['webroot'] = realpath($params['working'] . DS . $params['webroot']); + } - if (!empty($matches[0]) || !empty($isWin)) { + if (DS == '\\' || !empty($isWin)) { $params = str_replace('/', '\\', $params); } $this->params = $params + $this->params; } +/** + * Checks whether the given path is absolute or relative. + * + * @param string $path absolute or relative path. + * @return boolean + */ + protected function _isAbsolutePath($path) { + return $path[0] === '/' || preg_match('/([a-z])(:)/i', $path); + } + /** * Parses out the paths from from the argv * @@ -332,7 +345,7 @@ class ShellDispatcher { */ protected function _parsePaths($args) { $parsed = array(); - $keys = array('-working', '--working', '-app', '--app', '-root', '--root'); + $keys = array('-working', '--working', '-app', '--app', '-root', '--root', '-webroot', '--webroot'); $args = (array)$args; foreach ($keys as $key) { while (($index = array_search($key, $args)) !== false) {