CLI tasks are usefull when you want to run parts of your application from the CLI. Tasks are executed via the reactor CLI tool.
php reactor <task name> [<options>]
All tasks have two special parameters, env and database which lets you override the environment and database connection to use.
app/tasks directory and extend the mako\reactor\Task class.If you save the following code as hello.php and run it via the terminal then you'll be greeted by Hello, world!.
<?php
class Hello extends \mako\reactor\Task
{
public function run()
{
$this->cli->stdout('Hello, world!');
}
}
Passing arguments to a controller action is easy as you can se in the example below.
<?php
class color extends \mako\reactor\Task
{
public function color1($color)
{
$this->cli->stdout('your favorite color is ' . $color;);
}
public function color2($color = 'green')
{
$this->cli->stdout('your favorite color is ' . $color;);
}
}
Calling php reactor color.color1 blue will print your favorite color is blue. Trying to call the same task action without the color parameter will result in an error since its a required parameter. Calling php reactor color.color2 will not result in an error since the parmeter is optional but instead tell you that your favorite color is green.
The framework will try to execute the run method if a task is requested without specifying which action to run.