3.12.2.2 Tasks
Tasks are small extensions to shells. They allow logic to be shared between shells, and are added to shells by using the special $tasks class variable. For example in the core bake shell, there are a number of tasks defined:
<?php
class BakeShell extends Shell {
var $tasks = array('Project', 'DbConfig', 'Model', 'View', 'Controller');
}
?> <?phpclass BakeShell extends Shell {var $tasks = array('Project', 'DbConfig', 'Model', 'View', 'Controller');}?>
Tasks are stored in /vendors/shells/tasks/ in files named after their classes. So if we were to create a new ‘cool’ task. Class CoolTask (which extends Shell) would be placed in /vendors/shells/tasks/cool.php.
Each task must at least implement an execute() method - shells will call this method to start the task logic.
<?php
class SoundTask extends Shell {
var $uses = array('Model'); // same as controller var $uses
function execute() {}
}
?> <?phpclass SoundTask extends Shell {var $uses = array('Model'); // same as controller var $usesfunction execute() {}}?>
You can access tasks inside your shell classes and execute them there:
<?php
class SeaShell extends Shell // found in /vendors/shells/sea.php {
var $tasks = array('Sound'); //found in /vendors/shells/tasks/sound.php
function main() {}
}
?> <?phpclass SeaShell extends Shell // found in /vendors/shells/sea.php {var $tasks = array('Sound'); //found in /vendors/shells/tasks/sound.phpfunction main() {}}?>
A method called “sound” in the SeaShell class would override the ability to access the functionality in the Sound task specified in the $tasks array.
You can also access tasks directly from the command line:
$ cake sea sound
