<?php
namespace App\Controller;
use App\Entity\Page;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
class PageController extends AbstractController
{
/**
* @Route("/{uri}.html", name="page", requirements={"uri"=".*"}, priority=-100)
* @param string $uri
* @return Response
* @throws \Exception
*/
public function index(string $uri): Response
{
$page = $this->getDoctrine()->getRepository(Page::class)->findOneBy(['uri' => $uri, 'published' => true]);
if (empty($page)) {
throw $this->createNotFoundException();
}
return $this->render($page->getTemplate()->getPath(), ['page' => $page]);
}
}