%remaining%>'
+ );
+
+.. note::
+
+ A format can span more than one line; that's very useful when you want to
+ display more contextual information alongside the progress bar (see the
+ example at the beginning of this article).
+
+Bar Settings
+~~~~~~~~~~~~
+
+Amongst the placeholders, ``bar`` is a bit special as all the characters used
+to display it can be customized::
+
+ // the finished part of the bar
+ $progress->setBarCharacter('=');
+
+ // the unfinished part of the bar
+ $progress->setEmptyBarCharacter(' ');
+
+ // the progress character
+ $progress->setProgressCharacter('|');
+
+ // the bar width
+ $progress->setBarWidth(50);
+
+.. caution::
+
+ For performance reasons, be careful if you set the total number of steps
+ to a high number. For example, if you're iterating over a large number of
+ items, consider setting the redraw frequency to a higher value by calling
+ :method:`Symfony\\Component\\Console\\Helper\\ProgressHelper::setRedrawFrequency`,
+ so it updates on only some iterations::
+
+ $progress->start($output, 50000);
+
+ // update every 100 iterations
+ $progress->setRedrawFrequency(100);
+
+ $i = 0;
+ while ($i++ < 50000) {
+ // ... do some work
+
+ $progress->advance();
+ }
+
+Custom Placeholders
+~~~~~~~~~~~~~~~~~~~
+
+If you want to display some information that depends on the progress bar
+display that are not available in the list of built-in placeholders, you can
+create your own. Let's see how you can create a ``remaining_steps`` placeholder
+that displays the number of remaining steps::
+
+ ProgressBar::setPlaceholderFormatter(
+ '%remaining_steps%',
+ function (ProgressBar $bar, OutputInterface $output) {
+ return $bar->getMaxSteps() - $bar->getStep();
+ }
+ );
+
+Custom Messages
+~~~~~~~~~~~~~~~
+
+The ``%message%`` placeholder allows you to specify a custom message to be
+displayed with the progress bar. But if you need more than one, just define
+your own::
+
+ $bar->setMessage('Task starts');
+ $bar->setMessage('', 'filename');
+ $bar->start();
+
+ $bar->setMessage('Task is in progress...');
+ while ($file = array_pop($files)) {
+ $bar->setMessage($filename, 'filename');
+ $bar->advance();
+ }
+
+ $bar->setMessage('Task is finished');
+ $bar->setMessage('', 'filename');
+ $bar->finish();
+
+For the ``filename`` to be part of the progress bar, just add the
+``%filename%`` placeholder in your format::
+
+ $bar->setFormat(" %message%\n %step%/%max%\n Working on %filename%");
diff --git a/components/console/helpers/progresshelper.rst b/components/console/helpers/progresshelper.rst
index 9ee76b694cb..3722b3fe213 100644
--- a/components/console/helpers/progresshelper.rst
+++ b/components/console/helpers/progresshelper.rst
@@ -10,6 +10,13 @@ Progress Helper
.. versionadded:: 2.4
The ``clear`` method was added in Symfony 2.4.
+.. caution::
+
+ The Progress Helper was deprecated in Symfony 2.5 and will be removed in
+ Symfony 3.0. You should now use the
+ :doc:`Progress Bar ` instead which
+ is more powerful.
+
When executing longer-running commands, it may be helpful to show progress
information, which updates as your command runs:
@@ -25,7 +32,7 @@ pass it a total number of units, and advance the progress as your command execut
while ($i++ < 50) {
// ... do some work
- // advance the progress bar 1 unit
+ // advances the progress bar 1 unit
$progress->advance();
}
@@ -79,7 +86,7 @@ To see other available options, check the API documentation for
$progress->start($output, 50000);
- // update every 100 iterations
+ // updates every 100 iterations
$progress->setRedrawFrequency(100);
$i = 0;
diff --git a/images/components/console/progressbar.gif b/images/components/console/progressbar.gif
new file mode 100644
index 00000000000..6c80e6e897f
Binary files /dev/null and b/images/components/console/progressbar.gif differ
pFad - Phonifier reborn
Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.
Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.
Alternative Proxies:
Alternative Proxy
pFad Proxy
pFad v3 Proxy
pFad v4 Proxy