Browse Source

Remove -app, -working, and -root parameters.

These legacy parameters are not needed now that we are not supporting
globally installed CakePHP libraries. Because CakePHP will only be
supported in local per application installations, we have far less work
to make paths and environment data consistent and proper.
mark_story 12 years ago
parent
commit
e49f56d487

+ 3 - 7
src/Console/Command/CommandListShell.php

@@ -52,14 +52,10 @@ class CommandListShell extends Shell {
 	public function main() {
 		if (empty($this->params['xml'])) {
 			$this->out(__d('cake_console', "<info>Current Paths:</info>"), 2);
-			$this->out(" -app: " . APP_DIR);
-			$this->out(" -working: " . rtrim(APP, DS));
-			$this->out(" -root: " . rtrim(ROOT, DS));
-			$this->out(" -core: " . rtrim(CORE_PATH, DS));
+			$this->out("* app: " . APP_DIR);
+			$this->out("* root: " . rtrim(ROOT, DS));
+			$this->out("* core: " . rtrim(CORE_PATH, 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."));
-			$this->out(__d('cake_console', "Example: %s or %s", '-app relative/path/to/myapp', '-app /absolute/path/to/myapp'), 2);
 
 			$this->out(__d('cake_console', "<info>Available Shells:</info>"), 2);
 		}

+ 6 - 103
src/Console/ShellDispatcher.php

@@ -52,10 +52,9 @@ class ShellDispatcher {
  */
 	public function __construct($args = [], $bootstrap = true) {
 		set_time_limit(0);
-		$this->parseParams($args);
+		$this->args = $args;
 
 		if ($bootstrap) {
-			$this->_initConstants();
 			$this->_initEnvironment();
 		}
 	}
@@ -72,19 +71,6 @@ class ShellDispatcher {
 	}
 
 /**
- * Defines core configuration.
- *
- * @return void
- */
-	protected function _initConstants() {
-		if (function_exists('ini_set')) {
-			ini_set('html_errors', false);
-			ini_set('implicit_flush', true);
-			ini_set('max_execution_time', 0);
-		}
-	}
-
-/**
  * Defines current working environment.
  *
  * @return void
@@ -92,16 +78,14 @@ class ShellDispatcher {
  */
 	protected function _initEnvironment() {
 		if (!$this->_bootstrap()) {
-			$message = "Unable to load CakePHP core.\nMake sure " . DS . 'lib' . DS . 'Cake exists in ' . CAKE_CORE_INCLUDE_PATH;
+			$message = "Unable to load CakePHP core.\nMake sure Cake exists in " . CAKE_CORE_INCLUDE_PATH;
 			throw new Exception($message);
 		}
 
-		if (!isset($this->args[0]) || !isset($this->params['working'])) {
-			$message = "This file has been loaded incorrectly and cannot continue.\n" .
-				"Please make sure that " . DS . 'lib' . DS . 'Cake' . DS . "Console is in your system path,\n" .
-				"and check the cookbook for the correct usage of this command.\n" .
-				"(http://book.cakephp.org/)";
-			throw new Exception($message);
+		if (function_exists('ini_set')) {
+			ini_set('html_errors', false);
+			ini_set('implicit_flush', true);
+			ini_set('max_execution_time', 0);
 		}
 
 		$this->shiftArgs();
@@ -208,87 +192,6 @@ class ShellDispatcher {
 	}
 
 /**
- * Parses command line options and extracts the directory paths from $params
- *
- * @param array $args Parameters to parse
- * @return void
- */
-	public function parseParams($args) {
-		$this->_parsePaths($args);
-
-		$defaults = [
-			'app' => 'App',
-			'root' => dirname(dirname(dirname(__DIR__))),
-			'working' => null,
-			'webroot' => 'webroot'
-		];
-		$params = array_merge($defaults, array_intersect_key($this->params, $defaults));
-		$isWin = false;
-		foreach ($defaults as $default => $value) {
-			if (strpos($params[$default], '\\') !== false) {
-				$isWin = true;
-				break;
-			}
-		}
-		$params = str_replace('\\', '/', $params);
-
-		if (isset($params['working'])) {
-			$params['working'] = trim($params['working']);
-		}
-
-		if (!empty($params['working']) && (!isset($this->args[0]) || isset($this->args[0]) && $this->args[0][0] !== '.')) {
-			if ($params['working'][0] === '.') {
-				$params['working'] = realpath($params['working']);
-			}
-			if (empty($this->params['app']) && $params['working'] != $params['root']) {
-				$params['root'] = dirname($params['working']);
-				$params['app'] = basename($params['working']);
-			} else {
-				$params['root'] = $params['working'];
-			}
-		}
-
-		if ($params['app'][0] === '/' || preg_match('/([a-z])(:)/i', $params['app'], $matches)) {
-			$params['root'] = dirname($params['app']);
-		} elseif (strpos($params['app'], '/')) {
-			$params['root'] .= '/' . dirname($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)) {
-			$params = str_replace('/', '\\', $params);
-		}
-
-		$this->params = $params + $this->params;
-	}
-
-/**
- * Parses out the paths from from the argv
- *
- * @param array $args
- * @return void
- */
-	protected function _parsePaths($args) {
-		$parsed = [];
-		$keys = ['-working', '--working', '-app', '--app', '-root', '--root'];
-		foreach ($keys as $key) {
-			while (($index = array_search($key, $args)) !== false) {
-				$keyname = str_replace('-', '', $key);
-				$valueIndex = $index + 1;
-				$parsed[$keyname] = $args[$valueIndex];
-				array_splice($args, $index, 2);
-			}
-		}
-		$this->args = $args;
-		$this->params = $parsed;
-	}
-
-/**
  * Removes first argument and shifts other arguments up
  *
  * @return mixed Null if there are no arguments otherwise the shifted argument

+ 0 - 274
tests/TestCase/Console/ShellDispatcherTest.php

@@ -1,7 +1,5 @@
 <?php
 /**
- * ShellDispatcherTest file
- *
  * CakePHP(tm) Tests <http://book.cakephp.org/2.0/en/development/testing.html>
  * Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
  *
@@ -117,278 +115,6 @@ class ShellDispatcherTest extends TestCase {
 	}
 
 /**
- * testParseParams method
- *
- * @return void
- */
-	public function testParseParams() {
-		$Dispatcher = new TestShellDispatcher();
-
-		$params = array(
-			'/cake/1.2.x.x/cake/console/cake.php',
-			'bake',
-			'-app',
-			'new',
-			'-working',
-			'/var/www/htdocs'
-		);
-		$expected = array(
-			'app' => 'new',
-			'webroot' => 'webroot',
-			'working' => $this->_normalizePath('/var/www/htdocs/new'),
-			'root' => $this->_normalizePath('/var/www/htdocs')
-		);
-		$Dispatcher->parseParams($params);
-		$this->assertEquals($expected, $Dispatcher->params);
-
-		$params = array('cake.php');
-		$expected = array(
-			'app' => 'App',
-			'webroot' => 'webroot',
-			'working' => str_replace('\\', DS, dirname(CAKE_CORE_INCLUDE_PATH) . DS . 'App'),
-			'root' => str_replace('\\', DS, dirname(CAKE_CORE_INCLUDE_PATH)),
-		);
-		$Dispatcher->params = $Dispatcher->args = array();
-		$Dispatcher->parseParams($params);
-		$this->assertEquals($expected, $Dispatcher->params);
-
-		$params = array(
-			'cake.php',
-			'-app',
-			'new',
-		);
-		$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);
-
-		$params = array(
-			'./cake.php',
-			'bake',
-			'-app',
-			'new',
-			'-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);
-
-		$params = array(
-			'./console/cake.php',
-			'bake',
-			'-app',
-			'new',
-			'-working',
-			'/cake/1.2.x.x/cake'
-		);
-		$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);
-
-		$params = array(
-			'./console/cake.php',
-			'bake',
-			'-app',
-			'new',
-			'-dry',
-			'-working',
-			'/cake/1.2.x.x/cake'
-		);
-		$expected = array(
-			'app' => 'new',
-			'working' => str_replace('\\', DS, dirname(CAKE_CORE_INCLUDE_PATH) . DS . 'new'),
-			'root' => str_replace('\\', DS, dirname(CAKE_CORE_INCLUDE_PATH)),
-			'webroot' => 'webroot'
-		);
-		$Dispatcher->params = $Dispatcher->args = array();
-		$Dispatcher->parseParams($params);
-		$this->assertEquals($expected, $Dispatcher->params);
-
-		$params = array(
-			'./console/cake.php',
-			'-working',
-			'/cake/1.2.x.x/cake',
-			'schema',
-			'run',
-			'create',
-			'-dry',
-			'-f',
-			'-name',
-			'DbAcl'
-		);
-		$expected = array(
-			'app' => 'App',
-			'webroot' => 'webroot',
-			'working' => str_replace('\\', DS, dirname(CAKE_CORE_INCLUDE_PATH) . DS . 'App'),
-			'root' => str_replace('\\', DS, dirname(CAKE_CORE_INCLUDE_PATH)),
-		);
-		$Dispatcher->params = $Dispatcher->args = array();
-		$Dispatcher->parseParams($params);
-		$this->assertEquals($expected, $Dispatcher->params);
-
-		$expected = array(
-			'./console/cake.php', 'schema', 'run', 'create', '-dry', '-f', '-name', 'DbAcl'
-		);
-		$this->assertEquals($expected, $Dispatcher->args);
-
-		$params = array(
-			'/cake/1.2.x.x/cake/console/cake.php',
-			'-working',
-			'/cake/1.2.x.x/app',
-			'schema',
-			'run',
-			'create',
-			'-dry',
-			'-name',
-			'DbAcl'
-		);
-		$expected = array(
-			'app' => 'app',
-			'webroot' => 'webroot',
-			'working' => $this->_normalizePath('/cake/1.2.x.x/app'),
-			'root' => $this->_normalizePath('/cake/1.2.x.x'),
-		);
-		$Dispatcher->params = $Dispatcher->args = array();
-		$Dispatcher->parseParams($params);
-		$this->assertEquals($expected, $Dispatcher->params);
-
-		$params = array(
-			'cake.php',
-			'-working',
-			'C:/wamp/www/cake/app',
-			'bake',
-			'-app',
-			'C:/wamp/www/apps/cake/app',
-		);
-		$expected = array(
-			'app' => 'app',
-			'webroot' => 'webroot',
-			'working' => 'C:\wamp\www\apps\cake\app',
-			'root' => 'C:\wamp\www\apps\cake'
-		);
-
-		$Dispatcher->params = $Dispatcher->args = array();
-		$Dispatcher->parseParams($params);
-		$this->assertEquals($expected, $Dispatcher->params);
-
-		$params = array(
-			'cake.php',
-			'-working',
-			'C:\wamp\www\cake\app',
-			'bake',
-			'-app',
-			'C:\wamp\www\apps\cake\app',
-		);
-		$expected = array(
-			'app' => 'app',
-			'webroot' => 'webroot',
-			'working' => 'C:\wamp\www\apps\cake\app',
-			'root' => 'C:\wamp\www\apps\cake'
-		);
-		$Dispatcher->params = $Dispatcher->args = array();
-		$Dispatcher->parseParams($params);
-		$this->assertEquals($expected, $Dispatcher->params);
-
-		$params = array(
-			'cake.php',
-			'-working',
-			'C:\wamp\www\apps',
-			'bake',
-			'-app',
-			'cake\app',
-			'-url',
-			'http://example.com/some/url/with/a/path'
-		);
-		$expected = array(
-			'app' => 'app',
-			'webroot' => 'webroot',
-			'working' => 'C:\wamp\www\apps\cake\app',
-			'root' => 'C:\wamp\www\apps\cake',
-		);
-		$Dispatcher->params = $Dispatcher->args = array();
-		$Dispatcher->parseParams($params);
-		$this->assertEquals($expected, $Dispatcher->params);
-
-		$params = array(
-			'/home/amelo/dev/cake-common/cake/console/cake.php',
-			'-root',
-			'/home/amelo/dev/lsbu-vacancy',
-			'-working',
-			'/home/amelo/dev/lsbu-vacancy',
-			'-app',
-			'app',
-		);
-		$expected = array(
-			'app' => 'app',
-			'webroot' => 'webroot',
-			'working' => '/home/amelo/dev/lsbu-vacancy/app',
-			'root' => '/home/amelo/dev/lsbu-vacancy',
-		);
-		$Dispatcher->params = $Dispatcher->args = array();
-		$Dispatcher->parseParams($params);
-		$this->assertEquals($expected, $Dispatcher->params);
-
-		$params = array(
-			'/cake/1.2.x.x/cake/console/cake.php',
-			'bake',
-			'-app',
-			'new',
-			'-app',
-			'old',
-			'-working',
-			'/var/www/htdocs'
-		);
-		$expected = array(
-			'app' => 'old',
-			'webroot' => 'webroot',
-			'working' => $this->_normalizePath('/var/www/htdocs/old'),
-			'root' => $this->_normalizePath('/var/www/htdocs')
-		);
-		$Dispatcher->parseParams($params);
-		$this->assertEquals($expected, $Dispatcher->params);
-
-		if (DS === '\\') {
-			$params = array(
-				'cake.php',
-				'-working',
-				'D:\www',
-				'bake',
-				'my_app',
-			);
-			$expected = array(
-				'working' => 'D:\\\\www',
-				'app' => 'www',
-				'root' => 'D:\\',
-				'webroot' => 'webroot'
-			);
-
-			$Dispatcher->params = $Dispatcher->args = array();
-			$Dispatcher->parseParams($params);
-			$this->assertEquals($expected, $Dispatcher->params);
-		}
-	}
-
-/**
  * Verify loading of (plugin-) shells
  *
  * @return void