Tasks

Tasks are scripts executabled from UI. The creation of tasks is based on events.

// src/EventSuscriber/MyTaskEventSubscriber.php
namespace App\EventSuscriber;

use App\Core\Event\Task\TaskInitEvent;
use App\Core\Event\Task\TaskRunRequestedEvent;
use App\Core\EventSuscriber\Task\TaskEventSubscriber;

class MyTaskEventSubscriber extends TaskEventSubscriber
{
    public function onInit(TaskInitEvent $event)
    {
        $event->addTask('my_task', 'Example', 'My task');
    }

    public function onRunRequest(TaskRunRequestedEvent $event)
    {
        if ('my_task' !== $event->getTask()) {
            return;
        }

        $event->getOutput()->writeln('My task is started');

        // ...

        $event->getOutput()->writeln('My task is finished');
    }
}