src/Controller/LuckyController.php line 17

  1. <?php
  2. // src/Controller/LuckyController.php
  3. namespace App\Controller;
  4. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  5. use Symfony\Component\HttpFoundation\Response;
  6. use Symfony\Component\Routing\Annotation\Route;
  7. class LuckyController extends AbstractController
  8. {
  9.     #[Route('/lucky/number/{min}/{max}')]
  10.     #[Route('/')]
  11.     #[Route('/index')]
  12.     #[Route('/index.html')]
  13.     #[Route('/index.php')]
  14.     #[Route('/index.htm')]
  15.     public function number(int $min 1int $max 6): Response
  16.     {
  17.         if ($max $min)
  18.         {
  19.             // swap
  20.             $tmp $max;
  21.             $max $min;
  22.             $min $tmp;
  23.         }
  24.         // min and max are both inclusive
  25.         $number random_int($min$max);
  26.         return new Response(
  27.             '<!DOCTYPE html>
  28.             <html>
  29.             <meta charset="UTF-8">
  30.             <title>Karlsson</title>
  31.             <body>
  32.             <p>Page under construction. Reload to have a new number.</p>
  33.             <p>Dice show: '.$number.'</p>
  34.             </body>
  35.             </html>'
  36.         );
  37.     }
  38. }