Exemplo n.º 1
0
 /**
  * @param InputInterface $input
  * @param OutputInterface $output
  * @return void
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $config = Config::getInstance();
     $times = $input->getOption('times');
     if ($times < 1) {
         $output->writeln("<error>benchmark {$times} is too small</error>");
         return;
     }
     $type = $input->getArgument('type');
     $output->writeln("<info>benchmark {$type}:</info>\t<comment>{$times} times</comment>");
     switch ($type) {
         case 'all':
             foreach ($config->getQueries() as $name => $query) {
                 $this->benchmark($output, $query, $name, $times);
             }
             break;
         case 'file':
             foreach ($config->getQueries() as $name => $query) {
                 if (FileQuery::is_a($query)) {
                     $this->benchmark($output, $query, $name, $times);
                 }
             }
             break;
         case 'database':
             foreach ($config->getQueries() as $name => $query) {
                 if (DatabaseQuery::is_a($query)) {
                     $this->benchmark($output, $query, $name, $times);
                 }
             }
             break;
         default:
             $output->writeln("<error>Unknown type \"{$type}\".</error>");
             break;
     }
 }
Exemplo n.º 2
0
 /**
  * @param InputInterface $input
  * @param OutputInterface $output
  * @return void
  * @throws \Exception
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $config = Config::getInstance();
     $noProgress = $input->getOption('no-progress');
     $type = $input->getArgument('type');
     $output->writeln("<info>dump {$type}:</info>");
     switch ($type) {
         case 'default':
             foreach ($config->getQueries() as $name => $query) {
                 $this->dumpDefault($output, $query, $name, $noProgress);
             }
             break;
         case 'division':
             foreach ($config->getQueries() as $name => $query) {
                 $this->dumpDivision($output, $query, $name, $noProgress);
             }
             break;
         case 'division_id':
             foreach ($config->getQueries() as $name => $query) {
                 if (FileQuery::is_a($query)) {
                     $this->dumpDivisionWithId($output, $query, $name, $noProgress);
                 }
             }
             break;
         case 'count':
             foreach ($config->getQueries() as $name => $query) {
                 $this->dumpCount($output, $query, $name, $noProgress);
             }
             break;
         default:
             $output->writeln("<error>Unknown type \"{$type}\".</error>");
             break;
     }
 }
Exemplo n.º 3
0
 /**
  * Execute the command.
  *
  * @param  \Symfony\Component\Console\Input\InputInterface $input
  * @param  \Symfony\Component\Console\Output\OutputInterface $output
  * @return void
  */
 public function execute(InputInterface $input, OutputInterface $output)
 {
     $command = $this->executable() . ' ' . Config::getInstance()->filename;
     $process = new Process($command, realpath(__DIR__ . '/../'), array_merge($_SERVER, $_ENV), null, null);
     $process->run(function ($type, $line) use($output) {
         $output->write($line);
     });
 }
Exemplo n.º 4
0
 /**
  * @param InputInterface $input
  * @param OutputInterface $output
  * @return void
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $config = Config::getInstance();
     $ip = $input->getArgument('ip');
     $output->writeln("<info>query \"{$ip}\":</info>");
     $ip = ip2long($ip);
     foreach ($config->getQueries() as $name => $query) {
         $this->query($output, $query, $name, $ip);
     }
 }
Exemplo n.º 5
0
 /**
  * @param InputInterface $input
  * @param OutputInterface $output
  * @return null|int null or 0 if everything went fine, or an error code
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $config = Config::getInstance();
     $noProgress = $input->getOption('no-progress');
     $query = $input->getArgument('query');
     $provider = $config->getQuery($query);
     if (empty($provider)) {
         $output->writeln("<error>cannot found query \"{$query}\"</error>");
         $output->writeln("<info>you can execute \"</info>ipv4 edit<info>\" to configure the query</info>");
         return 1;
     }
     $type = $input->getOption('type');
     $filename = $config->getFilename($input->getArgument('filename'));
     $export = ExportQuery::create($type, $filename);
     if (empty($export)) {
         $output->writeln("<error>cannot found export query \"{$type}\"</error>");
         return 2;
     }
     $export->setProviders([$provider]);
     $encoding = $input->getOption('encoding');
     if (!empty($encoding)) {
         $export->setEncoding($encoding);
     }
     $ecdz = $input->getOption('ecdz');
     if ($ecdz && method_exists($export, 'setEcdz')) {
         $export->setEcdz($ecdz);
     }
     $remove_ip_in_recode = $input->getOption('remove-ip-in-recode');
     if ($remove_ip_in_recode && method_exists($export, 'setRemoveIpInRecode')) {
         $export->setRemoveIpInRecode($remove_ip_in_recode);
     }
     $output->writeln("<info>export \"{$query}\" to \"{$type}\" filename \"{$filename}\":</info>");
     if (!$noProgress) {
         $export->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 {
         $export->init();
     }
     $output->writeln('<info> completed!</info>');
     return 0;
 }
Exemplo n.º 6
0
 /**
  * @param InputInterface $input
  * @param OutputInterface $output
  * @return void
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $config = Config::getInstance();
     $force = $input->getOption('force');
     $noProgress = $input->getOption('no-progress');
     $output->writeln("<info>initialize ip database:</info>");
     foreach ($config->getQueries() as $name => $query) {
         if (empty($query->getProviders())) {
             $this->download($output, $query, $name, $force, $noProgress);
         } else {
             $this->division($output, $noProgress);
             $this->generate($output, $query, $name, $force, $noProgress);
         }
     }
 }
Exemplo n.º 7
0
 /**
  * @param InputInterface $input
  * @param OutputInterface $output
  * @return void
  * @throws \Exception
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $config = Config::getInstance();
     $cleanDivision = false;
     $type = $input->getArgument('type');
     $output->writeln("<info>clean {$type}:</info>");
     switch ($type) {
         case 'all':
             foreach ($config->getQueries() as $name => $query) {
                 if (DatabaseQuery::is_a($query)) {
                     $cleanDivision = true;
                 }
                 $this->clean($output, $query, $name);
             }
             break;
         case 'file':
             foreach ($config->getQueries() as $name => $query) {
                 if (FileQuery::is_a($query)) {
                     $this->clean($output, $query, $name);
                 }
             }
             break;
         case 'database':
             foreach ($config->getQueries() as $name => $query) {
                 if (DatabaseQuery::is_a($query)) {
                     $cleanDivision = true;
                     $this->clean($output, $query, $name);
                 }
             }
             break;
         default:
             $output->writeln("<error>Unknown type \"{$type}\".</error>");
             break;
     }
     if ($cleanDivision) {
         $this->cleanDivision($output);
     }
 }