KarlComSe /
mvc-report
| 1 | <?php |
||
| 2 | |||
| 3 | namespace App\Controller; |
||
| 4 | |||
| 5 | # Generic use statements |
||
| 6 | use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; |
||
| 7 | use Symfony\Component\HttpFoundation\Response; |
||
| 8 | use Symfony\Component\Routing\Attribute\Route; |
||
| 9 | |||
| 10 | # Specific use statements |
||
| 11 | use App\Service\QuoteService; |
||
| 12 | |||
| 13 | class IndexController extends AbstractController |
||
| 14 | { |
||
| 15 | protected QuoteService $quoteService; |
||
| 16 | |||
| 17 | public function __construct(QuoteService $quoteService) |
||
| 18 | { |
||
| 19 | $this->quoteService = $quoteService; |
||
| 20 | } |
||
| 21 | |||
| 22 | #[Route('/', name: 'app_home')] |
||
| 23 | public function index(): Response |
||
| 24 | { |
||
| 25 | $json = $this->quoteService->getAssadsQuote()->getContent(); |
||
| 26 | if ($json === false || $json === null || $json === '') { |
||
|
0 ignored issues
–
show
introduced
by
Loading history...
|
|||
| 27 | return new Response('Failed to get quote data.'); |
||
| 28 | } |
||
| 29 | $quote = json_decode( |
||
| 30 | $json, |
||
| 31 | true |
||
| 32 | ); |
||
| 33 | |||
| 34 | $data = [ |
||
| 35 | 'quoteData' => [ |
||
| 36 | 'quote' => $quote['quote'], |
||
| 37 | 'explanation' => $quote['explanation'] |
||
| 38 | ] |
||
| 39 | ]; |
||
| 40 | |||
| 41 | return $this->render('index.html.twig', $data); |
||
| 42 | } |
||
| 43 | } |
||
| 44 |