diff --git a/config/autoload/cli.global.php b/config/autoload/cli.global.php
index 1d5ea78f..1276cc9e 100644
--- a/config/autoload/cli.global.php
+++ b/config/autoload/cli.global.php
@@ -8,6 +8,7 @@ return [
Command\GenerateShortcodeCommand::class,
Command\ResolveUrlCommand::class,
Command\ListShortcodesCommand::class,
+ Command\GetVisitsCommand::class,
]
],
diff --git a/config/autoload/services.global.php b/config/autoload/services.global.php
index 1133642d..4d6cc40e 100644
--- a/config/autoload/services.global.php
+++ b/config/autoload/services.global.php
@@ -47,6 +47,7 @@ return [
CLI\Command\GenerateShortcodeCommand::class => AnnotatedFactory::class,
CLI\Command\ResolveUrlCommand::class => AnnotatedFactory::class,
CLI\Command\ListShortcodesCommand::class => AnnotatedFactory::class,
+ CLI\Command\GetVisitsCommand::class => AnnotatedFactory::class,
// Middleware
Middleware\Routable\RedirectMiddleware::class => AnnotatedFactory::class,
diff --git a/src/CLI/Command/GenerateShortcodeCommand.php b/src/CLI/Command/GenerateShortcodeCommand.php
index ea6fc929..ffc355db 100644
--- a/src/CLI/Command/GenerateShortcodeCommand.php
+++ b/src/CLI/Command/GenerateShortcodeCommand.php
@@ -88,8 +88,6 @@ class GenerateShortcodeCommand extends Command
$output->writeln(
sprintf('Provided URL "%s" is invalid. Try with a different one.', $longUrl)
);
- } catch (\Exception $e) {
- $output->writeln('' . $e . '');
}
}
}
diff --git a/src/CLI/Command/GetVisitsCommand.php b/src/CLI/Command/GetVisitsCommand.php
new file mode 100644
index 00000000..3c4e796d
--- /dev/null
+++ b/src/CLI/Command/GetVisitsCommand.php
@@ -0,0 +1,77 @@
+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');
+ }
+
+ 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');
+ $visits = $this->visitsTracker->info($shortCode);
+ $table = new Table($output);
+ $table->setHeaders([
+ 'Referer',
+ 'Date',
+ 'Temote Address',
+ 'User agent',
+ ]);
+
+ foreach ($visits as $row) {
+ $table->addRow(array_values($row->jsonSerialize()));
+ }
+ $table->render();
+ }
+}
diff --git a/src/CLI/Command/ResolveUrlCommand.php b/src/CLI/Command/ResolveUrlCommand.php
index 73b330d9..4eb5ff41 100644
--- a/src/CLI/Command/ResolveUrlCommand.php
+++ b/src/CLI/Command/ResolveUrlCommand.php
@@ -73,8 +73,6 @@ class ResolveUrlCommand extends Command
$output->writeln(
sprintf('Provided short code "%s" has an invalid format.', $shortCode)
);
- } catch (\Exception $e) {
- $output->writeln('' . $e . '');
}
}
}