-
-
Notifications
You must be signed in to change notification settings - Fork 9.7k
Closed
Labels
Description
There is a design issue with progress bar placeholder formats. They don't have access to information I wish to pass to ProgressBar when it's being constructed. For example
ProgressBar::setPlaceholderFormatterDefinition('speed', function (ProgressBar $bar) {
return Helper::formatMemory($bar->getProgress() / max(1, time() - $bar->startTime)).'/s';
});
This doesn't work, because there is no $bar->startTime
property and I have no way to pass it to ProgressBar so placeholder can retrieve it.
Similarly, I wanted to show IP of client that is being connected to server
ProgressBar::setPlaceholderFormatterDefinition('host', function (ProgressBar $bar) {
return $bar->host;
});
Of course, it has same problem.
I guess I could workaround it by passing the variable via use
, but this would require to:
- have
setPlaceholderFormatterDefinition
call always in same scope asProgressBar
is being initialized - unique placeholder identifier for each progress bar
That's too much of expensive workarounds. These placeholders are designed to be defined once at application bootstrap and reused.
I don't know what's best course of action to solve this, I have couple ideas, but I'm not fan of either
- allow to pass arbitrary data to ProgressBar
- allow to pass arbitrary data to OutputInterface (closure is receiving it as second parameter)
- pass to closure
$this
+func_get_args
(similar to 1. I guess) - make ProgressBar open to inheritance again