Example #1
0
 /**
  * @param Query $query
  * @param string $name
  * @param bool $force
  * @return void
  * @throws \Exception
  */
 protected function generate(Query $query, $name, $force)
 {
     $use = implode(', ', $query->getProviders());
     if (!$force && count($query) > 0) {
         $this->stdout("use exist {$name} table.\n", Console::FG_YELLOW);
     } else {
         $this->stdout("generate {$name} table with {$use}:\n", Console::FG_GREEN);
         if (empty($this->controller->noProgress)) {
             $query->init(function ($code, $n) {
                 static $total = 0;
                 switch ($code) {
                     case 0:
                         Console::startProgress(0, $n);
                         $total = $n;
                         break;
                     case 1:
                         Console::updateProgress($n, $total);
                         break;
                     case 2:
                         Console::updateProgress($total, $total);
                         Console::endProgress();
                         break;
                 }
             });
         } else {
             $query->init();
         }
         $this->stdout(" completed!\n", Console::FG_GREEN);
     }
 }
Example #2
0
 /**
  * @param OutputInterface $output
  * @param Query $query
  * @param string $name
  * @param bool $force
  * @param bool $noProgress
  * @return void
  * @throws \Exception
  */
 protected function generate(OutputInterface $output, Query $query, $name, $force, $noProgress)
 {
     $use = implode(', ', $query->getProviders());
     if (!$force && $query->exists()) {
         $output->writeln("<comment>use exist {$name} table.</comment>", OutputInterface::VERBOSITY_VERBOSE);
     } else {
         $output->writeln("<info>generate {$name} table with {$use}:</info>");
         if (!$noProgress) {
             $query->init(function ($code, $n) use($output) {
                 switch ($code) {
                     case 0:
                         $this->progress = new ProgressBar($output, $n);
                         $this->progress->start();
                         break;
                     case 1:
                         $this->progress->setProgress($n);
                         break;
                     case 2:
                         $this->progress->finish();
                         break;
                 }
             });
         } else {
             $query->init();
         }
         $output->writeln('<info> completed!</info>');
     }
 }