<?php
namespace App\Controller;
use App\DTO\AppDTO;
use App\Service\Cache\Cache;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Component\HttpFoundation\RequestStack;
use App\RepositoryInterface\PageRepositoryInterface;
class PageController extends AbstractASController
{
//Repositories
protected PageRepositoryInterface $Pages;
public function __construct(PageRepositoryInterface $Pages, RequestStack $requestStack)
{
$this->requestStack = $requestStack;
$this->Pages = $Pages;
}
#[Route(path: '/{page_intname}', name: 'static_page_no_locale', defaults: ['_locale' => '%app.default_lang%'])]
#[Route(path: '/{_locale}/{page_intname}', name: 'static_page', requirements: ['_locale' => '%app.langs%'])]
public function index(string $page_intname, AppDTO $app): Response
{
$page = $this->Pages->getByName($page_intname);
if (!$page) {
throw $this->createNotFoundException();
}
$response = $this->render('page/static.html.twig', [
'page_name' => $page_intname,
'page' => $page,
'pageblocks' => $page->getBlocks(),
'photos' => $page->getPhotos(),
'controller_name' => 'PageController',
]);
$response = Cache::http($response, $this->getParameter('app.http_cache_time'));
return $response;
}
}