akeneo/pim-community-dev — pull request #448 by antoineguigan (2013-11-06 09:59:06+00:00)
Title: Added classes to manage progress bars in commands

Bug fix: [no]
Feature addition: [no]
Backwards compatibility break: [no]
Unit test passes: [N/A]
Behat scenarios passes: [N/A]
Checkstyle issues: [no]*
ChangeLog updated: [no]
Documentation PR:
Fixes the following jira:

This PR adds two more classes to easily manage progress bars in commands without having to add business logic inside command classes.

To add a progress bar inside a command, proceed like this :

$this->getContainer()->get('pim_catalog.event_listener.progress')->bind(
$output,
'event_name',
'Treating section %s'
);

The command bar will be updated each time a ProgressEvent with the name 'event_name' is fired. To fire these events inside a service, the following code can be used :

$this->eventDispatcher->dispatch(
'event',
new ProgressEvent($treatedItems, $totalItems, 'section')
);

(The event dispatcher has to be injected inside your service)