<?php
/**
* @author Antony Tkachenko <at@canaryknight.ru>
*/
namespace App\Controller;
use App\Entity\ModulePage;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
use Symfony\Component\Routing\Annotation\Route;
class PageController extends AbstractController
{
/**
* @Route("/module/{slug}", name="module_page.ru", methods={"GET"})
*/
public function modulePage(ModulePage $module): Response
{
if (true !== $module->getActive() && !$this->isGranted('ROLE_ADMIN')) {
throw new NotFoundHttpException();
}
$date = $module->getUpdatedAt() ?: $module->getCreatedAt();
$modified = $date->format('D, d M Y H:i:s \G\M\T');
$response = $this->render('module/page.html.twig', [
'module' => $module,
'description' => $module->getMetaDescription(),
'keywords' => $module->getMetaKeywords(),
'title' => $module->getPageTitle(),
'modified' => $modified,
]);
$response->headers->set('Last-Modified', $modified);
return $response;
}
}