2010-07-07 03:30:24 +00:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* Task collection is used as a registry for loaded tasks and handles loading
|
|
|
|
* and constructing task class objects.
|
|
|
|
*
|
|
|
|
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
|
|
|
|
* Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
|
|
|
*
|
|
|
|
* Licensed under The MIT License
|
|
|
|
* Redistributions of files must retain the above copyright notice.
|
|
|
|
*
|
|
|
|
* @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
|
|
|
* @link http://cakephp.org CakePHP(tm) Project
|
2010-12-24 18:57:20 +00:00
|
|
|
* @package cake.console.libs
|
2010-07-07 03:30:24 +00:00
|
|
|
* @since CakePHP(tm) v 2.0
|
|
|
|
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
|
|
|
|
*/
|
2011-02-14 03:40:19 +00:00
|
|
|
<<<<<<< HEAD:lib/Cake/Console/TaskCollection.php
|
2010-12-07 05:56:10 +00:00
|
|
|
App::uses('ObjectCollection', 'Utility');
|
2010-07-07 03:30:24 +00:00
|
|
|
|
2011-02-14 03:40:19 +00:00
|
|
|
=======
|
|
|
|
>>>>>>> origin/2.0:cake/console/libs/task_collection.php
|
2010-07-07 03:30:24 +00:00
|
|
|
class TaskCollection extends ObjectCollection {
|
|
|
|
/**
|
2010-10-24 18:55:16 +00:00
|
|
|
* Shell to use to set params to tasks.
|
2010-07-07 03:30:24 +00:00
|
|
|
*
|
|
|
|
* @var array
|
|
|
|
*/
|
2010-10-04 04:23:54 +00:00
|
|
|
protected $_Shell;
|
2010-07-07 03:30:24 +00:00
|
|
|
|
2010-10-17 19:58:44 +00:00
|
|
|
/**
|
|
|
|
* The directory inside each shell path that contains tasks.
|
|
|
|
*
|
|
|
|
* @var string
|
|
|
|
*/
|
|
|
|
public $taskPathPrefix = 'tasks/';
|
|
|
|
|
2010-07-07 03:30:24 +00:00
|
|
|
/**
|
|
|
|
* Constructor
|
|
|
|
*
|
|
|
|
* @param array $paths Array of paths to search for tasks on .
|
|
|
|
* @return void
|
|
|
|
*/
|
2010-10-24 18:55:16 +00:00
|
|
|
public function __construct(Shell $Shell) {
|
2010-10-04 04:23:54 +00:00
|
|
|
$this->_Shell = $Shell;
|
2010-07-07 03:30:24 +00:00
|
|
|
}
|
2010-10-24 18:55:16 +00:00
|
|
|
|
2010-07-07 03:30:24 +00:00
|
|
|
/**
|
2010-10-17 19:07:00 +00:00
|
|
|
* Loads/constructs a task. Will return the instance in the collection
|
|
|
|
* if it already exists.
|
2010-07-07 03:30:24 +00:00
|
|
|
*
|
|
|
|
* @param string $task Task name to load
|
|
|
|
* @param array $settings Settings for the task.
|
|
|
|
* @return Task A task object, Either the existing loaded task or a new one.
|
|
|
|
* @throws MissingTaskFileException, MissingTaskClassException when the task could not be found
|
|
|
|
*/
|
2011-01-19 00:33:05 +00:00
|
|
|
public function load($task, $settings = array()) {
|
2010-07-07 03:30:24 +00:00
|
|
|
list($plugin, $name) = pluginSplit($task, true);
|
|
|
|
|
|
|
|
if (isset($this->_loaded[$name])) {
|
|
|
|
return $this->_loaded[$name];
|
|
|
|
}
|
|
|
|
$taskFile = Inflector::underscore($name);
|
|
|
|
$taskClass = $name . 'Task';
|
2010-12-07 06:14:17 +00:00
|
|
|
App::uses($taskClass, 'Console/Command/Task');
|
2010-07-07 03:30:24 +00:00
|
|
|
if (!class_exists($taskClass)) {
|
|
|
|
if (!class_exists($taskClass)) {
|
|
|
|
throw new MissingTaskClassException($taskClass);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-10-06 04:15:51 +00:00
|
|
|
$this->_loaded[$name] = new $taskClass(
|
2010-10-24 18:55:16 +00:00
|
|
|
$this->_Shell->stdout, $this->_Shell->stderr, $this->_Shell->stdin
|
2010-10-06 04:15:51 +00:00
|
|
|
);
|
2011-01-19 00:33:05 +00:00
|
|
|
$enable = isset($settings['enabled']) ? $settings['enabled'] : true;
|
2010-07-07 03:30:24 +00:00
|
|
|
if ($enable === true) {
|
|
|
|
$this->_enabled[] = $name;
|
|
|
|
}
|
|
|
|
return $this->_loaded[$name];
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|