]> Raphaël G. Git Repositories - treebundle/blob - Controller/TreeController.php
53bd4298b0094d92495c3aef798b685ee91703b6
[treebundle] / Controller / TreeController.php
1 <?php declare(strict_types=1);
2
3 /*
4 * This file is part of the Rapsys TreeBundle package.
5 *
6 * (c) Raphaël Gertz <symfony@rapsys.eu>
7 *
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
10 */
11
12 namespace Rapsys\TreeBundle\Controller;
13
14 use Psr\Container\ContainerInterface;
15
16 use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
17 use Symfony\Component\HttpFoundation\Request;
18 use Symfony\Component\HttpFoundation\Response;
19
20 use Twig\Environment;
21
22 /**
23 * {@inheritdoc}
24 */
25 class TreeController extends AbstractController {
26 /**
27 * Context array
28 */
29 protected array $context = [];
30
31 /**
32 * Creates a new tree controller
33 *
34 * @param ContainerInterface $container The ContainerInterface instance
35 * @param Environment $twig The twig environment instance
36 */
37 function __construct(protected ContainerInterface $container, protected Environment $twig) {
38 }
39
40 /**
41 * The index page
42 *
43 * Display file tree
44 *
45 * @param Request $request The request instance
46 * @return Response The rendered view
47 */
48 public function index(Request $request, string $path): Response {
49 //Set title
50 $this->context['title'] = [
51 'page' => 'Page title',
52 'section' => 'Section title',
53 'site' => 'Site title'
54 ];
55
56 //Set canonical
57 $this->context['canonical'] = '';
58
59 //Render template
60 $response = $this->twig->render('@RapsysTree/index.html.twig', $this->context);
61 var_dump($response);
62 exit;
63 $response->setEtag(md5($response->getContent()));
64 $response->setPublic();
65 $response->isNotModified($request);
66
67 //Return response
68 return $response;
69 }
70 }