mf / symfony-console-subscriber
Symfony Console 的控制台订阅者
3.0.0
2022-07-25 14:08 UTC
Requires
- php: ^8.1
- symfony/console: ^5.0 || ^6.0
- symfony/event-dispatcher: ^5.0 || ^6.0
Requires (Dev)
- ergebnis/composer-normalize: ^2.28
- lmc/coding-standard: ^3.3
- mockery/mockery: ^1.4
- php-parallel-lint/php-parallel-lint: ^1.3
- phpstan/extension-installer: ^1.1
- phpstan/phpstan: ^1.8
- phpstan/phpstan-mockery: ^1.1
- phpstan/phpstan-phpunit: ^1.1
- phpunit/phpunit: ^9.5.20
README
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!'));