symfony/symfony — pull request #10356 by fabpot (2014-03-01 07:36:17+00:00)
Title: [Console] Progress bar placeholder extensibility

| Q | A
| ------------- | ---
| Bug fix? | no
| New feature? | no
| BC breaks? | no
| Deprecations? | no
| Tests pass? | yes
| Fixed tickets | #9573, #9574
| License | MIT
| Doc PR | not yet

This pull request refactors the way placeholders in the progress bar are managed. It is now possible to add new placeholder to override the default behavior of existing placeholder.

```php
// set a new placeholder
ProgressBar::setPlaceholderFormatter('%remaining_steps%', function (ProgressBar $bar) {
return $bar->getMaxSteps() - $bar->getStep();
});

// change the behavior of an existing placeholder
ProgressBar::setPlaceholderFormatter('%max%', function (ProgressBar $bar) {
return $bar->getMaxSteps() ?: '~';
});
```

Several new built-in placeholders have also been added:

* `%remaining%`: Display the remaining time
* `%estimated%`: Display the estimated time of the whole "task"
* `%memory%`: Display the memory usage

TODO:

- [ ] add some docs