<?php
namespace App\Controller;
use App\DataProvider\PageItemDataProvider;
use App\Entity\PageOutput;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
use Symfony\Component\Routing\Annotation\Route;
class DocsController extends AbstractController
{
private $pageItemDataProvider;
/**
* DocsController constructor.
* @param PageItemDataProvider $pageItemDataProvider
*/
public function __construct(
PageItemDataProvider $pageItemDataProvider
) {
$this->pageItemDataProvider = $pageItemDataProvider;
}
/**
* @return Response
*
* @Route("/services", name="services_redirect")
*/
public function redirectServices(): Response
{
return $this->redirectToRoute("docs", [], Response::HTTP_MOVED_PERMANENTLY);
}
/**
* @Route("/docs", name="docs")
* @Route("/docs/{category}", name="docs_page")
* @Route("/docs/{category}/{section}", name="docs_page")
* @Route("/docs/{category}/{section}/{old}", name="docs_page_old")
*
* @param string $category
* @param string $section
* @param string|null $old
* @return Response
*/
public function getPage(
string $category = "getting-started",
string $section = "introduction",
string $old = null
): Response {
$slug = $this->pageItemDataProvider->translatePathToSlug($category, $section);
/** @var PageOutput $page */
$page = $this->pageItemDataProvider->getPage($slug);
// This should clean up the remaining pages we removed from search engines
if (null === $page) {
return new Response('', Response::HTTP_GONE);
}
return $this->render('docs/page.html.twig', [
'page' => $page,
]);
}
/**
* @Route("/account/docs", name="account_docs")
* @Route("/account/docs/{category}", name="account_docs_page")
* @Route("/account/docs/{category}/{section}", name="account_docs_page")
*
* @param string $category
* @param string|null $section
* @return Response
*/
public function docsPage(string $category = "getting-started", string $section = null): Response
{
$slug = $this->pageItemDataProvider->translatePathToSlug($category, $section);
/** @var PageOutput $page */
$page = $this->pageItemDataProvider->getPage($slug);
if (null === $page) {
throw new NotFoundHttpException(sprintf('Page "%s" was not found', $category));
}
return $this->render('account/docs_page.html.twig', [
'page' => $page,
]);
}
}