public function testWithLastModified()
 {
     $now = time();
     $cacheProvider = new CacheProvider();
     $res = $cacheProvider->withLastModified(new Response(), $now);
     $lastModified = $res->getHeaderLine('Last-Modified');
     $this->assertEquals(gmdate('D, d M Y H:i:s T', $now), $lastModified);
 }
示例#2
0
 public function dispatch($request, $response, $args)
 {
     $event = $this->eventService->getLatestEvent();
     $filter = $this->contentService->getTwigFilter();
     $this->view->getEnvironment()->addFilter($filter);
     $previousEvents = $this->eventService->getPastEvents();
     $resWithETag = $this->cache->withETag($response, $event->getMeetupID());
     $this->view->render($response, 'home.twig', ['event' => $event, 'previousEvents' => $previousEvents]);
     return $resWithETag;
 }
示例#3
0
 public function eventByYearMonth(Request $request, Response $response, $args)
 {
     $year = intval($args["year"]);
     $month = intval($args["month"]);
     $eventMeta = $this->eventManager->getByYearMonth($year, $month);
     $event = $this->eventService->getEventById($eventMeta[0]['meetup_id']);
     $resWithETag = $this->cache->withETag($response, $eventMeta[0]['meetup_id']);
     $previousEvents = $this->eventService->getPastEvents();
     $this->view->render($response, 'event.twig', ['event' => $event, 'eventMeta' => $eventMeta[0], 'previousEvents' => $previousEvents]);
     return $resWithETag;
 }
示例#4
0
 /**
  * Encode DataObject collection.
  *
  * @param  CollectionInterface $action_result
  * @param  ResponseInterface   $response
  * @return ResponseInterface
  */
 private function encodeCollection(CollectionInterface $action_result, ResponseInterface $response)
 {
     $response = $response->write(json_encode($action_result))->withStatus(200);
     if ($action_result->canBeEtagged()) {
         if ($action_result->getApplicationIdentifier() != $this->app_identifier) {
             $action_result->setApplicationIdentifier($this->app_identifier);
             // Sign collection etag with app identifier
         }
         $response = $this->cache_provider->withEtag($response, $action_result->getEtag($this->user_identifier));
         $response = $this->cache_provider->withExpires($response, '+90 days');
     }
     if ($action_result->getCurrentPage() && $action_result->getItemsPerPage()) {
         $response = $response->withHeader('X-PaginationCurrentPage', $action_result->getCurrentPage())->withHeader('X-PaginationItemsPerPage', $action_result->getItemsPerPage())->withHeader('X-PaginationTotalItems', $action_result->count());
     } else {
         $response = $response->withHeader('X-PaginationCurrentPage', 0)->withHeader('X-PaginationItemsPerPage', 0)->withHeader('X-PaginationTotalItems', $action_result->count());
     }
     return $response;
 }