src/Controller/DocsController.php line 47

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use App\DataProvider\PageItemDataProvider;
  4. use App\Entity\PageOutput;
  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 DocsController extends AbstractController
  10. {
  11.     private $pageItemDataProvider;
  12.     /**
  13.      * DocsController constructor.
  14.      * @param PageItemDataProvider $pageItemDataProvider
  15.      */
  16.     public function __construct(
  17.         PageItemDataProvider $pageItemDataProvider
  18.     ) {
  19.         $this->pageItemDataProvider $pageItemDataProvider;
  20.     }
  21.     /**
  22.      * @return Response
  23.      *
  24.      * @Route("/services", name="services_redirect")
  25.      */
  26.     public function redirectServices(): Response
  27.     {
  28.         return $this->redirectToRoute("docs", [], Response::HTTP_MOVED_PERMANENTLY);
  29.     }
  30.     /**
  31.      * @Route("/docs", name="docs")
  32.      * @Route("/docs/{category}", name="docs_page")
  33.      * @Route("/docs/{category}/{section}", name="docs_page")
  34.      * @Route("/docs/{category}/{section}/{old}", name="docs_page_old")
  35.      *
  36.      * @param string $category
  37.      * @param string $section
  38.      * @param string|null $old
  39.      * @return Response
  40.      */
  41.     public function getPage(
  42.         string $category "getting-started",
  43.         string $section "introduction",
  44.         string $old null
  45.     ): Response {
  46.         $slug $this->pageItemDataProvider->translatePathToSlug($category$section);
  47.         /** @var PageOutput $page */
  48.         $page $this->pageItemDataProvider->getPage($slug);
  49.         // This should clean up the remaining pages we removed from search engines
  50.         if (null === $page) {
  51.             return new Response(''Response::HTTP_GONE);
  52.         }
  53.         return $this->render('docs/page.html.twig', [
  54.             'page' => $page,
  55.         ]);
  56.     }
  57.     /**
  58.      * @Route("/account/docs", name="account_docs")
  59.      * @Route("/account/docs/{category}", name="account_docs_page")
  60.      * @Route("/account/docs/{category}/{section}", name="account_docs_page")
  61.      *
  62.      * @param string $category
  63.      * @param string|null $section
  64.      * @return Response
  65.      */
  66.     public function docsPage(string $category "getting-started"string $section null): Response
  67.     {
  68.         $slug $this->pageItemDataProvider->translatePathToSlug($category$section);
  69.         /** @var PageOutput $page */
  70.         $page $this->pageItemDataProvider->getPage($slug);
  71.         if (null === $page) {
  72.             throw new NotFoundHttpException(sprintf('Page "%s" was not found'$category));
  73.         }
  74.         return $this->render('account/docs_page.html.twig', [
  75.             'page' => $page,
  76.         ]);
  77.     }
  78. }