src/Controller/SlugController.php line 32

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. namespace App\Controller;
  4. use App\Service\DataFetcher;
  5. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  6. use Symfony\Component\HttpFoundation\Response;
  7. use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
  8. use Symfony\Component\Routing\Annotation\Route;
  9. class SlugController extends Controller
  10. {
  11.     #[Route('/blog/{slug}'name'blog.slug'methods: ['GET'])]
  12.     public function blogSlug(string $slugDataFetcher $dataFetcher): Response
  13.     {
  14.         $page $dataFetcher->getBlogPost($slug);
  15.         if (null === $page) {
  16.             throw new NotFoundHttpException();
  17.         }
  18.         $author $dataFetcher->getAuthorByName($page['author']);
  19.         return $this->render('blog_post.html.twig', [
  20.             'record' => $page,
  21.             'author' => $author,
  22.         ]);
  23.     }
  24.     #[Route('/portfolio/{slug}'name'portfolio.slug'methods: ['GET'])]
  25.     public function portfolioSlug(string $slugDataFetcher $dataFetcher): Response
  26.     {
  27.         $page $dataFetcher->getRealisation($slug);
  28.         if (null === $page) {
  29.             throw new NotFoundHttpException();
  30.         }
  31.         return $this->render('portfolio.html.twig', [
  32.             'record' => $page,
  33.         ]);
  34.     }
  35. }