diff --git a/lib/Cake/Console/Command/CommandListShell.php b/lib/Cake/Console/Command/CommandListShell.php index ca6620a5b..9ea44960c 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: " . rtrim(WWW_ROOT, DS)); $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..bb2095418 100644 --- a/lib/Cake/Console/ShellDispatcher.php +++ b/lib/Cake/Console/ShellDispatcher.php @@ -129,7 +129,12 @@ class ShellDispatcher { define('APP', $this->params['working'] . DS); } if (!defined('WWW_ROOT')) { - define('WWW_ROOT', APP . $this->params['webroot'] . DS); + if (!$this->_isAbsolutePath($this->params['webroot'])) { + $webroot = realpath(APP . $this->params['webroot']); + } else { + $webroot = $this->params['webroot']; + } + define('WWW_ROOT', $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,25 +310,45 @@ 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']); } - + $isWindowsAppPath = $this->_isWindowsPath($params['app']); $params['app'] = basename($params['app']); $params['working'] = rtrim($params['root'], '/'); if (!$isWin || !preg_match('/^[A-Z]:$/i', $params['app'])) { $params['working'] .= '/' . $params['app']; } - if (!empty($matches[0]) || !empty($isWin)) { + if ($isWindowsAppPath || !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 bool + */ + protected function _isAbsolutePath($path) { + return $path[0] === '/' || $this->_isWindowsPath($path); + } + +/** + * Checks whether the given path is Window OS path. + * + * @param string $path absolute path. + * @return bool + */ + protected function _isWindowsPath($path) { + return preg_match('/([a-z])(:)/i', $path) == 1; + } + /** * Parses out the paths from from the argv * @@ -332,7 +357,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) { diff --git a/lib/Cake/Test/Case/Console/ShellDispatcherTest.php b/lib/Cake/Test/Case/Console/ShellDispatcherTest.php index cec15d12a..a6f4afb05 100644 --- a/lib/Cake/Test/Case/Console/ShellDispatcherTest.php +++ b/lib/Cake/Test/Case/Console/ShellDispatcherTest.php @@ -137,9 +137,8 @@ class ShellDispatcherTest extends CakeTestCase { * * @return void */ - public function testParseParams() { + public function testParseParamsAppWorkingAbsolute() { $Dispatcher = new TestShellDispatcher(); - $params = array( '/cake/1.2.x.x/cake/console/cake.php', 'bake', @@ -156,7 +155,15 @@ class ShellDispatcherTest extends CakeTestCase { ); $Dispatcher->parseParams($params); $this->assertEquals($expected, $Dispatcher->params); + } +/** + * testParseParams method + * + * @return void + */ + public function testParseParamsNone() { + $Dispatcher = new TestShellDispatcher(); $params = array('cake.php'); $expected = array( 'app' => 'app', @@ -167,7 +174,15 @@ class ShellDispatcherTest extends CakeTestCase { $Dispatcher->params = $Dispatcher->args = array(); $Dispatcher->parseParams($params); $this->assertEquals($expected, $Dispatcher->params); + } +/** + * testParseParams method + * + * @return void + */ + public function testParseParamsApp() { + $Dispatcher = new TestShellDispatcher(); $params = array( 'cake.php', '-app', @@ -182,7 +197,15 @@ class ShellDispatcherTest extends CakeTestCase { $Dispatcher->params = $Dispatcher->args = array(); $Dispatcher->parseParams($params); $this->assertEquals($expected, $Dispatcher->params); + } +/** + * testParseParams method + * + * @return void + */ + public function testParseParamsAppWorkingRelative() { + $Dispatcher = new TestShellDispatcher(); $params = array( './cake.php', 'bake', @@ -191,17 +214,24 @@ class ShellDispatcherTest extends CakeTestCase { '-working', '/cake/1.2.x.x/cake/console' ); - $expected = array( 'app' => 'new', 'webroot' => 'webroot', 'working' => str_replace('\\', DS, dirname(CAKE_CORE_INCLUDE_PATH) . DS . 'new'), 'root' => str_replace('\\', DS, dirname(CAKE_CORE_INCLUDE_PATH)) ); - $Dispatcher->params = $Dispatcher->args = array(); $Dispatcher->parseParams($params); $this->assertEquals($expected, $Dispatcher->params); + } + +/** + * testParseParams method + * + * @return void + */ + public function testParseParams() { + $Dispatcher = new TestShellDispatcher(); $params = array( './console/cake.php',