mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2024-11-15 03:18:26 +00:00
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:
parent
db6149a5e8
commit
e807cc0eca
14 changed files with 28 additions and 225 deletions
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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
|
||||
*
|
|
@ -160,7 +160,7 @@ class ProjectTask extends Shell {
|
|||
$this->out(sprintf(__('<success>Created:</success> %s in %s'), $app, $path));
|
||||
$this->hr();
|
||||
} else {
|
||||
$this->err(sprintf(__(" '%s' could not be created properly"), $app));
|
||||
$this->err(sprintf(__("<error>Could not create</error> '%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')) {
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -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');
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -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';
|
||||
|
||||
|
|
|
@ -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';
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
|
||||
|
|
|
@ -93,7 +93,6 @@ class ModelTaskTest extends CakeTestCase {
|
|||
|
||||
$this->Task->name = 'ModelTask';
|
||||
$this->Task->interactive = true;
|
||||
$this->Task->Dispatch->shellPaths = App::path('shells');
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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));
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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';
|
||||
}
|
||||
|
|
|
@ -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');
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in a new issue