mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2024-11-15 11:28:25 +00:00
Making TaskCollection require a Shell instead of a ShellDispatcher.
This will help reduce the coupling between ShellDispatcher and other objects. Since ShellDispatcher never directly uses or interacts with TaskCollection, it doesn't make much sense for it to have one. Instead shells will either get their own, or be passed one in.
This commit is contained in:
parent
b6602f1d0d
commit
a55098b00b
2 changed files with 13 additions and 14 deletions
|
@ -20,11 +20,11 @@ App::import('Core', 'ObjectCollection');
|
||||||
|
|
||||||
class TaskCollection extends ObjectCollection {
|
class TaskCollection extends ObjectCollection {
|
||||||
/**
|
/**
|
||||||
* Shell Dispatcher to give to tasks. and use to find tasks.
|
* Shell to give to tasks. and use to find tasks.
|
||||||
*
|
*
|
||||||
* @var array
|
* @var array
|
||||||
*/
|
*/
|
||||||
protected $_Dispatch;
|
protected $_Shell;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor
|
* Constructor
|
||||||
|
@ -32,8 +32,8 @@ class TaskCollection extends ObjectCollection {
|
||||||
* @param array $paths Array of paths to search for tasks on .
|
* @param array $paths Array of paths to search for tasks on .
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function __construct(ShellDispatcher $Dispatcher) {
|
public function __construct(Shell $Shell) {
|
||||||
$this->_Dispatch = $Dispatcher;
|
$this->_Shell = $Shell;
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* Loads/constructs a task. Will return the instance in the registry if it already exists.
|
* Loads/constructs a task. Will return the instance in the registry if it already exists.
|
||||||
|
@ -60,7 +60,7 @@ class TaskCollection extends ObjectCollection {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->_loaded[$name] = new $taskClass($this->_Dispatch);
|
$this->_loaded[$name] = new $taskClass($this->_Shell);
|
||||||
if ($enable === true) {
|
if ($enable === true) {
|
||||||
$this->_enabled[] = $name;
|
$this->_enabled[] = $name;
|
||||||
}
|
}
|
||||||
|
@ -75,7 +75,7 @@ class TaskCollection extends ObjectCollection {
|
||||||
* @throws MissingTaskFileException
|
* @throws MissingTaskFileException
|
||||||
*/
|
*/
|
||||||
protected function _getPath($file) {
|
protected function _getPath($file) {
|
||||||
foreach ($this->_Dispatch->shellPaths as $path) {
|
foreach ($this->_Shell->shellPaths as $path) {
|
||||||
$taskPath = $path . 'tasks' . DS . $file . '.php';
|
$taskPath = $path . 'tasks' . DS . $file . '.php';
|
||||||
if (file_exists($taskPath)) {
|
if (file_exists($taskPath)) {
|
||||||
return $taskPath;
|
return $taskPath;
|
||||||
|
|
|
@ -17,7 +17,6 @@
|
||||||
* @since CakePHP(tm) v 2.0
|
* @since CakePHP(tm) v 2.0
|
||||||
* @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';
|
|
||||||
|
|
||||||
App::import('Shell', 'TaskCollection', false);
|
App::import('Shell', 'TaskCollection', false);
|
||||||
App::import('Shell', 'Shell', false);
|
App::import('Shell', 'Shell', false);
|
||||||
|
@ -29,9 +28,9 @@ class TaskCollectionTest extends CakeTestCase {
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
function setup() {
|
function setup() {
|
||||||
$dispatcher = $this->getMock('ShellDispatcher', array(), array(), '', false);
|
$shell = $this->getMock('Shell', array(), array(), '', false);
|
||||||
$dispatcher->shellPaths = App::path('shells');
|
$shell->shellPaths = App::path('shells');
|
||||||
$this->Tasks = new TaskCollection($dispatcher);
|
$this->Tasks = new TaskCollection($shell);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -87,10 +86,10 @@ class TaskCollectionTest extends CakeTestCase {
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
function testLoadPluginTask() {
|
function testLoadPluginTask() {
|
||||||
$dispatcher = $this->getMock('ShellDispatcher', array(), array(), '', false);
|
$shell = $this->getMock('Shell', array(), array(), '', false);
|
||||||
$dispatcher->shellPaths = App::path('shells');
|
$shell->shellPaths = App::path('shells');
|
||||||
$dispatcher->shellPaths[] = TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'plugins' . DS . 'test_plugin' . DS . 'vendors' . DS . 'shells' . DS;
|
$shell->shellPaths[] = TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'plugins' . DS . 'test_plugin' . DS . 'vendors' . DS . 'shells' . DS;
|
||||||
$this->Tasks = new TaskCollection($dispatcher);
|
$this->Tasks = new TaskCollection($shell);
|
||||||
|
|
||||||
$result = $this->Tasks->load('TestPlugin.OtherTask');
|
$result = $this->Tasks->load('TestPlugin.OtherTask');
|
||||||
$this->assertType('OtherTaskTask', $result, 'Task class is wrong.');
|
$this->assertType('OtherTaskTask', $result, 'Task class is wrong.');
|
||||||
|
|
Loading…
Reference in a new issue