Symfony\Component\Console\Helper\ProgressBar::setPlaceholderFormatterDefinition PHP Method

setPlaceholderFormatterDefinition() public static method

This method also allow you to override an existing placeholder.
public static setPlaceholderFormatterDefinition ( string $name, callable $callable )
$name string The placeholder name (including the delimiter char like %)
$callable callable A PHP callable
    public static function setPlaceholderFormatterDefinition($name, callable $callable)
    {
        if (!self::$formatters) {
            self::$formatters = self::initPlaceholderFormatters();
        }
        self::$formatters[$name] = $callable;
    }

Usage Example

コード例 #1
0
 /**
  * @return bool
  */
 public function download()
 {
     if ($this->isDownloaded()) {
         return true;
     }
     $httpClient = new Client();
     $request = new Request('GET', $this->getUrl());
     $response = $httpClient->send($request, [RequestOptions::PROGRESS => function ($total, $current) {
         if ($total <= 0 || !$this->output) {
             return;
         }
         if (!$this->progressBar) {
             $this->progressBar = new ProgressBar($this->output, $total);
             $this->progressBar->setPlaceholderFormatterDefinition('max', function (ProgressBar $bar) {
                 return $this->formatSize($bar->getMaxSteps());
             });
             $this->progressBar->setPlaceholderFormatterDefinition('current', function (ProgressBar $bar) {
                 return str_pad($this->formatSize($bar->getProgress()), 11, ' ', STR_PAD_LEFT);
             });
         }
         $this->progressBar->setProgress($current);
     }]);
     $this->filesystem->dumpFile($this->getDestinationFile(), $response->getBody()->getContents());
     $this->downloaded = true;
     return true;
 }
All Usage Examples Of Symfony\Component\Console\Helper\ProgressBar::setPlaceholderFormatterDefinition