mf/symfony-console-subscriber

Console Subscriber for Symfony Console

3.0.0 2022-07-25 14:08 UTC

This package is auto-updated.

Last update: 2024-11-25 19:31:40 UTC


README

Latest Stable Version Tests and linting Coverage Status Total Downloads License

Console Subscriber for Symfony Console.

Installation

composer require mf/symfony-console-subscriber

Usage

Comparision

It is same as using SymfonyStyle directly, you just use EventDispatcher to handle your events.

SymfonyStyle

$io->note('note');
    
// vs Dispatching
    
$eventDispatcher->dispatch(new NoteEvent('Some note.'));

initialization

$io = new SymfonyStyle();
$subscriber = new ConsoleSubscriber();

$subscriber->setIo($io);

$eventDispatcher->addSubscriber($subscriber);

dispatch

Note

$eventDispatcher->dispatch(new NoteEvent('Some note.'));

Progress

$items = [1, 2, 3];
    
$eventDispatcher->dispatch(new ProgressStartEvent($items));

foreach($items as $i) {
    // do something
    
    $eventDispatcher->dispatch(new ProgressAdvanceEvent());
}

$eventDispatcher->dispatch(new ProgressFinishedEvent('All items were iterated!'));