setFormatDefinition() public static méthode

This method also allow you to override an existing format.
public static setFormatDefinition ( string $name, string $format )
$name string The format name
$format string A format string
 /**
  * {@inheritDoc}
  */
 protected function initialize(InputInterface $input, OutputInterface $output)
 {
     $this->em = $this->getEntityManager();
     if (class_exists('Symfony\\Component\\Console\\Helper\\ProgressBar')) {
         ProgressBar::setFormatDefinition('normal', " %current%/%max% [%bar%] %percent:3s%%\n%message%");
         ProgressBar::setFormatDefinition('verbose', " %current%/%max% [%bar%] %percent:3s%% %elapsed:6s%\n%message%");
         ProgressBar::setFormatDefinition('very_verbose', " %current%/%max% [%bar%] %percent:3s%% %elapsed:6s%/%estimated:-6s%\n%message%");
         ProgressBar::setFormatDefinition('debug', " %current%/%max% [%bar%] %percent:3s%% %elapsed:6s%/%estimated:-6s% %memory:6s%\n%message%");
     }
 }
Exemple #2
0
 /**
  * @return void
  */
 protected function setupFormat()
 {
     ProgressBar::setFormatDefinition('normal_nomax', ' <fg=yellow>*</fg=yellow> <fg=green>%barTitle%</fg=green> <fg=yellow>(%max%)</fg=yellow>');
     ProgressBar::setFormatDefinition('verbose_nomax', ' <fg=yellow>*</fg=yellow> <fg=green>%barTitle%</fg=green> <fg=yellow>(%max%)</fg=yellow>');
     ProgressBar::setFormatDefinition('very_verbose_nomax', ' <fg=yellow>*</fg=yellow> <fg=green>%barTitle%</fg=green> <fg=yellow>(%max%)</fg=yellow>');
     ProgressBar::setFormatDefinition('debug_nomax', ' <fg=yellow>*</fg=yellow> <fg=green>%barTitle%</fg=green> <fg=yellow>(%max%)</fg=yellow>');
     ProgressBar::setFormatDefinition('normal', ' <fg=yellow>*</fg=yellow> <fg=green>%barTitle%</fg=green> <fg=yellow>(%max%)</fg=yellow>');
     ProgressBar::setFormatDefinition('verbose', ' <fg=yellow>*</fg=yellow> <fg=green>%barTitle%</fg=green> <fg=yellow>%percent%% (%current%/%max%) %elapsed:6s%</fg=yellow>');
     ProgressBar::setFormatDefinition('very_verbose', " <fg=yellow>*</fg=yellow> <fg=green>%barTitle:-25s%</fg=green> [%bar%] <fg=yellow>%percent%% (%current%/%max%) %elapsed:6s% %memory:6s%</fg=yellow>\r");
     ProgressBar::setFormatDefinition('debug', " <fg=yellow>*</fg=yellow> <fg=green>%barTitle:-25s%</fg=green> %bar% <fg=yellow>%percent:20s%% [%current%/%max%] Memory: %memory%, Elapsed: %elapsed%, Remaining: %remaining%</fg=yellow>\r");
 }
 /**
  * {@inheritDoc}
  */
 protected function initialize(InputInterface $input, OutputInterface $output)
 {
     $this->dispatcher = $this->getContainer()->get('event_dispatcher');
     $this->indexManager = $this->getContainer()->get('fos_elastica.index_manager');
     $this->providerRegistry = $this->getContainer()->get('fos_elastica.provider_registry');
     $this->resetter = $this->getContainer()->get('fos_elastica.resetter');
     $this->progressClosureBuilder = new ProgressClosureBuilder();
     if (!$input->getOption('no-overwrite-format') && class_exists('Symfony\\Component\\Console\\Helper\\ProgressBar')) {
         ProgressBar::setFormatDefinition('normal', " %current%/%max% [%bar%] %percent:3s%%\n%message%");
         ProgressBar::setFormatDefinition('verbose', " %current%/%max% [%bar%] %percent:3s%% %elapsed:6s%\n%message%");
         ProgressBar::setFormatDefinition('very_verbose', " %current%/%max% [%bar%] %percent:3s%% %elapsed:6s%/%estimated:-6s%\n%message%");
         ProgressBar::setFormatDefinition('debug', " %current%/%max% [%bar%] %percent:3s%% %elapsed:6s%/%estimated:-6s% %memory:6s%\n%message%");
     }
 }
 /**
  * Initializes a new instance of the Reporter class.
  *
  * @param  $output
  * @param  $total
  *
  * @return Reporter
  */
 public function __construct(OutputInterface $output, $total)
 {
     $this->issues = new IssueCollection();
     $this->output = $output;
     if ($total > 1) {
         $this->output->writeln('');
         ProgressBar::setFormatDefinition('minimal', ' <fg=cyan>Reviewing file %current% of %max%.</>');
         $this->progress = new ProgressBar($output, $total);
         $this->progress->setFormat('minimal');
         $this->progress->start();
     }
     $this->total = $total;
     $this->current = 1;
 }
 /**
  * TerminusStyle constructor.
  *
  * @param \Symfony\Component\Console\Input\InputInterface $input
  * @param \Symfony\Component\Console\Output\OutputInterface $output
  */
 public function __construct(InputInterface $input, OutputInterface $output)
 {
     ProgressBar::setFormatDefinition('normal', self::NORMAL_PROGRESS_FORMAT);
     parent::__construct($input, $output);
 }
Exemple #6
0
 protected function copyTable($table, $keyColumn = false)
 {
     $columns = join(array_map(function ($column) {
         return $this->sc->quoteIdentifier($column->getName());
     }, $table->getColumns()), ',');
     $sqlParameters = array();
     $maxKey = null;
     // set selection range
     if ($keyColumn) {
         $sqlMax = 'SELECT MAX(' . $this->tc->quoteIdentifier($keyColumn) . ') ' . 'FROM ' . $this->tc->quoteIdentifier($table->getName());
         $maxKey = $this->tc->fetchColumn($sqlMax);
         if (isset($maxKey)) {
             $sqlParameters[] = $maxKey;
         }
     } else {
         // clear target table
         $this->truncateTable($this->tc, $table);
     }
     echo $table->getName() . ": copying ";
     // count selection range
     $sqlCount = 'SELECT COUNT(1) FROM (' . $this->sc->quoteIdentifier($table->getName()) . ')';
     if ($keyColumn && isset($maxKey)) {
         $sqlCount .= ' WHERE ' . $this->sc->quoteIdentifier($keyColumn) . ' > ?';
     }
     $totalRows = $this->sc->fetchColumn($sqlCount, $sqlParameters);
     echo $totalRows . " rows (" . ($keyColumn ? 'partial copy' : 'overwrite') . ")\n";
     $progress = new ProgressBar($this->output, $totalRows);
     $progress->setFormatDefinition('debug', ' [%bar%] %percent:3s%% %elapsed:8s%/%estimated:-8s% %current% rows');
     $progress->setFormat('debug');
     $freq = (int) $totalRows / 20;
     $progress->setRedrawFrequency($freq > 10 ? $freq : 10);
     $progress->start();
     // transfer sql
     $sqlValuePlaceholder = '(' . join(array_fill(0, sizeof($table->getColumns()), '?'), ',') . ')';
     $loopOffsetIndex = 0;
     do {
         // get source data
         $sql = 'SELECT ' . $columns . ' FROM ' . $this->sc->quoteIdentifier($table->getName());
         // limit selection for PRIMARY KEY mode
         if ($keyColumn) {
             if (isset($maxKey)) {
                 $sql .= ' WHERE ' . $this->sc->quoteIdentifier($keyColumn) . ' > ?';
                 $sqlParameters = array($maxKey);
             }
             $sql .= ' ORDER BY ' . $this->sc->quoteIdentifier($keyColumn) . ' LIMIT ' . $this->batch;
         } else {
             $sql .= ' LIMIT ' . $this->batch . ' OFFSET ' . $this->batch * $loopOffsetIndex++;
         }
         if (sizeof($rows = $this->sc->fetchAll($sql, $sqlParameters)) == 0) {
             // avoid div by zero in progress->advance
             break;
         }
         if ($this->tc->getDatabasePlatform()->getName() !== 'sqlite') {
             $sqlInsert = 'INSERT INTO ' . $this->tc->quoteIdentifier($table->getName()) . ' (' . $columns . ') ' . 'VALUES ' . join(array_fill(0, count($rows), $sqlValuePlaceholder), ',');
             $data = array();
             foreach ($rows as $row) {
                 // remember max key
                 if ($keyColumn) {
                     $maxKey = $row[$keyColumn];
                 }
                 $data = array_merge($data, array_values($row));
             }
             $this->tc->executeUpdate($sqlInsert, $data);
             $progress->advance(count($rows));
         } else {
             // sqlite
             $stmt = $this->tc->prepare('INSERT INTO ' . $this->tc->quoteIdentifier($table->getName()) . ' (' . $columns . ') ' . 'VALUES (' . join(array_fill(0, count($table->getColumns()), '?'), ',') . ')');
             $this->tc->beginTransaction();
             foreach ($rows as $row) {
                 // remember max key
                 if ($keyColumn) {
                     $maxKey = $row[$keyColumn];
                 }
                 $stmt->execute(array_values($row));
                 $progress->advance(1);
             }
             $this->tc->commit();
         }
     } while ($keyColumn && sizeof($rows));
     $progress->finish();
     echo "\n\n";
     // CRLF after progressbar @ 100%
 }