visitsTracker = $visitsTracker; } /** * @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'); try { $visits = $this->visitsTracker->info($shortCode); return new JsonResponse([ 'visits' => [ 'data' => $visits, // 'pagination' => [], ] ]); } catch (InvalidArgumentException $e) { return new JsonResponse([ 'error' => RestUtils::getRestErrorCodeFromException($e), 'message' => sprintf('Provided short code "%s" is invalid', $shortCode), ], 400); } catch (\Exception $e) { return new JsonResponse([ 'error' => RestUtils::UNKNOWN_ERROR, 'message' => 'Unexpected error occured', ], 500); } } }