Console Subscriber for Symfony Console.
composer require mf/symfony-console-subscriber
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.'));
$io = new SymfonyStyle();
$subscriber = new ConsoleSubscriber();
$subscriber->setIo($io);
$eventDispatcher->addSubscriber($subscriber);
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!'));