Пример #1
0
 /**
  * Gets the details page.
  *
  * @return Crawler
  * @todo Refactor this as it is not possible to mock currently
  */
 private function getDetails()
 {
     if (is_null($this->details)) {
         $url = $this->crawler->selectLink($this->getTitle())->link()->getUri();
         $scraper = new Scraper();
         $this->details = $scraper->fetch($url);
         $this->length = $scraper->getResponseSize();
     }
     return $this->details;
 }
Пример #2
0
 /**
  * Executes the command.
  *
  * @param  InputInterface  $input
  * @param  OutputInterface $output
  * @return void
  * @todo Should we catch the exception if there is an invalid URL and present our own message?
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $pretty = $input->getOption('pretty');
     $url = $input->getArgument('url');
     if ($output->isVerbose()) {
         $output->writeln('<info>Processing URL ' . $url . '</info>');
     }
     $scraper = new Scraper();
     $products = $scraper->fetchAndProcess($url);
     $calculator = new ProductTotalParser($products);
     $formatter = new JsonFormatter(['results' => $products, 'total' => $calculator->getTotalPrice()]);
     $formatter->setPretty($pretty);
     if ($output->isVerbose()) {
         if ($pretty) {
             $output->writeln('<info>Enabled pretty printing</info>');
         }
         if (!count($products)) {
             $output->writeln('<error>No results found!</error>');
         }
     }
     $output->writeln($formatter->getFormatted());
 }