Removing a bunch of dead properties from ShellDispatcher and Shell.

They are no longer needed/used.
Moving Shell back to console/shells so App::import() can easily find it.
This commit is contained in:
mark_story 2010-10-17 21:04:14 -04:00
parent db6149a5e8
commit e807cc0eca
14 changed files with 28 additions and 225 deletions

View file

@ -42,61 +42,6 @@ class ShellDispatcher {
*/ */
public $args = array(); 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 * Constructor
* *
@ -116,7 +61,6 @@ class ShellDispatcher {
if ($bootstrap) { if ($bootstrap) {
$this->_initEnvironment(); $this->_initEnvironment();
} }
$this->__buildPaths();
} }
/** /**
@ -179,35 +123,6 @@ class ShellDispatcher {
$this->shiftArgs(); $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. * Initializes the environment and loads the Cake core.
* *
@ -257,12 +172,7 @@ class ShellDispatcher {
return true; return true;
} }
list($plugin, $shell) = pluginSplit($shell); $Shell = $this->_getShell($shell);
$this->shell = $shell;
$this->shellName = Inflector::camelize($shell);
$this->shellClass = $this->shellName . 'Shell';
$Shell = $this->_getShell($plugin);
$command = null; $command = null;
if (isset($this->args[0])) { if (isset($this->args[0])) {
@ -289,43 +199,31 @@ class ShellDispatcher {
return $Shell->main(); 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 * Get shell to use, either plugin shell or application shell
* *
* All paths in the shellPaths property are searched. * All paths in the loaded shell paths are searched.
* shell, shellPath and shellClass properties are taken into account.
* *
* @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 * @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) { protected function _getShell($shell) {
foreach ($this->shellPaths as $path) { list($plugin, $shell) = pluginSplit($shell, true);
$this->shellPath = $path . $this->shell . '.php';
$pluginShellPath = DS . $plugin . DS . 'vendors' . DS . 'shells' . DS;
if ((strpos($path, $pluginShellPath) !== false || !$plugin) && file_exists($this->shellPath)) { $loaded = App::import('Shell', $plugin . $shell);
$loaded = true; $class = Inflector::camelize($shell) . 'Shell';
break;
}
}
if (!isset($loaded)) {
throw new MissingShellFileException(array('shell' => $this->shell . '.php'));
}
if (!class_exists('Shell')) { if (!$loaded) {
require_once CONSOLE_LIBS . 'shell.php'; throw new MissingShellFileException(array('shell' => $shell));
} }
if (!class_exists($class)) {
if (!class_exists($this->shellClass)) { throw new MissingShellClassException(array('shell' => $class));
require $this->shellPath;
} }
if (!class_exists($this->shellClass)) { $Shell = new $class($this);
throw new MissingShellClassException(array('shell' => $this->shell));
}
$Shell = new $this->shellClass($this);
return $Shell; return $Shell;
} }

View file

@ -76,29 +76,6 @@ class Shell extends Object {
*/ */
public $args = array(); 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. * The name of the shell in camelized.
* *
@ -171,16 +148,6 @@ class Shell extends Object {
* *
*/ */
function __construct(&$dispatch, $stdout = null, $stderr = null, $stdin = null) { 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) { if ($this->name == null) {
$this->name = Inflector::underscore(str_replace(array('Shell', 'Task'), '', get_class($this))); $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 * Creates a file at given path
* *

View file

@ -160,7 +160,7 @@ class ProjectTask extends Shell {
$this->out(sprintf(__('<success>Created:</success> %s in %s'), $app, $path)); $this->out(sprintf(__('<success>Created:</success> %s in %s'), $app, $path));
$this->hr(); $this->hr();
} else { } else {
$this->err(sprintf(__(" '%s' could not be created properly"), $app)); $this->err(sprintf(__("<error>Could not create</error> '%s' properly."), $app));
return false; return false;
} }
@ -198,7 +198,7 @@ class ProjectTask extends Shell {
* @return boolean Success * @return boolean Success
*/ */
public function securitySalt($path) { public function securitySalt($path) {
$File =& new File($path . 'config' . DS . 'core.php'); $File = new File($path . 'config' . DS . 'core.php');
$contents = $File->read(); $contents = $File->read();
if (preg_match('/([\s]*Configure::write\(\'Security.salt\',[\s\'A-z0-9]*\);)/', $contents, $match)) { if (preg_match('/([\s]*Configure::write\(\'Security.salt\',[\s\'A-z0-9]*\);)/', $contents, $match)) {
if (!class_exists('Security')) { if (!class_exists('Security')) {
@ -221,7 +221,7 @@ class ProjectTask extends Shell {
* @return boolean Success * @return boolean Success
*/ */
public function securityCipherSeed($path) { public function securityCipherSeed($path) {
$File =& new File($path . 'config' . DS . 'core.php'); $File = new File($path . 'config' . DS . 'core.php');
$contents = $File->read(); $contents = $File->read();
if (preg_match('/([\s]*Configure::write\(\'Security.cipherSeed\',[\s\'A-z0-9]*\);)/', $contents, $match)) { if (preg_match('/([\s]*Configure::write\(\'Security.cipherSeed\',[\s\'A-z0-9]*\);)/', $contents, $match)) {
if (!class_exists('Security')) { if (!class_exists('Security')) {

View file

@ -17,9 +17,7 @@
* @since CakePHP(tm) v 1.2.0.5432 * @since CakePHP(tm) v 1.2.0.5432
* @license MIT License (http://www.opensource.org/licenses/mit-license.php) * @license MIT License (http://www.opensource.org/licenses/mit-license.php)
*/ */
require_once CAKE . 'console' . DS . 'shell_dispatcher.php'; require_once CAKE . 'console' . DS . 'shell_dispatcher.php';
require_once CONSOLE_LIBS . 'shell.php';
/** /**
* TestShellDispatcher class * TestShellDispatcher class
@ -83,11 +81,11 @@ class TestShellDispatcher extends ShellDispatcher {
/** /**
* getShell * getShell
* *
* @param mixed $plugin * @param mixed $shell
* @return mixed * @return mixed
*/ */
public function getShell($plugin = null) { public function getShell($shell) {
return $this->_getShell($plugin); return $this->_getShell($shell);
} }
/** /**
@ -96,11 +94,11 @@ class TestShellDispatcher extends ShellDispatcher {
* @param mixed $plugin * @param mixed $plugin
* @return mixed * @return mixed
*/ */
protected function _getShell($plugin = null) { protected function _getShell($shell) {
if (isset($this->TestShell)) { if (isset($this->TestShell)) {
return $this->TestShell; return $this->TestShell;
} }
return parent::_getShell($plugin); return parent::_getShell($shell);
} }
} }
@ -125,7 +123,7 @@ class ShellDispatcherTest extends CakeTestCase {
), ),
'shells' => array( 'shells' => array(
CORE_PATH ? CONSOLE_LIBS : ROOT . DS . CONSOLE_LIBS, 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); ), true);
} }
@ -381,28 +379,6 @@ class ShellDispatcherTest extends CakeTestCase {
$this->assertEqual($expected, $Dispatcher->params); $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 * Verify loading of (plugin-) shells
* *
@ -414,21 +390,12 @@ class ShellDispatcherTest extends CakeTestCase {
$Dispatcher = new TestShellDispatcher(); $Dispatcher = new TestShellDispatcher();
$Dispatcher->shell = 'sample'; $result = $Dispatcher->getShell('sample');
$Dispatcher->shellName = 'Sample'; $this->assertInstanceOf('SampleShell', $result);
$Dispatcher->shellClass = 'SampleShell';
$result = $Dispatcher->getShell();
$this->assertIsA($result, 'SampleShell');
$Dispatcher = new TestShellDispatcher(); $Dispatcher = new TestShellDispatcher();
$result = $Dispatcher->getShell('test_plugin.example');
$Dispatcher->shell = 'example'; $this->assertInstanceOf('ExampleShell', $result);
$Dispatcher->shellName = 'Example';
$Dispatcher->shellClass = 'ExampleShell';
$result = $Dispatcher->getShell('test_plugin');
$this->assertIsA($result, 'ExampleShell');
} }
/** /**

View file

@ -62,7 +62,6 @@ class BakeShellTest extends CakeTestCase {
array('in', 'out', 'hr', 'err', 'createFile', '_stop', '_checkUnitTest'), array('in', 'out', 'hr', 'err', 'createFile', '_stop', '_checkUnitTest'),
array(&$this->Dispatcher, $out, $out, $in) array(&$this->Dispatcher, $out, $out, $in)
); );
$this->Shell->Dispatch->shellPaths = App::path('shells');
} }
/** /**

View file

@ -76,7 +76,6 @@ class ControllerTaskTest extends CakeTestCase {
array(&$this->Dispatcher, $out, $out, $in) array(&$this->Dispatcher, $out, $out, $in)
); );
$this->Task->name = 'ControllerTask'; $this->Task->name = 'ControllerTask';
$this->Task->Dispatch->shellPaths = App::path('shells');
$this->Task->Template = new TemplateTask($this->Dispatcher, $out, $out, $in); $this->Task->Template = new TemplateTask($this->Dispatcher, $out, $out, $in);
$this->Task->Template->params['theme'] = 'default'; $this->Task->Template->params['theme'] = 'default';

View file

@ -68,7 +68,6 @@ class DbConfigTaskTest extends CakeTestCase {
array('in', 'out', 'err', 'hr', 'createFile', '_stop', '_checkUnitTest', '_verify'), array('in', 'out', 'err', 'hr', 'createFile', '_stop', '_checkUnitTest', '_verify'),
array(&$this->Dispatcher, $out, $out, $in) array(&$this->Dispatcher, $out, $out, $in)
); );
$this->Task->Dispatch->shellPaths = App::path('shells');
$this->Task->params['working'] = rtrim(APP, DS); $this->Task->params['working'] = rtrim(APP, DS);
$this->Task->databaseClassName = 'TEST_DATABASE_CONFIG'; $this->Task->databaseClassName = 'TEST_DATABASE_CONFIG';

View file

@ -63,7 +63,6 @@ class FixtureTaskTest extends CakeTestCase {
); );
$this->Task->Template = new TemplateTask($this->Dispatcher, $out, $out, $in); $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->DbConfig = $this->getMock('DbConfigTask', array(), array(&$this->Dispatcher, $out, $out, $in));
$this->Task->Dispatch->shellPaths = App::path('shells');
$this->Task->Template->initialize(); $this->Task->Template->initialize();
} }

View file

@ -93,7 +93,6 @@ class ModelTaskTest extends CakeTestCase {
$this->Task->name = 'ModelTask'; $this->Task->name = 'ModelTask';
$this->Task->interactive = true; $this->Task->interactive = true;
$this->Task->Dispatch->shellPaths = App::path('shells');
} }
/** /**

View file

@ -49,7 +49,6 @@ class ProjectTaskTest extends CakeTestCase {
array('in', 'err', 'createFile', '_stop'), array('in', 'err', 'createFile', '_stop'),
array(&$this->Dispatcher, $out, $out, $in) array(&$this->Dispatcher, $out, $out, $in)
); );
$this->Dispatcher->shellPaths = App::path('shells');
$this->Task->path = TMP . 'tests' . DS; $this->Task->path = TMP . 'tests' . DS;
} }

View file

@ -90,7 +90,6 @@ class TemplateTaskTest extends CakeTestCase {
*/ */
public function testFindingInstalledThemesForBake() { public function testFindingInstalledThemesForBake() {
$consoleLibs = CAKE_CORE_INCLUDE_PATH . DS . CAKE . 'console' . DS; $consoleLibs = CAKE_CORE_INCLUDE_PATH . DS . CAKE . 'console' . DS;
$this->Task->Dispatch->shellPaths = array($consoleLibs);
$this->Task->initialize(); $this->Task->initialize();
$this->assertEqual($this->Task->templatePaths, array('default' => $consoleLibs . 'templates' . DS . 'default' . DS)); $this->assertEqual($this->Task->templatePaths, array('default' => $consoleLibs . 'templates' . DS . 'default' . DS));
} }

View file

@ -250,7 +250,6 @@ class TestTaskTest extends CakeTestCase {
array('in', 'err', 'createFile', '_stop', 'isLoadableClass'), array('in', 'err', 'createFile', '_stop', 'isLoadableClass'),
array(&$this->Dispatcher, $out, $out, $in) array(&$this->Dispatcher, $out, $out, $in)
); );
$this->Dispatcher->shellPaths = App::path('shells');
$this->Task->name = 'TestTask'; $this->Task->name = 'TestTask';
$this->Task->Template = new TemplateTask($this->Dispatcher, $out, $out, $in); $this->Task->Template = new TemplateTask($this->Dispatcher, $out, $out, $in);
} }

View file

@ -237,7 +237,6 @@ class ViewTaskTest extends CakeTestCase {
$this->Task->Project = $this->getMock('ProjectTask', array(), array(&$this->Dispatcher, $out, $out, $in)); $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->Task->DbConfig = $this->getMock('DbConfigTask', array(), array(&$this->Dispatcher, $out, $out, $in));
$this->Dispatcher->shellPaths = App::path('shells');
$this->Task->path = TMP; $this->Task->path = TMP;
$this->Task->Template->params['theme'] = 'default'; $this->Task->Template->params['theme'] = 'default';
} }

View file

@ -42,7 +42,6 @@ class TestSuiteShellTest extends CakeTestCase {
array('in', 'out', 'hr', 'help', 'error', 'err', '_stop', 'initialize', 'run', 'clear'), array('in', 'out', 'hr', 'help', 'error', 'err', '_stop', 'initialize', 'run', 'clear'),
array(&$this->Dispatcher) array(&$this->Dispatcher)
); );
$this->Shell->Dispatch->shellPaths = App::path('shells');
} }
/** /**