Exemplo n.º 1
0
 /**
  * @param Request $request
  * @param Response $response
  * @param callable|null $out
  * @return null|Response
  */
 public function dispatch(Request $request, Response $response, callable $out = null)
 {
     $shortCode = $request->getAttribute('shortCode');
     $startDate = $this->getDateQueryParam($request, 'startDate');
     $endDate = $this->getDateQueryParam($request, 'endDate');
     try {
         $visits = $this->visitsTracker->info($shortCode, new DateRange($startDate, $endDate));
         return new JsonResponse(['visits' => ['data' => $visits]]);
     } catch (InvalidArgumentException $e) {
         $this->logger->warning('Provided nonexistent shortcode' . PHP_EOL . $e);
         return new JsonResponse(['error' => RestUtils::getRestErrorCodeFromException($e), 'message' => sprintf($this->translator->translate('Provided short code %s does not exist'), $shortCode)], 404);
     } catch (\Exception $e) {
         $this->logger->error('Unexpected error while parsing short code' . PHP_EOL . $e);
         return new JsonResponse(['error' => RestUtils::UNKNOWN_ERROR, 'message' => $this->translator->translate('Unexpected error occurred')], 500);
     }
 }
Exemplo n.º 2
0
 public function execute(InputInterface $input, OutputInterface $output)
 {
     $shortCode = $input->getArgument('shortCode');
     $startDate = $this->getDateOption($input, 'startDate');
     $endDate = $this->getDateOption($input, 'endDate');
     $visits = $this->visitsTracker->info($shortCode, new DateRange($startDate, $endDate));
     $table = new Table($output);
     $table->setHeaders([$this->translator->translate('Referer'), $this->translator->translate('Date'), $this->translator->translate('Remote Address'), $this->translator->translate('User agent')]);
     foreach ($visits as $row) {
         $rowData = $row->jsonSerialize();
         // Unset location info
         unset($rowData['visitLocation']);
         $table->addRow(array_values($rowData));
     }
     $table->render();
 }