oneOfCommandArguments() public static method

public static oneOfCommandArguments ( ) : InvalidArgumentException
return InvalidArgumentException
コード例 #1
0
 /**
  *
  */
 public function testOneOfCommandArguments()
 {
     /** @var \BrowscapPHP\Exception\InvalidArgumentException $exception */
     $exception = InvalidArgumentException::oneOfCommandArguments('http://example.org', 'Uri not reachable');
     self::assertInstanceOf('\\BrowscapPHP\\Exception\\InvalidArgumentException', $exception);
     self::assertSame('One of the command arguments "http://example.org", "Uri not reachable" is required', $exception->getMessage());
 }
コード例 #2
0
 /**
  * @param InputInterface  $input
  * @param OutputInterface $output
  *
  * @throws \UnexpectedValueException
  * @throws \BrowscapPHP\Exception\InvalidArgumentException
  * @return int|null|void
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     if (!$input->getOption('log-file') && !$input->getOption('log-dir')) {
         throw InvalidArgumentException::oneOfCommandArguments('log-file', 'log-dir');
     }
     $loggerHelper = new LoggerHelper();
     $logger = $loggerHelper->create($input->getOption('debug'));
     $browscap = new Browscap();
     $loader = new IniLoader();
     $collection = ReaderFactory::factory();
     $fs = new Filesystem();
     $browscap->setLogger($logger)->setCache($this->getCache($input));
     /** @var $file \Symfony\Component\Finder\SplFileInfo */
     foreach ($this->getFiles($input) as $file) {
         $this->uas = [];
         $path = $this->getPath($file);
         $this->countOk = 0;
         $this->countNok = 0;
         $logger->info('Analyzing file "' . $file->getPathname() . '"');
         $lines = file($path);
         if (empty($lines)) {
             $logger->info('Skipping empty file "' . $file->getPathname() . '"');
             continue;
         }
         $this->totalCount = count($lines);
         foreach ($lines as $line) {
             $this->handleLine($output, $collection, $browscap, $line);
         }
         $this->outputProgress($output, '', true);
         arsort($this->uas, SORT_NUMERIC);
         try {
             $fs->dumpFile($input->getArgument('output') . '/output.txt', implode(PHP_EOL, array_unique($this->undefinedClients)));
         } catch (IOException $e) {
             // do nothing
         }
         try {
             $fs->dumpFile($input->getArgument('output') . '/output-with-amount.txt', $this->createAmountContent());
         } catch (IOException $e) {
             // do nothing
         }
         try {
             $fs->dumpFile($input->getArgument('output') . '/output-with-amount-and-type.txt', $this->createAmountTypeContent());
         } catch (IOException $e) {
             // do nothing
         }
     }
     $outputFile = $input->getArgument('output') . '/output.txt';
     try {
         $fs->dumpFile($outputFile, implode(PHP_EOL, array_unique($this->undefinedClients)));
     } catch (IOException $e) {
         throw new \UnexpectedValueException('writing to file "' . $outputFile . '" failed', 0, $e);
     }
     try {
         $fs->dumpFile($input->getArgument('output') . '/output-with-amount.txt', $this->createAmountContent());
     } catch (IOException $e) {
         // do nothing
     }
     try {
         $fs->dumpFile($input->getArgument('output') . '/output-with-amount-and-type.txt', $this->createAmountTypeContent());
     } catch (IOException $e) {
         // do nothing
     }
 }