diff --git a/cake/console/shell_dispatcher.php b/cake/console/shell_dispatcher.php
index 4704213c9..c67153d31 100644
--- a/cake/console/shell_dispatcher.php
+++ b/cake/console/shell_dispatcher.php
@@ -42,61 +42,6 @@ class ShellDispatcher {
*/
public $args = array();
-/**
- * The file name of the shell that was invoked.
- *
- * @var string
- * @access public
- */
- public $shell = null;
-
-/**
- * The class name of the shell that was invoked.
- *
- * @var string
- * @access public
- */
- public $shellClass = null;
-
-/**
- * The command called if public methods are available.
- *
- * @var string
- * @access public
- */
- public $shellCommand = null;
-
-/**
- * The path locations of shells.
- *
- * @var array
- * @access public
- */
- public $shellPaths = array();
-
-/**
- * The path to the current shell location.
- *
- * @var string
- * @access public
- */
- public $shellPath = null;
-
-/**
- * The name of the shell in camelized.
- *
- * @var string
- * @access public
- */
- public $shellName = null;
-
-/**
- * TaskCollection object for the command
- *
- * @var TaskCollection
- */
- protected $_Tasks;
-
/**
* Constructor
*
@@ -116,7 +61,6 @@ class ShellDispatcher {
if ($bootstrap) {
$this->_initEnvironment();
}
- $this->__buildPaths();
}
/**
@@ -179,35 +123,6 @@ class ShellDispatcher {
$this->shiftArgs();
}
-/**
- * Builds the shell paths.
- *
- * @access private
- * @return void
- */
- function __buildPaths() {
- $paths = array();
-
- $plugins = App::objects('plugin', null, false);
- foreach ((array)$plugins as $plugin) {
- $pluginPath = App::pluginPath($plugin);
- $path = $pluginPath . 'vendors' . DS . 'shells' . DS;
- if (file_exists($path)) {
- $paths[] = $path;
- }
- }
-
- $vendorPaths = array_values(App::path('vendors'));
- foreach ($vendorPaths as $vendorPath) {
- $path = rtrim($vendorPath, DS) . DS . 'shells' . DS;
- if (file_exists($path)) {
- $paths[] = $path;
- }
- }
-
- $this->shellPaths = array_values(array_unique(array_merge($paths, App::path('shells'))));
- }
-
/**
* Initializes the environment and loads the Cake core.
*
@@ -257,12 +172,7 @@ class ShellDispatcher {
return true;
}
- list($plugin, $shell) = pluginSplit($shell);
- $this->shell = $shell;
- $this->shellName = Inflector::camelize($shell);
- $this->shellClass = $this->shellName . 'Shell';
-
- $Shell = $this->_getShell($plugin);
+ $Shell = $this->_getShell($shell);
$command = null;
if (isset($this->args[0])) {
@@ -289,43 +199,31 @@ class ShellDispatcher {
return $Shell->main();
}
}
- throw new MissingShellMethodException(array('shell' => $this->shell, 'method' => $arg));
+ throw new MissingShellMethodException(array('shell' => $shell, 'method' => $arg));
}
/**
* Get shell to use, either plugin shell or application shell
*
- * All paths in the shellPaths property are searched.
- * shell, shellPath and shellClass properties are taken into account.
+ * All paths in the loaded shell paths are searched.
*
- * @param string $plugin Optionally the name of a plugin
+ * @param string $shell Optionally the name of a plugin
* @return mixed False if no shell could be found or an object on success
+ * @throws MissingShellFileException, MissingShellClassException when errors are encountered.
*/
- protected function _getShell($plugin = null) {
- foreach ($this->shellPaths as $path) {
- $this->shellPath = $path . $this->shell . '.php';
- $pluginShellPath = DS . $plugin . DS . 'vendors' . DS . 'shells' . DS;
+ protected function _getShell($shell) {
+ list($plugin, $shell) = pluginSplit($shell, true);
- if ((strpos($path, $pluginShellPath) !== false || !$plugin) && file_exists($this->shellPath)) {
- $loaded = true;
- break;
- }
+ $loaded = App::import('Shell', $plugin . $shell);
+ $class = Inflector::camelize($shell) . 'Shell';
+
+ if (!$loaded) {
+ throw new MissingShellFileException(array('shell' => $shell));
}
- if (!isset($loaded)) {
- throw new MissingShellFileException(array('shell' => $this->shell . '.php'));
+ if (!class_exists($class)) {
+ throw new MissingShellClassException(array('shell' => $class));
}
-
- if (!class_exists('Shell')) {
- require_once CONSOLE_LIBS . 'shell.php';
- }
-
- if (!class_exists($this->shellClass)) {
- require $this->shellPath;
- }
- if (!class_exists($this->shellClass)) {
- throw new MissingShellClassException(array('shell' => $this->shell));
- }
- $Shell = new $this->shellClass($this);
+ $Shell = new $class($this);
return $Shell;
}
diff --git a/cake/console/libs/shell.php b/cake/console/shells/shell.php
similarity index 94%
rename from cake/console/libs/shell.php
rename to cake/console/shells/shell.php
index 42cad33d5..525644f3b 100644
--- a/cake/console/libs/shell.php
+++ b/cake/console/shells/shell.php
@@ -76,29 +76,6 @@ class Shell extends Object {
*/
public $args = array();
-/**
- * Shell paths
- *
- * @var string
- */
- public $shellPaths = array();
-
-/**
- * The file name of the shell that was invoked.
- *
- * @var string
- * @access public
- */
- public $shell = null;
-
-/**
- * The command called if public methods are available.
- *
- * @var string
- * @access public
- */
- public $command = null;
-
/**
* The name of the shell in camelized.
*
@@ -171,16 +148,6 @@ class Shell extends Object {
*
*/
function __construct(&$dispatch, $stdout = null, $stderr = null, $stdin = null) {
- $vars = array('shell', 'shellCommand' => 'command', 'shellPaths');
-
- foreach ($vars as $key => $var) {
- if (is_string($key)) {
- $this->{$var} = $dispatch->{$key};
- } else {
- $this->{$var} = $dispatch->{$var};
- }
- }
-
if ($this->name == null) {
$this->name = Inflector::underscore(str_replace(array('Shell', 'Task'), '', get_class($this)));
}
@@ -590,25 +557,6 @@ class Shell extends Object {
}
}
-/**
- * Will check the number args matches otherwise throw an error
- *
- * @param integer $expectedNum Expected number of paramters
- * @param string $command Command
- */
- protected function _checkArgs($expectedNum, $command = null) {
- if (!$command) {
- $command = $this->command;
- }
- if (count($this->args) < $expectedNum) {
- $message[] = "Got: " . count($this->args);
- $message[] = "Expected: {$expectedNum}";
- $message[] = "Please type `cake {$this->shell} help` for help";
- $message[] = "on usage of the {$this->name} {$command}.";
- $this->error('Wrong number of parameters', $message);
- }
- }
-
/**
* Creates a file at given path
*
diff --git a/cake/console/shells/tasks/project.php b/cake/console/shells/tasks/project.php
index d0ab7e120..12f9050d1 100644
--- a/cake/console/shells/tasks/project.php
+++ b/cake/console/shells/tasks/project.php
@@ -160,7 +160,7 @@ class ProjectTask extends Shell {
$this->out(sprintf(__('Created: %s in %s'), $app, $path));
$this->hr();
} else {
- $this->err(sprintf(__(" '%s' could not be created properly"), $app));
+ $this->err(sprintf(__("Could not create '%s' properly."), $app));
return false;
}
@@ -198,7 +198,7 @@ class ProjectTask extends Shell {
* @return boolean Success
*/
public function securitySalt($path) {
- $File =& new File($path . 'config' . DS . 'core.php');
+ $File = new File($path . 'config' . DS . 'core.php');
$contents = $File->read();
if (preg_match('/([\s]*Configure::write\(\'Security.salt\',[\s\'A-z0-9]*\);)/', $contents, $match)) {
if (!class_exists('Security')) {
@@ -221,7 +221,7 @@ class ProjectTask extends Shell {
* @return boolean Success
*/
public function securityCipherSeed($path) {
- $File =& new File($path . 'config' . DS . 'core.php');
+ $File = new File($path . 'config' . DS . 'core.php');
$contents = $File->read();
if (preg_match('/([\s]*Configure::write\(\'Security.cipherSeed\',[\s\'A-z0-9]*\);)/', $contents, $match)) {
if (!class_exists('Security')) {
diff --git a/cake/tests/cases/console/shell_dispatcher.test.php b/cake/tests/cases/console/shell_dispatcher.test.php
index 2b6b354f6..2da5bbe81 100644
--- a/cake/tests/cases/console/shell_dispatcher.test.php
+++ b/cake/tests/cases/console/shell_dispatcher.test.php
@@ -17,9 +17,7 @@
* @since CakePHP(tm) v 1.2.0.5432
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
*/
-
require_once CAKE . 'console' . DS . 'shell_dispatcher.php';
-require_once CONSOLE_LIBS . 'shell.php';
/**
* TestShellDispatcher class
@@ -83,11 +81,11 @@ class TestShellDispatcher extends ShellDispatcher {
/**
* getShell
*
- * @param mixed $plugin
+ * @param mixed $shell
* @return mixed
*/
- public function getShell($plugin = null) {
- return $this->_getShell($plugin);
+ public function getShell($shell) {
+ return $this->_getShell($shell);
}
/**
@@ -96,11 +94,11 @@ class TestShellDispatcher extends ShellDispatcher {
* @param mixed $plugin
* @return mixed
*/
- protected function _getShell($plugin = null) {
+ protected function _getShell($shell) {
if (isset($this->TestShell)) {
return $this->TestShell;
}
- return parent::_getShell($plugin);
+ return parent::_getShell($shell);
}
}
@@ -125,7 +123,7 @@ class ShellDispatcherTest extends CakeTestCase {
),
'shells' => array(
CORE_PATH ? CONSOLE_LIBS : ROOT . DS . CONSOLE_LIBS,
- TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'vendors' . DS . 'shells' . DS
+ TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'console' . DS . 'shells' . DS
)
), true);
}
@@ -381,28 +379,6 @@ class ShellDispatcherTest extends CakeTestCase {
$this->assertEqual($expected, $Dispatcher->params);
}
-/**
- * testBuildPaths method
- *
- * @return void
- */
- public function testBuildPaths() {
- $Dispatcher = new TestShellDispatcher();
-
- $result = $Dispatcher->shellPaths;
-
- $expected = array(
- TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'plugins' . DS . 'test_plugin' . DS . 'vendors' . DS . 'shells' . DS,
- TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'plugins' . DS . 'test_plugin_two' . DS . 'vendors' . DS . 'shells' . DS,
- APP . 'vendors' . DS . 'shells' . DS,
- VENDORS . 'shells' . DS,
- CORE_PATH ? CONSOLE_LIBS : ROOT . DS . CONSOLE_LIBS,
- TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'vendors' . DS . 'shells' . DS,
- );
- $this->assertIdentical(array_diff($result, $expected), array());
- $this->assertIdentical(array_diff($expected, $result), array());
- }
-
/**
* Verify loading of (plugin-) shells
*
@@ -414,21 +390,12 @@ class ShellDispatcherTest extends CakeTestCase {
$Dispatcher = new TestShellDispatcher();
- $Dispatcher->shell = 'sample';
- $Dispatcher->shellName = 'Sample';
- $Dispatcher->shellClass = 'SampleShell';
-
- $result = $Dispatcher->getShell();
- $this->assertIsA($result, 'SampleShell');
+ $result = $Dispatcher->getShell('sample');
+ $this->assertInstanceOf('SampleShell', $result);
$Dispatcher = new TestShellDispatcher();
-
- $Dispatcher->shell = 'example';
- $Dispatcher->shellName = 'Example';
- $Dispatcher->shellClass = 'ExampleShell';
-
- $result = $Dispatcher->getShell('test_plugin');
- $this->assertIsA($result, 'ExampleShell');
+ $result = $Dispatcher->getShell('test_plugin.example');
+ $this->assertInstanceOf('ExampleShell', $result);
}
/**
diff --git a/cake/tests/cases/console/shells/bake.test.php b/cake/tests/cases/console/shells/bake.test.php
index ec124251e..c5a04e887 100644
--- a/cake/tests/cases/console/shells/bake.test.php
+++ b/cake/tests/cases/console/shells/bake.test.php
@@ -62,7 +62,6 @@ class BakeShellTest extends CakeTestCase {
array('in', 'out', 'hr', 'err', 'createFile', '_stop', '_checkUnitTest'),
array(&$this->Dispatcher, $out, $out, $in)
);
- $this->Shell->Dispatch->shellPaths = App::path('shells');
}
/**
diff --git a/cake/tests/cases/console/shells/tasks/controller.test.php b/cake/tests/cases/console/shells/tasks/controller.test.php
index e625b0db1..d4e2f348f 100644
--- a/cake/tests/cases/console/shells/tasks/controller.test.php
+++ b/cake/tests/cases/console/shells/tasks/controller.test.php
@@ -76,7 +76,6 @@ class ControllerTaskTest extends CakeTestCase {
array(&$this->Dispatcher, $out, $out, $in)
);
$this->Task->name = 'ControllerTask';
- $this->Task->Dispatch->shellPaths = App::path('shells');
$this->Task->Template = new TemplateTask($this->Dispatcher, $out, $out, $in);
$this->Task->Template->params['theme'] = 'default';
diff --git a/cake/tests/cases/console/shells/tasks/db_config.test.php b/cake/tests/cases/console/shells/tasks/db_config.test.php
index e74b94d95..f20434390 100644
--- a/cake/tests/cases/console/shells/tasks/db_config.test.php
+++ b/cake/tests/cases/console/shells/tasks/db_config.test.php
@@ -68,7 +68,6 @@ class DbConfigTaskTest extends CakeTestCase {
array('in', 'out', 'err', 'hr', 'createFile', '_stop', '_checkUnitTest', '_verify'),
array(&$this->Dispatcher, $out, $out, $in)
);
- $this->Task->Dispatch->shellPaths = App::path('shells');
$this->Task->params['working'] = rtrim(APP, DS);
$this->Task->databaseClassName = 'TEST_DATABASE_CONFIG';
diff --git a/cake/tests/cases/console/shells/tasks/fixture.test.php b/cake/tests/cases/console/shells/tasks/fixture.test.php
index 9386ae570..b52f5ff94 100644
--- a/cake/tests/cases/console/shells/tasks/fixture.test.php
+++ b/cake/tests/cases/console/shells/tasks/fixture.test.php
@@ -63,7 +63,6 @@ class FixtureTaskTest extends CakeTestCase {
);
$this->Task->Template = new TemplateTask($this->Dispatcher, $out, $out, $in);
$this->Task->DbConfig = $this->getMock('DbConfigTask', array(), array(&$this->Dispatcher, $out, $out, $in));
- $this->Task->Dispatch->shellPaths = App::path('shells');
$this->Task->Template->initialize();
}
diff --git a/cake/tests/cases/console/shells/tasks/model.test.php b/cake/tests/cases/console/shells/tasks/model.test.php
index e7700ce24..9dec253b0 100644
--- a/cake/tests/cases/console/shells/tasks/model.test.php
+++ b/cake/tests/cases/console/shells/tasks/model.test.php
@@ -93,7 +93,6 @@ class ModelTaskTest extends CakeTestCase {
$this->Task->name = 'ModelTask';
$this->Task->interactive = true;
- $this->Task->Dispatch->shellPaths = App::path('shells');
}
/**
diff --git a/cake/tests/cases/console/shells/tasks/project.test.php b/cake/tests/cases/console/shells/tasks/project.test.php
index 7f64abb47..b6518d86d 100644
--- a/cake/tests/cases/console/shells/tasks/project.test.php
+++ b/cake/tests/cases/console/shells/tasks/project.test.php
@@ -49,7 +49,6 @@ class ProjectTaskTest extends CakeTestCase {
array('in', 'err', 'createFile', '_stop'),
array(&$this->Dispatcher, $out, $out, $in)
);
- $this->Dispatcher->shellPaths = App::path('shells');
$this->Task->path = TMP . 'tests' . DS;
}
diff --git a/cake/tests/cases/console/shells/tasks/template.test.php b/cake/tests/cases/console/shells/tasks/template.test.php
index c5c0eed16..08cba89e5 100644
--- a/cake/tests/cases/console/shells/tasks/template.test.php
+++ b/cake/tests/cases/console/shells/tasks/template.test.php
@@ -90,7 +90,6 @@ class TemplateTaskTest extends CakeTestCase {
*/
public function testFindingInstalledThemesForBake() {
$consoleLibs = CAKE_CORE_INCLUDE_PATH . DS . CAKE . 'console' . DS;
- $this->Task->Dispatch->shellPaths = array($consoleLibs);
$this->Task->initialize();
$this->assertEqual($this->Task->templatePaths, array('default' => $consoleLibs . 'templates' . DS . 'default' . DS));
}
diff --git a/cake/tests/cases/console/shells/tasks/test.test.php b/cake/tests/cases/console/shells/tasks/test.test.php
index 15319c93f..3fb5e7ce3 100644
--- a/cake/tests/cases/console/shells/tasks/test.test.php
+++ b/cake/tests/cases/console/shells/tasks/test.test.php
@@ -250,7 +250,6 @@ class TestTaskTest extends CakeTestCase {
array('in', 'err', 'createFile', '_stop', 'isLoadableClass'),
array(&$this->Dispatcher, $out, $out, $in)
);
- $this->Dispatcher->shellPaths = App::path('shells');
$this->Task->name = 'TestTask';
$this->Task->Template = new TemplateTask($this->Dispatcher, $out, $out, $in);
}
diff --git a/cake/tests/cases/console/shells/tasks/view.test.php b/cake/tests/cases/console/shells/tasks/view.test.php
index c4878d3a5..33219f004 100644
--- a/cake/tests/cases/console/shells/tasks/view.test.php
+++ b/cake/tests/cases/console/shells/tasks/view.test.php
@@ -237,7 +237,6 @@ class ViewTaskTest extends CakeTestCase {
$this->Task->Project = $this->getMock('ProjectTask', array(), array(&$this->Dispatcher, $out, $out, $in));
$this->Task->DbConfig = $this->getMock('DbConfigTask', array(), array(&$this->Dispatcher, $out, $out, $in));
- $this->Dispatcher->shellPaths = App::path('shells');
$this->Task->path = TMP;
$this->Task->Template->params['theme'] = 'default';
}
diff --git a/cake/tests/cases/console/shells/testsuite.test.php b/cake/tests/cases/console/shells/testsuite.test.php
index 9e2d4d863..88b9b7e85 100644
--- a/cake/tests/cases/console/shells/testsuite.test.php
+++ b/cake/tests/cases/console/shells/testsuite.test.php
@@ -42,7 +42,6 @@ class TestSuiteShellTest extends CakeTestCase {
array('in', 'out', 'hr', 'help', 'error', 'err', '_stop', 'initialize', 'run', 'clear'),
array(&$this->Dispatcher)
);
- $this->Shell->Dispatch->shellPaths = App::path('shells');
}
/**