/** * 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); }
/** * Build content route * * @param Route $route * @param string $name */ protected function buildContentRoute(Route $route, $name) { $contentType = $route->getContent(); $contents = $this->app['content_repository']->listContents($contentType); $this->logger->log(sprintf('Building route <comment>%s</comment> for <info>%s</info> <comment>%s(s)</comment>', $name, count($contents), $route->getContent())); $this->logger->getProgress(count($contents)); $this->logger->start(); foreach ($contents as $content) { $this->builder->build($route, $name, [$contentType => $content]); $this->logger->advance(); } $this->logger->finish(); }
/** * Get destination file path for the given route / parameters * * @param Route $route * @param array $parameters * * @return string */ protected function getFilePath(Route $route, array $parameters = []) { $filepath = trim($route->getFilePath(), '/'); foreach ($route->getDefaults() as $key => $value) { if (isset($parameters[$key]) && $parameters[$key] == $value) { $filepath = rtrim(preg_replace(sprintf('#{%s}/?#', $key), null, $filepath), '/'); } } foreach ($parameters as $key => $value) { $filepath = str_replace(sprintf('{%s}', $key), (string) $value, $filepath); } return $filepath; }