Skip to content

Commit 790a4ae

Browse files
committed
minor #17638 [Console] Add placeholder formatters per ProgressBar instance (alexandre-daubois)
This PR was merged into the 6.3 branch. Discussion ---------- [Console] Add placeholder formatters per ProgressBar instance Resolves #17545 Commits ------- 54d88e1 [Console] Add placeholder formatters per ProgressBar instance
2 parents c3b8944 + 54d88e1 commit 790a4ae

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)