mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2024-11-15 03:18:26 +00:00
Merge pull request #9717 from bancer/shell-webroot
accept webroot shell parameter
This commit is contained in:
commit
f46f042001
3 changed files with 65 additions and 9 deletions
|
@ -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', "<info>Changing Paths:</info>"), 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."));
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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',
|
||||
|
|
Loading…
Reference in a new issue