mf/symfony-console-subscriber

Symfony Console 的控制台订阅者

3.0.0 2022-07-25 14:08 UTC

This package is auto-updated.

Last update: 2024-08-25 18:56:33 UTC


README

Latest Stable Version Tests and linting Coverage Status Total Downloads License

Symfony Console 的控制台订阅者。

安装

composer require mf/symfony-console-subscriber

使用

比较

它和使用 SymfonyStyle 直接一样,你只需要使用 EventDispatcher 来处理你的事件。

SymfonyStyle

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

初始化

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

$subscriber->setIo($io);

$eventDispatcher->addSubscriber($subscriber);

分发

注意

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

进度

$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!'));