cakephp2-php8/lib/Cake/Console/TaskCollection.php
José Lorenzo Rodríguez 6e4f4efb79 Merge remote branch 'origin/2.0' into 2.0-class-loading
Conflicts:
	cake/bootstrap.php
	lib/Cake/Console/Command/TestSuiteShell.php
	lib/Cake/Console/TaskCollection.php
	lib/Cake/Controller/ComponentCollection.php
	lib/Cake/Controller/Controller.php
	lib/Cake/Core/App.php
	lib/Cake/Model/BehaviorCollection.php
	lib/Cake/Network/CakeRequest.php
	lib/Cake/TestSuite/CakeTestSuiteDispatcher.php
	lib/Cake/TestSuite/CakeWebTestCase.php
	lib/Cake/TestSuite/TestManager.php
	lib/Cake/TestSuite/TestRunner.php
	lib/Cake/View/HelperCollection.php
	lib/Cake/tests/cases/libs/model/datasources/dbo/dbo_postgres.test.php
	lib/Cake/tests/cases/libs/test_manager.test.php
2011-02-13 23:10:19 -04:30

82 lines
2.3 KiB
PHP

<?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
* @package cake.console.libs
* @since CakePHP(tm) v 2.0
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
*/
<<<<<<< HEAD:lib/Cake/Console/TaskCollection.php
App::uses('ObjectCollection', 'Utility');
=======
>>>>>>> origin/2.0:cake/console/libs/task_collection.php
class TaskCollection extends ObjectCollection {
/**
* Shell to use to set params to tasks.
*
* @var array
*/
protected $_Shell;
/**
* The directory inside each shell path that contains tasks.
*
* @var string
*/
public $taskPathPrefix = 'tasks/';
/**
* Constructor
*
* @param array $paths Array of paths to search for tasks on .
* @return void
*/
public function __construct(Shell $Shell) {
$this->_Shell = $Shell;
}
/**
* Loads/constructs a task. Will return the instance in the collection
* if it already exists.
*
* @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
*/
public function load($task, $settings = array()) {
list($plugin, $name) = pluginSplit($task, true);
if (isset($this->_loaded[$name])) {
return $this->_loaded[$name];
}
$taskFile = Inflector::underscore($name);
$taskClass = $name . 'Task';
App::uses($taskClass, 'Console/Command/Task');
if (!class_exists($taskClass)) {
if (!class_exists($taskClass)) {
throw new MissingTaskClassException($taskClass);
}
}
$this->_loaded[$name] = new $taskClass(
$this->_Shell->stdout, $this->_Shell->stderr, $this->_Shell->stdin
);
$enable = isset($settings['enabled']) ? $settings['enabled'] : true;
if ($enable === true) {
$this->_enabled[] = $name;
}
return $this->_loaded[$name];
}
}