# Tasks - Documentation of Murph
None

Skip to content

# Tasks

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

src/EventSubscriber/MyTaskEventSubscriber.php

    namespace App\EventSubscriber;

    use App\Core\Event\Task\TaskInitEvent;
    use App\Core\Event\Task\TaskRunRequestedEvent;
    use App\Core\EventSubscriber\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');
        }
    }