| 12345678910111213141516171819202122232425262728293031323334353637 |
- <?php
- namespace App\Service\Cron\UI;
- use Symfony\Component\Console\Helper\ProgressBar;
- use Symfony\Component\Console\Output\OutputInterface;
- /**
- * Console user interface.
- *
- * Use it to make communicate cron-jobs with command output
- */
- class ConsoleUI implements CronUIInterface
- {
- protected ProgressBar $progressBar;
- public function __construct(
- private OutputInterface $output,
- ) {
- $this->progressBar = new ProgressBar($output, 0);
- }
- public function print(string $message): void
- {
- $this->output->writeln($message);
- }
- public function progress(int $i, int $total): void
- {
- $this->progressBar->setMaxSteps($total);
- $this->progressBar->setProgress($i);
- if ($i === $total) {
- $this->print(''); // to force a line break after the progression bar ends
- }
- }
- }
|