<?php
declare(strict_types=1);
namespace App\Controller;
use App\Service\DataFetcher;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
use Symfony\Component\Routing\Annotation\Route;
class SlugController extends Controller
{
#[Route('/blog/{slug}', name: 'blog.slug', methods: ['GET'])]
public function blogSlug(string $slug, DataFetcher $dataFetcher): Response
{
$page = $dataFetcher->getBlogPost($slug);
if (null === $page) {
throw new NotFoundHttpException();
}
$author = $dataFetcher->getAuthorByName($page['author']);
return $this->render('blog_post.html.twig', [
'record' => $page,
'author' => $author,
]);
}
#[Route('/portfolio/{slug}', name: 'portfolio.slug', methods: ['GET'])]
public function portfolioSlug(string $slug, DataFetcher $dataFetcher): Response
{
$page = $dataFetcher->getRealisation($slug);
if (null === $page) {
throw new NotFoundHttpException();
}
return $this->render('portfolio.html.twig', [
'record' => $page,
]);
}
}