Gets the current step position.
public getProgress ( ) : integer | ||
return | integer | The progress bar step |
/** * Get progress bar instance * * @param integer $total * * @return ProgressBar */ public function getProgress($total = null) { if (!$this->progress || $this->progress->getMaxSteps() === $this->progress->getProgress()) { $this->progress = new ProgressBar($this->output, $total); } return $this->progress; }
/** * @param RunnerEvent $runnerEvent */ public function finishProgress(RunnerEvent $runnerEvent) { if ($this->progressBar->getProgress() != $this->progressBar->getMaxSteps()) { $this->progressBar->setFormat('<fg=red>%message%</fg=red>'); $this->progressBar->setMessage('Aborted ...'); } $this->progressBar->finish(); $this->output->writeln(''); }
/** * {@inheritdoc} */ public function increment($increment = 1) { if ($this->bar === null) { return; } $this->bar->advance($increment); if ($this->bar->getProgress() === $this->bar->getMaxSteps()) { $this->consoleIO->getOutput()->writeln(' - Finished!'); } }
/** * @phpcsSuppress SlevomatCodingStandard.Typehints.TypeHintDeclaration.missingParameterTypeHint * @param int $step */ public function progressAdvance($step = 1) { if ($this->output->isDecorated() && $step > 0) { $stepTime = (time() - $this->progressBar->getStartTime()) / $step; if ($stepTime > 0 && $stepTime < 1) { $this->progressBar->setRedrawFrequency(1 / $stepTime); } else { $this->progressBar->setRedrawFrequency(1); } } $this->progressBar->setProgress($this->progressBar->getProgress() + $step); }
public function testProgressBar() { $progressBar = new ProgressBar(new NullOutput()); $output = new InstallOutput(null, $progressBar); $output->start('Start', 5); $this->assertEquals(5, $progressBar->getMaxSteps()); $this->assertEquals('Start', $progressBar->getMessage('message')); $output->step('Step 1'); $this->assertEquals(1, $progressBar->getProgress()); $this->assertEquals('Step 1', $progressBar->getMessage('message')); $output->end('End'); $this->assertEquals(5, $progressBar->getProgress()); $this->assertEquals('End', $progressBar->getMessage('message')); }
function it_finishes_progress_early(OutputInterface $output, ProgressBar $progressBar, RunnerEvent $event) { $progressBar->getProgress()->willReturn(1); $progressBar->getMaxSteps()->willReturn(2); $progressBar->setFormat(Argument::type('string'))->shouldBeCalled(); $progressBar->setMessage(Argument::type('string'))->shouldBeCalled(); $progressBar->setOverwrite(false)->shouldBeCalled(); $progressBar->finish()->shouldBeCalled(); $output->writeln('')->shouldBeCalled(); $this->finishProgress($event); }
public function reDrawProgressBar() { if ($this->progress !== null && $this->progress->getStartTime() !== null && $this->progress->getProgress() !== $this->progress->getMaxSteps() && $this->progresseBar === true) { $this->progress->display(); } }
protected function execute(InputInterface $input, OutputInterface $output) { $file = $input->getArgument('file'); $fileReal = realpath($file); $output->write('<info>Checking if file</info> ' . $file . ' <info>exits...</info> '); if (!$this->getContainer()->get('filesystem')->exists($fileReal)) { $output->writeln('<error> File not found! </error>'); return; } $output->writeln('<info>File found!</info>'); mb_internal_encoding('UTF-8'); $encodingList = mb_detect_order(); if (!in_array('ISO-8859-1', $encodingList)) { array_push($encodingList, 'ISO-8859-1'); mb_detect_order($encodingList); } $fileEncoding = mb_detect_encoding($fileContents = file_get_contents($file)); $output->writeln('<info>Opening file:</info> ' . $fileReal . ''); $fileContentArray = explode("\n", $fileContents); $output->writeln('<info>Found</info> ' . ($lines = count($fileContentArray) . ' <info>lines in the file.</info>')); $questionHelper = $this->getHelper('question'); $output->writeln(''); if (!$questionHelper->ask($input, $output, new ConfirmationQuestion('<question>Do you confirm deleting all entries? (Y/n)</question> ', true))) { $output->writeln(''); $output->writeln('<error> </error>'); $output->writeln('<error> Aborting, because merging is not yet implemented! </error>'); $output->writeln('<error> </error>'); return; } $output->writeln(''); $doctrine = $this->getContainer()->get('doctrine'); $entityManger = $doctrine->getManager(); $validator = $this->getContainer()->get('validator'); $deletedRows = $entityManger->createQuery('DELETE FROM ChrKo\\Bundle\\GermanCentralBankBundle\\Entity\\Bank b')->execute(); $output->writeln('<info>Deleted </info>' . $deletedRows . '<info> Rows!</info>'); $output->writeln(''); if (!$questionHelper->ask($input, $output, new ConfirmationQuestion('<question>Do you want to proceed and import? (Y/n)</question> '))) { $output->writeln(''); $output->writeln('<error> </error>'); $output->writeln('<error> Aborting. </error>'); $output->writeln('<error> </error>'); } $output->writeln(''); $map = ['bankNumber' => [0, 8], 'attribute' => [8, 1], 'name' => [9, 58], 'zipCode' => [67, 5], 'city' => [72, 35], 'shortname' => [107, 27], 'pan' => [134, 5], 'bic' => [139, 11], 'checkDigitPlanCalculationMethod' => [150, 2], 'recordNumber' => [152, 6], 'modificationIdentifier' => [158, 1], 'bankNumberDeletion' => [159, 1], 'successorBankNumber' => [160, 8]]; $progressBar = new ProgressBar($output); $progressBar->setRedrawFrequency($redrawFrequency = 100); $progressBar->start($lines); $validationErrors = []; foreach ($fileContentArray as $row => $line) { $line = trim($line); if (empty($line)) { continue; } $bank = new Bank(); if ($fileEncoding != mb_internal_encoding()) { $line = mb_convert_encoding($line, mb_internal_encoding(), $fileEncoding); } foreach ($map as $fieldName => $substr) { $method = 'set' . ucfirst($fieldName); $bank->{$method}(trim(mb_substr($line, $substr[0], $substr[1]))); } $errors = $validator->validate($bank); if (count($errors) > 0) { $validationErrors[] = (string) $errors; $validationErrors[] = $row . $line; } else { $entityManger->persist($bank); } if ($progressBar->getProgress() % $redrawFrequency == 0) { $entityManger->flush(); $entityManger->clear(); } $progressBar->advance(); } $progressBar->finish(); $entityManger->flush(); $entityManger->clear(); $output->writeln(''); $output->write('<error>'); dump($validationErrors); $output->writeln('</error>'); }