src/Controller/MobileController.php line 15

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  4. use Symfony\Component\HttpFoundation\Request;
  5. use Symfony\Component\HttpFoundation\Response;
  6. use Symfony\Component\HttpFoundation\JsonResponse;
  7. use Symfony\Component\Routing\Annotation\Route;
  8. use Symfony\Component\Uid\Uuid;
  9. class MobileController extends AbstractController
  10. {
  11.     #[Route('/mobile'name'app_mobile'methods: ['GET'])]
  12.     public function index(Request $request): Response
  13.     {
  14.         return $this->render('mobile/mobile.html.twig', [
  15.             'site_name' => 'First ID Demo'
  16.         ]);
  17.     }
  18.     #[Route('/mobile/generate-maid'name'app_generate_maid'methods: ['GET'])]
  19.     public function generateMaid(): JsonResponse
  20.     {
  21.         $maid Uuid::v4()->toRfc4122();
  22.         return new JsonResponse(['maid' => $maid]);
  23.     }
  24.     #[Route('/mobile/generate-email'name'app_generate_email'methods: ['GET'])]
  25.     public function generateEmail(): JsonResponse
  26.     {
  27.         $randomEmail 'user' rand(10009999) . '@example.com';
  28.         return new JsonResponse(['email' => $randomEmail]);
  29.     }
  30.     #[Route('/mobile/generate-config'name'app_generate_config'methods: ['GET'])]
  31.     public function generateConfig(): JsonResponse
  32.     {
  33.         $config = [
  34.             'deviceType' => ['web''mobile''tablet'][array_rand(['web''mobile''tablet'])],
  35.             'deviceManufacturer' => ['Apple''Samsung''Google''Dell''HP'][array_rand(['Apple''Samsung''Google''Dell''HP'])],
  36.             'osVersion' => rand(1015) . '.' rand(09) . '.' rand(09),
  37.             'buildId' => 'Build_' bin2hex(random_bytes(4)),
  38.             'deviceModel' => ['iPhone 12''Galaxy S21''Pixel 5''XPS 13''Spectre x360'][array_rand(['iPhone 12''Galaxy S21''Pixel 5''XPS 13''Spectre x360'])],
  39.             'deviceResolution' => rand(7203840) . 'x' rand(4802160),
  40.             'deviceRam' => rand(232) * 1024
  41.         ];
  42.         return new JsonResponse(['config' => $config]);
  43.     }
  44. }