예제 #1
0
 /**
  * Populate content for the request
  *
  * @param Route $route
  * @param Request $request
  * @param Response $response
  */
 protected function setLastModifiedHeader(Route $route, Request $request, Response $response)
 {
     $content = $route->getContent();
     if ($route->isList()) {
         $dates = array_map(function (array $content) {
             return $content['lastModified'];
         }, $request->attributes->get($content . 's'));
         rsort($dates);
         $lastModified = $dates[0];
     } else {
         $lastModified = $request->attributes->get($content)['lastModified'];
     }
     $response->headers->set('Last-Modified', $lastModified);
 }
 /**
  * Populate content for the request
  *
  * @param Route $route
  * @param Request $request
  */
 protected function populateContent(Route $route, Request $request)
 {
     $content = $route->getContent();
     $name = $content;
     if ($route->isList()) {
         $name .= 's';
         $value = $this->repository->getContents($content, $route->getIndexBy(), $route->getOrder());
         if ($route->isPaginated()) {
             $paginator = new Paginator($value, $route->getPerPage());
             $value = $paginator->get($request->attributes->get('page'));
             $request->attributes->set('paginator', $paginator);
         }
     } else {
         $value = $this->repository->getContent($content, $request->attributes->get($content));
     }
     $request->attributes->set($name, $value);
 }
예제 #3
0
 /**
  * Dump route content to destination file
  *
  * @param Route $route
  * @param string $name
  */
 protected function dump(Route $route, $name)
 {
     if (!$route->isVisible()) {
         return;
     }
     if (!in_array('GET', $route->getMethods())) {
         throw new Exception(sprintf('Only GET mehtod supported, "%s" given.', $name));
     }
     if ($route->hasContent()) {
         if ($route->isList()) {
             if ($route->isPaginated()) {
                 $this->buildPaginatedRoute($route, $name);
             } else {
                 $this->buildListRoute($route, $name);
             }
         } else {
             $this->buildContentRoute($route, $name);
         }
     } else {
         $this->logger->log(sprintf('Building route <comment>%s</comment>', $name));
         $this->builder->build($route, $name);
     }
 }