Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/mortalflesh/symfony-console-subscriber
Console Subscriber for Symfony Console
https://github.com/mortalflesh/symfony-console-subscriber
symfony symfony-console symfony-eventdispatcher symfony-style
Last synced: 11 days ago
JSON representation
Console Subscriber for Symfony Console
- Host: GitHub
- URL: https://github.com/mortalflesh/symfony-console-subscriber
- Owner: MortalFlesh
- License: mit
- Created: 2017-10-29T15:14:47.000Z (about 7 years ago)
- Default Branch: master
- Last Pushed: 2022-07-25T14:08:16.000Z (over 2 years ago)
- Last Synced: 2024-10-27T01:41:30.287Z (21 days ago)
- Topics: symfony, symfony-console, symfony-eventdispatcher, symfony-style
- Language: PHP
- Size: 36.1 KB
- Stars: 2
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
Symfony Console Subscriber
==========================[![Latest Stable Version](https://img.shields.io/packagist/v/mf/symfony-console-subscriber.svg)](https://packagist.org/packages/mf/symfony-console-subscriber)
[![Tests and linting](https://github.com/MortalFlesh/symfony-console-subscriber/actions/workflows/tests.yaml/badge.svg)](https://github.com/MortalFlesh/symfony-console-subscriber/actions/workflows/tests.yaml)
[![Coverage Status](https://coveralls.io/repos/github/MortalFlesh/symfony-console-subscriber/badge.svg?branch=master)](https://coveralls.io/github/MortalFlesh/symfony-console-subscriber?branch=master)
[![Total Downloads](https://img.shields.io/packagist/dt/mf/symfony-console-subscriber.svg)](https://packagist.org/packages/mf/symfony-console-subscriber)
[![License](https://img.shields.io/packagist/l/mf/symfony-console-subscriber.svg)](https://packagist.org/packages/mf/symfony-console-subscriber)Console Subscriber for Symfony Console.
## Installation
```bash
composer require mf/symfony-console-subscriber
```## Usage
### Comparision
It is same as using `SymfonyStyle` directly, you just use `EventDispatcher` to handle your events.`SymfonyStyle`
```php
$io->note('note');
// vs Dispatching
$eventDispatcher->dispatch(new NoteEvent('Some note.'));
```### initialization
```php
$io = new SymfonyStyle();
$subscriber = new ConsoleSubscriber();$subscriber->setIo($io);
$eventDispatcher->addSubscriber($subscriber);
```### dispatch
Note
```php
$eventDispatcher->dispatch(new NoteEvent('Some note.'));
```Progress
```php
$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!'));
```