public function indexAction(Request $request)
{
/** @var \Networking\InitCmsBundle\Lib\PhpCacheInterface $phpCache */
$phpCache = $this->get('networking_init_cms.lib.php_cache');
/** @var PageSnapshotInterface $page */
$page = $request->get('_content');
$template = $request->get('_template');
if ($template instanceof \Sensio\Bundle\FrameworkExtraBundle\Configuration\Template) {
$template = $template->getTemplate();
}
if ($phpCache->isCacheable($request, $this->getUser()) && $page instanceof PageSnapshotInterface) {
if (!$this->isSnapshotActive($page)) {
throw new NotFoundHttpException();
}
if ($this->getSnapshotVisibility($page) != PageInterface::VISIBILITY_PUBLIC) {
if (false === $this->get('security.authorization_checker')->isGranted('ROLE_USER')) {
throw new AccessDeniedException();
}
}
$updatedAt = $phpCache->get(sprintf('page_%s_created_at', $page->getId()));
$cacheKey = $request->getLocale() . $request->getPathInfo();
if ($updatedAt != $page->getSnapshotDate()) {
$phpCache->delete($cacheKey);
}
$response = $phpCache->get($request->getLocale() . $request->getPathInfo());
if (!$response || !$response instanceof Response) {
$params = $this->getPageParameters($request);
if ($params instanceof RedirectResponse) {
return $params;
}
$html = $this->renderView($template, $params);
$response = new Response($html);
$phpCache->set($cacheKey, $response);
$phpCache->set(sprintf('page_%s_created_at', $page->getId()), $page->getSnapshotDate());
} else {
$phpCache->touch($cacheKey);
$phpCache->touch(sprintf('page_%s_created_at', $page->getId()));
}
} else {
$params = $this->getPageParameters($request);
if ($params instanceof RedirectResponse) {
return $params;
}
$html = $this->renderView($template, $params);
$response = new Response($html);
}
$response->headers->setCookie(new Cookie('_locale', $request->getLocale()));
return $response;
}