Skip to content

Commit 54d88e1

Browse files
[Console] Add placeholder formatters per ProgressBar instance
1 parent 7a79bc7 commit 54d88e1

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

components/console/helpers/progressbar.rst

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -337,13 +337,27 @@ display that are not available in the list of built-in placeholders, you can
337337
create your own. Let's see how you can create a ``remaining_steps`` placeholder
338338
that displays the number of remaining steps::
339339

340+
// This definition is globally registered for all ProgressBar instances
340341
ProgressBar::setPlaceholderFormatterDefinition(
341342
'remaining_steps',
342343
function (ProgressBar $progressBar, OutputInterface $output) {
343344
return $progressBar->getMaxSteps() - $progressBar->getProgress();
344345
}
345346
);
346347

348+
It is also possible to set a placeholder formatter per ProgressBar instance
349+
with the ``setPlaceholderFormatter`` method::
350+
351+
$progressBar = new ProgressBar($output, 3, 0);
352+
$progressBar->setFormat('%countdown% [%bar%]');
353+
$progressBar->setPlaceholderFormatter('countdown', function (ProgressBar $progressBar) {
354+
return $progressBar->getMaxSteps() - $progressBar->getProgress();
355+
});
356+
357+
.. versionadded:: 6.3
358+
359+
The ``setPlaceholderFormatter()`` method was introduced in Symfony 6.3.
360+
347361
Custom Messages
348362
~~~~~~~~~~~~~~~
349363

0 commit comments

Comments
 (0)
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