From 7c186a8ba6c5a23f7ec0c02d39efb36260593b4f Mon Sep 17 00:00:00 2001 From: =?utf8?q?Rapha=C3=ABl=20Gertz?= Date: Thu, 10 Oct 2024 23:19:23 +0200 Subject: [PATCH] Add constructor Add index member function --- Controller/TreeController.php | 35 ++++++++++++++++++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-) diff --git a/Controller/TreeController.php b/Controller/TreeController.php index b51c01d..a8f1992 100644 --- a/Controller/TreeController.php +++ b/Controller/TreeController.php @@ -11,15 +11,48 @@ namespace Rapsys\TreeBundle\Controller; +use Psr\Container\ContainerInterface; + use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; +use Symfony\Component\HttpFoundation\Request; +use Symfony\Component\HttpFoundation\Response; + +use Twig\Environment; /** * {@inheritdoc} */ class TreeController extends AbstractController { + /** + * Context array + */ + protected array $context = []; + /** * Creates a new tree controller + * + * @param ContainerInterface $container The ContainerInterface instance + * @param Environment $twig The twig environment instance */ - function __construct() { + function __construct(protected ContainerInterface $container, protected Environment $twig) { + } + + /** + * The index page + * + * Display file tree + * + * @param Request $request The request instance + * @return Response The rendered view + */ + public function index(Request $request, string $path): Response { + //Render template + $response = $this->twig->render('@RapsysTree/index.html.twig', $this->context); + $response->setEtag(md5($response->getContent())); + $response->setPublic(); + $response->isNotModified($request); + + //Return response + return $response; } } -- 2.41.1