<?php
namespace Eadmin\Controller;
use Eadmin\Response\HttpOk;
use Eadmin\Entity\Client;
use Eadmin\Error\FieldException;
use Eadmin\Error\NotFoundException;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Cache;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Routing\Annotation\Route;
/**
* @Route(
* path = "",
* schemes = {"http|https"}
* )
* @Cache(
* maxage = "0",
* smaxage = "0",
* expires = "now",
* public = false
* )
*/
class QRCodeController extends AbstractController {
public function getEntityClass(){
return Client::class;
}
/**
* @Route(
* path = "/qrcode",
* methods = {"GET"}
* )
*/
public function generateQrCode(Request $request): Response
{
//$pathEad = realpath(__DIR__ . '/../../') . '/bin/console';
//$output = shell_exec("php {$pathEad} cache:clear --no-warmup");
if($request->get('debug') == 1){
return new HttpOk([ "message" => $output ]);
}
//$token = $request->get('token');
$data = $request->get('data');
$width = (int)$request->get('w');
$height = (int)$request->get('h');
$hw = (int)$request->get('hw');
if(!empty($hw)){
$width = $hw;
$height = $hw;
}
/*if(empty($token)){
throw new FieldException("Empty Field", [ "token" ]);
}*/
if(empty($data)){
throw new FieldException("Empty Field", [ "data" ]);
}
if(
!stristr($data, 'br.gov.bcb.pix') &&
!stristr($data, '/certificado/') &&
!stristr($data, '/certificate/')
){
throw new FieldException("Invalid Field", [ "data" ]);
}
/*$client = $this->repository->findOneBy([
"token" => $token
]);
if(!$client){
throw new NotFoundException("Client not found");
}*/
$qrCodeService = $this->generalService->getService('QRcodeService');
$qrCodeService->setData($data);
if(!empty($width)){
$qrCodeService->setWidth($width);
}
if(!empty($height)){
$qrCodeService->setHeight($height);
}
return $qrCodeService->view();
}
/**
* @Route(
* path = "/qrcode/teste",
* methods = {"GET"}
* )
*/
public function generateQrCodeTeste(Request $request): Response
{
//$pathEad = realpath(__DIR__ . '/../../') . '/bin/console';
//$output = shell_exec("php {$pathEad} cache:clear --no-warmup");
if($request->get('debug') == 1){
return new HttpOk([ "message" => $output ]);
}
//$token = $request->get('token');
$data = $request->get('data');
$width = (int)$request->get('w');
$height = (int)$request->get('h');
$hw = (int)$request->get('hw');
if(!empty($hw)){
$width = $hw;
$height = $hw;
}
/*if(empty($token)){
throw new FieldException("Empty Field", [ "token" ]);
}*/
if(empty($data)){
throw new FieldException("Empty Field", [ "data" ]);
}
if(
!stristr($data, 'br.gov.bcb.pix') &&
!stristr($data, '/certificado/') &&
!stristr($data, '/certificate/')
){
throw new FieldException("Invalid Field", [ "data" ]);
}
$this->data["qrcodeInfo"] = [
"width" => $width,
"height" => $height,
"data" => $data
];
return $this->renderEAD('qrcode.html.twig');
}
}