@@ -95,22 +95,32 @@ that the progress bar display is refreshed with a 100% completion.
95
95
:method: `Symfony\\ Component\\ Console\\ Helper\\ ProgressBar::display `
96
96
to show the progress bar again.
97
97
98
- If you want to use the progress bar to show the progress of an iteration you can use the
99
- :method: `Symfony\\ Component\\ Console\\ Helper\\ ProgressBar::iterate ` method that will automatically call ``start ``,
100
- ``advance `` and ``finish `` while iterating::
98
+ If the progress information is stored in an iterable variable (such as an array
99
+ or a PHP generator) you can use the
100
+ :method: `Symfony\\ Component\\ Console\\ Helper\\ ProgressBar::iterate ` method,
101
+ which starts, advances and finishes the progress bar automatically::
101
102
102
103
use Symfony\Component\Console\Helper\ProgressBar;
103
104
104
105
$progressBar = new ProgressBar($output);
105
106
106
- // starts and displays the progress bar
107
- foreach ($progressBar->iterate($iterable) as $key => $value) {
107
+ // $iterable can be for example an array ([1, 2, 3, ...]) or a generator
108
+ // $iterable = function () { yield 1; yield 2; ... };
109
+ foreach ($progressBar->iterate($iterable) as $value) {
108
110
// ... do some work
109
111
}
110
112
113
+ If ``$iterable = [1, 2] ``, the previous code will output the following:
114
+
115
+ .. code-block :: terminal
116
+
117
+ 0/2 [>---------------------------] 0%
118
+ 1/2 [==============>-------------] 50%
119
+ 2/2 [============================] 100%
120
+
111
121
.. versionadded :: 4.3
112
122
113
- The ``iterate `` method was introduced in Symfony 4.3.
123
+ The ``iterate() `` method was introduced in Symfony 4.3.
114
124
115
125
Customizing the Progress Bar
116
126
----------------------------
0 commit comments