visitsTracker = $visitsTracker; } public function configure() { $this->setName('shortcode:visits') ->setDescription('Returns the detailed visits information for provided short code') ->addArgument('shortCode', InputArgument::REQUIRED, 'The short code which visits we want to get') ->addOption( 'startDate', 's', InputOption::VALUE_OPTIONAL, 'Allows to filter visits, returning only those older than start date' ) ->addOption( 'endDate', 'e', InputOption::VALUE_OPTIONAL, 'Allows to filter visits, returning only those newer than end date' ); } public function interact(InputInterface $input, OutputInterface $output) { $shortCode = $input->getArgument('shortCode'); if (! empty($shortCode)) { return; } /** @var QuestionHelper $helper */ $helper = $this->getHelper('question'); $question = new Question( 'A short code was not provided. Which short code do you want to use?: ' ); $shortCode = $helper->ask($input, $output, $question); if (! empty($shortCode)) { $input->setArgument('shortCode', $shortCode); } } 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([ 'Referer', 'Date', 'Remote Address', 'User agent', ]); foreach ($visits as $row) { $rowData = $row->jsonSerialize(); // Unset location info unset($rowData['visitLocation']); $table->addRow(array_values($rowData)); } $table->render(); } protected function getDateOption(InputInterface $input, $key) { $value = $input->getOption($key); if (isset($value)) { $value = new \DateTime($value); } return $value; } }