getStation(); $tz = $station->getTimezoneObject(); $queryParams = $request->getQueryParams(); if (isset($queryParams['start'])) { [$startDate, $endDate] = $this->getDateRange($request); $cacheKey = 'api_station_' . $station->getId() . '_schedule_' . $startDate->format('Ymd') . '-' . $endDate->format('Ymd'); $events = $cache->get( $cacheKey, function (CacheItem $item) use ( $station, $scheduleRepo, $scheduleApiGenerator, $scheduler, $startDate, $endDate ) { $item->expiresAfter(600); $nowTz = CarbonImmutable::now($station->getTimezoneObject()); $events = $scheduleRepo->getAllScheduledItemsForStation($station); return $this->getEvents( $startDate, $endDate, $nowTz, $scheduler, $events, [$scheduleApiGenerator, '__invoke'] ); } ); } else { if (!empty($queryParams['now'])) { $now = CarbonImmutable::parse($queryParams['now'], $tz); $cacheKey = 'api_station_' . $station->getId() . '_schedule_' . $now->format('Ymd_gia'); } else { $now = CarbonImmutable::now($tz); $cacheKey = 'api_station_' . $station->getId() . '_schedule_upcoming'; } $events = $cache->get( $cacheKey, function (CacheItem $item) use ($scheduleRepo, $station, $now) { $item->expiresAfter(60); return $scheduleRepo->getUpcomingSchedule($station, $now); } ); $rows = (int)$request->getQueryParam('rows', 5); $events = array_slice($events, 0, $rows); } return $response->withJson($events); } }