src/Controller/QRCodeController.php line 38

Open in your IDE?
  1. <?php
  2. namespace Eadmin\Controller;
  3. use Eadmin\Response\HttpOk;
  4. use Eadmin\Entity\Client;
  5. use Eadmin\Error\FieldException;
  6. use Eadmin\Error\NotFoundException;
  7. use Sensio\Bundle\FrameworkExtraBundle\Configuration\Cache;
  8. use Symfony\Component\HttpFoundation\Response;
  9. use Symfony\Component\HttpFoundation\Request;
  10. use Symfony\Component\Routing\Annotation\Route;
  11. /**
  12.  * @Route(
  13.  *      path          = "",
  14.  *      schemes         = {"http|https"}
  15.  * )
  16.  * @Cache(
  17.  *      maxage          = "0",
  18.  *      smaxage         = "0",
  19.  *      expires         = "now",
  20.  *      public          = false
  21.  * )
  22.  */
  23. class QRCodeController extends AbstractController {
  24.     public function getEntityClass(){
  25.         return Client::class;
  26.     }
  27.     /**
  28.      * @Route(
  29.      *      path          = "/qrcode",
  30.      *      methods       = {"GET"}
  31.      * )
  32.      */
  33.     public function generateQrCode(Request $request): Response
  34.     {
  35.         //$pathEad = realpath(__DIR__ . '/../../') . '/bin/console';
  36.         //$output = shell_exec("php {$pathEad} cache:clear --no-warmup");
  37.         if($request->get('debug') == 1){
  38.             return new HttpOk([ "message" => $output ]);
  39.         }
  40.         //$token = $request->get('token');
  41.         $data $request->get('data');
  42.         $width = (int)$request->get('w');
  43.         $height = (int)$request->get('h');
  44.         $hw = (int)$request->get('hw');
  45.         if(!empty($hw)){
  46.             $width $hw;
  47.             $height $hw;
  48.         }
  49.         /*if(empty($token)){
  50.             throw new FieldException("Empty Field", [ "token" ]);
  51.         }*/
  52.         if(empty($data)){
  53.             throw new FieldException("Empty Field", [ "data" ]);
  54.         }
  55.         if(
  56.             !stristr($data'br.gov.bcb.pix') && 
  57.             !stristr($data'/certificado/') &&
  58.             !stristr($data'/certificate/')
  59.         ){
  60.             throw new FieldException("Invalid Field", [ "data" ]);
  61.         }
  62.         /*$client = $this->repository->findOneBy([
  63.             "token" => $token
  64.         ]);
  65.         if(!$client){
  66.             throw new NotFoundException("Client not found");
  67.         }*/
  68.         $qrCodeService $this->generalService->getService('QRcodeService');
  69.         $qrCodeService->setData($data);
  70.         if(!empty($width)){
  71.             $qrCodeService->setWidth($width);
  72.         }
  73.         if(!empty($height)){
  74.             $qrCodeService->setHeight($height);
  75.         }
  76.         return $qrCodeService->view();
  77.     }
  78.     /**
  79.      * @Route(
  80.      *      path          = "/qrcode/teste",
  81.      *      methods       = {"GET"}
  82.      * )
  83.      */
  84.     public function generateQrCodeTeste(Request $request): Response
  85.     {
  86.         //$pathEad = realpath(__DIR__ . '/../../') . '/bin/console';
  87.         //$output = shell_exec("php {$pathEad} cache:clear --no-warmup");
  88.         if($request->get('debug') == 1){
  89.             return new HttpOk([ "message" => $output ]);
  90.         }
  91.         //$token = $request->get('token');
  92.         $data $request->get('data');
  93.         $width = (int)$request->get('w');
  94.         $height = (int)$request->get('h');
  95.         $hw = (int)$request->get('hw');
  96.         if(!empty($hw)){
  97.             $width $hw;
  98.             $height $hw;
  99.         }
  100.         /*if(empty($token)){
  101.             throw new FieldException("Empty Field", [ "token" ]);
  102.         }*/
  103.         if(empty($data)){
  104.             throw new FieldException("Empty Field", [ "data" ]);
  105.         }
  106.         if(
  107.             !stristr($data'br.gov.bcb.pix') && 
  108.             !stristr($data'/certificado/') &&
  109.             !stristr($data'/certificate/')
  110.         ){
  111.             throw new FieldException("Invalid Field", [ "data" ]);
  112.         }
  113.         $this->data["qrcodeInfo"] = [
  114.             "width" => $width,
  115.             "height" => $height,
  116.             "data" => $data
  117.         ];
  118.         return $this->renderEAD('qrcode.html.twig');
  119.     }
  120. }