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:
Простой текст<?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.
Простой текст<?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:
Простой текст<?phpclass SeaShell extends Shell // found in /vendors/shells/sea.php {var $tasks = array('Sound'); //found in /vendors/shells/tasks/sound.phpfunction main() {$this->Sound->execute();}}?>
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


Коментарии:
Добавить коментарий