|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace App\Controller; |
|
4
|
|
|
|
|
5
|
|
|
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; |
|
6
|
|
|
use Symfony\Component\HttpFoundation\Response; |
|
7
|
|
|
use Symfony\Component\HttpFoundation\Request; |
|
8
|
|
|
use Symfony\Component\HttpFoundation\Session\SessionInterface; |
|
9
|
|
|
use Symfony\Component\Routing\Annotation\Route; |
|
10
|
|
|
use Symfony\Component\Routing\Generator\UrlGeneratorInterface; |
|
11
|
|
|
|
|
12
|
|
|
class RouteControllerTwig extends AbstractController |
|
13
|
|
|
{ |
|
14
|
|
|
#[Route("/lucky", name: "lucky_number")] |
|
15
|
|
|
public function number(): Response |
|
16
|
|
|
{ |
|
17
|
|
|
$number = random_int(0, 100); |
|
18
|
|
|
|
|
19
|
|
|
$data = [ |
|
20
|
|
|
'number' => $number |
|
21
|
|
|
]; |
|
22
|
|
|
|
|
23
|
|
|
return $this->render('lucky_number.html.twig', $data); |
|
24
|
|
|
} |
|
25
|
|
|
|
|
26
|
|
|
#[Route("/presentation", name: "presentation")] |
|
27
|
|
|
public function presentation(): Response |
|
28
|
|
|
{ |
|
29
|
|
|
return $this->render('presentation.html.twig'); |
|
30
|
|
|
} |
|
31
|
|
|
|
|
32
|
|
|
#[Route("/about", name: "about")] |
|
33
|
|
|
public function about(): Response |
|
34
|
|
|
{ |
|
35
|
|
|
return $this->render('about.html.twig'); |
|
36
|
|
|
} |
|
37
|
|
|
|
|
38
|
|
|
#[Route("/report", name: "report")] |
|
39
|
|
|
public function report(): Response |
|
40
|
|
|
{ |
|
41
|
|
|
return $this->render('report.html.twig'); |
|
42
|
|
|
} |
|
43
|
|
|
#[Route("/api", name: "api_landing")] |
|
44
|
|
|
public function landingPage(UrlGeneratorInterface $urlGenerator): Response |
|
45
|
|
|
{ |
|
46
|
|
|
$jsonRoutes = [ |
|
47
|
|
|
[ |
|
48
|
|
|
'path' => '/api/quote', |
|
49
|
|
|
'description' => 'Get random quote', |
|
50
|
|
|
], |
|
51
|
|
|
[ |
|
52
|
|
|
'path' => '/api/deck', |
|
53
|
|
|
'description' => 'Get the deck of cards', |
|
54
|
|
|
], |
|
55
|
|
|
[ |
|
56
|
|
|
'path' => '/api/deck/shuffle', |
|
57
|
|
|
'description' => 'Shuffle the deck of cards', |
|
58
|
|
|
], |
|
59
|
|
|
[ |
|
60
|
|
|
'path' => '/api/deck/draw/{number}', |
|
61
|
|
|
'description' => 'Draw cards from the deck', |
|
62
|
|
|
], |
|
63
|
|
|
[ |
|
64
|
|
|
'path' => '/api/game/standings', |
|
65
|
|
|
'description' => 'Get current standings in Blackjack game', |
|
66
|
|
|
], |
|
67
|
|
|
[ |
|
68
|
|
|
'path' => '/api/library/books', |
|
69
|
|
|
'description' => 'Show all books in library', |
|
70
|
|
|
], |
|
71
|
|
|
[ |
|
72
|
|
|
'path' => '/api/library/book/{isbn}', |
|
73
|
|
|
'description' => 'Show a book by ISBN, example: ', |
|
74
|
|
|
'url' => $urlGenerator->generate('api_library_book', ['isbn' => 9789171370181], UrlGeneratorInterface::ABSOLUTE_URL), |
|
75
|
|
|
] |
|
76
|
|
|
]; |
|
77
|
|
|
return $this->render('api_landing.html.twig', [ |
|
78
|
|
|
'jsonRoutes' => $jsonRoutes, |
|
79
|
|
|
]); |
|
80
|
|
|
} |
|
81
|
|
|
|
|
82
|
|
|
#[Route("/session", name: "session")] |
|
83
|
|
|
public function displaySession(SessionInterface $session): Response |
|
84
|
|
|
{ |
|
85
|
|
|
// Start session if not already started |
|
86
|
|
|
if (!$session->isStarted()) { |
|
87
|
|
|
$session->start(); |
|
88
|
|
|
} |
|
89
|
|
|
|
|
90
|
|
|
$sessionName = $session->getName(); |
|
91
|
|
|
$sessionId = $session->getId(); |
|
92
|
|
|
$sessionCookie = $this->getParameter('session.storage.options'); |
|
93
|
|
|
|
|
94
|
|
|
// Pass session information to template |
|
95
|
|
|
return $this->render('session.html.twig', [ |
|
96
|
|
|
'sessionName' => $sessionName, |
|
97
|
|
|
'sessionId' => $sessionId, |
|
98
|
|
|
'sessionCookie' => $sessionCookie, |
|
99
|
|
|
'sessionData' => $session->all(), |
|
100
|
|
|
]); |
|
101
|
|
|
} |
|
102
|
|
|
#[Route("/session/destroy", name: "session_destroy")] |
|
103
|
|
|
public function destroySession(SessionInterface $session): Response |
|
104
|
|
|
{ |
|
105
|
|
|
// Invalidate the session |
|
106
|
|
|
$session->invalidate(); |
|
107
|
|
|
|
|
108
|
|
|
// Start session if not already started |
|
109
|
|
|
if (!$session->isStarted()) { |
|
110
|
|
|
$session->start(); |
|
111
|
|
|
} |
|
112
|
|
|
|
|
113
|
|
|
// Add flash message |
|
114
|
|
|
$this->addFlash( |
|
115
|
|
|
'notice', |
|
116
|
|
|
'Session destroyed!' |
|
117
|
|
|
); |
|
118
|
|
|
|
|
119
|
|
|
return $this->render('session_destroy.html.twig'); |
|
120
|
|
|
} |
|
121
|
|
|
|
|
122
|
|
|
#[Route("/metrics", name: "metrics")] |
|
123
|
|
|
public function metrics(): Response |
|
124
|
|
|
{ |
|
125
|
|
|
return $this->render('metrics.html.twig'); |
|
126
|
|
|
} |
|
127
|
|
|
|
|
128
|
|
|
/** |
|
129
|
|
|
* Landing page. |
|
130
|
|
|
*/ |
|
131
|
|
|
#[Route('/library', name: 'app_library')] |
|
132
|
|
|
public function index(): Response |
|
133
|
|
|
{ |
|
134
|
|
|
return $this->render('book/index.html.twig', [ |
|
135
|
|
|
'controller_name' => 'BookController', |
|
136
|
|
|
]); |
|
137
|
|
|
} |
|
138
|
|
|
|
|
139
|
|
|
} |
|
140
|
|
|
|