feat: add stub implementation for image
QRCodeFromEntity fix: base64 StubQRCodeGenerator
This commit is contained in:
parent
9e96c007bd
commit
64a07b232a
BIN
assets/images/wip.png
Normal file
BIN
assets/images/wip.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.0 KiB |
@ -5,3 +5,7 @@ body {
|
|||||||
.header {
|
.header {
|
||||||
background-color: skyblue;
|
background-color: skyblue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.header-another-code {
|
||||||
|
font-size: 2rem;
|
||||||
|
}
|
||||||
|
@ -27,8 +27,13 @@ services:
|
|||||||
arguments:
|
arguments:
|
||||||
$available_currencies: '%app.currencies%'
|
$available_currencies: '%app.currencies%'
|
||||||
|
|
||||||
|
App\Service\StubQRCodeGenerator:
|
||||||
|
arguments:
|
||||||
|
$imagePath: '%kernel.project_dir%/assets/images/wip.png'
|
||||||
|
|
||||||
App\Service\CurrencyListerInterface: '@App\Service\StaticCurrencyLister'
|
App\Service\CurrencyListerInterface: '@App\Service\StaticCurrencyLister'
|
||||||
App\Service\QRCodeQROptionsProviderInterface: '@App\Service\QRCodeQROptionsDefaultProvider'
|
App\Service\QRCodeQROptionsProviderInterface: '@App\Service\QRCodeQROptionsDefaultProvider'
|
||||||
|
App\Service\QRCodeGeneratorInterface: '@App\Service\StubQRCodeGenerator'
|
||||||
|
|
||||||
# add more service definitions when explicit configuration is needed
|
# add more service definitions when explicit configuration is needed
|
||||||
# please note that last definitions always *replace* previous ones
|
# please note that last definitions always *replace* previous ones
|
||||||
|
@ -4,6 +4,7 @@ namespace App\Controller;
|
|||||||
|
|
||||||
use App\Entity\QRCode\QRCode;
|
use App\Entity\QRCode\QRCode;
|
||||||
use App\Form\Type\QRCodeType;
|
use App\Form\Type\QRCodeType;
|
||||||
|
use App\Service\QRCodeGeneratorInterface;
|
||||||
use App\Service\QRCodeQROptionsProviderInterface;
|
use App\Service\QRCodeQROptionsProviderInterface;
|
||||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||||
use Symfony\Component\HttpFoundation\Request;
|
use Symfony\Component\HttpFoundation\Request;
|
||||||
@ -11,14 +12,16 @@ use Symfony\Component\HttpFoundation\Response;
|
|||||||
use Symfony\Component\Routing\Attribute\Route;
|
use Symfony\Component\Routing\Attribute\Route;
|
||||||
|
|
||||||
class IndexController extends AbstractController {
|
class IndexController extends AbstractController {
|
||||||
|
public function __construct(private readonly QRCodeQROptionsProviderInterface $qrCodeQROptionsFactory) {}
|
||||||
#[Route('/', name: 'homepage')]
|
#[Route('/', name: 'homepage')]
|
||||||
public function indexAction(Request $request, QRCodeQROptionsProviderInterface $qrCodeQROptionsFactory): Response
|
public function indexAction(
|
||||||
|
Request $request,
|
||||||
|
QRCodeGeneratorInterface $qrCodeGenerator,
|
||||||
|
): Response
|
||||||
{
|
{
|
||||||
$qrCode = new QRCode(
|
$qrCodeImage = null;
|
||||||
codeQROptions: $qrCodeQROptionsFactory->getDefault()
|
|
||||||
);
|
|
||||||
|
|
||||||
|
$qrCode = $this->createQrCodeEntity();
|
||||||
$form = $this->createForm(QRCodeType::class, $qrCode);
|
$form = $this->createForm(QRCodeType::class, $qrCode);
|
||||||
|
|
||||||
|
|
||||||
@ -26,13 +29,24 @@ class IndexController extends AbstractController {
|
|||||||
$form->submit($request->request->all($form->getName()));
|
$form->submit($request->request->all($form->getName()));
|
||||||
|
|
||||||
if ($form->isSubmitted() && $form->isValid()) {
|
if ($form->isSubmitted() && $form->isValid()) {
|
||||||
// TODO: call service to generate
|
/* Puvodne jsem premyslel nad redirectem a ulozenim obrazku
|
||||||
print_r($qrCode);
|
do session, nicmene u takovehleho typu aplikace me to prijde naopak kontraproduktivni.
|
||||||
|
a zadani o tom mlci. Navic v pripade ze aplikace bude provozovana ve vice instancich
|
||||||
|
by se musela resit memcache, redis... */
|
||||||
|
$qrCodeImage = $qrCodeGenerator->generateQRCodeFromEntity($qrCode);
|
||||||
|
$form = $this->createForm(QRCodeType::class, $this->createQrCodeEntity());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return $this->render('index/homepage.html.twig', [
|
return $this->render('index/homepage.html.twig', [
|
||||||
'form' => $form
|
'form' => $form,
|
||||||
|
'qrCodeImage' => $qrCodeImage
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private function createQrCodeEntity(): QRCode {
|
||||||
|
return new QRCode(
|
||||||
|
codeQROptions: $this->qrCodeQROptionsFactory->getDefault()
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
16
src/Service/QRCodeGeneratorInterface.php
Normal file
16
src/Service/QRCodeGeneratorInterface.php
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
<?php
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace App\Service;
|
||||||
|
|
||||||
|
use App\Entity\QRCode\QRCode;
|
||||||
|
|
||||||
|
interface QRCodeGeneratorInterface
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Generates QR code from entity
|
||||||
|
* @param QRCode $entity
|
||||||
|
* @return string base64 encoded PNG
|
||||||
|
*/
|
||||||
|
public function generateQRCodeFromEntity(QRCode $entity): string;
|
||||||
|
}
|
21
src/Service/StubQRCodeGenerator.php
Normal file
21
src/Service/StubQRCodeGenerator.php
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
<?php
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace App\Service;
|
||||||
|
|
||||||
|
use App\Entity\QRCode\QRCode;
|
||||||
|
|
||||||
|
readonly final class StubQRCodeGenerator implements QRCodeGeneratorInterface
|
||||||
|
{
|
||||||
|
public function __construct(private string $imagePath) {}
|
||||||
|
|
||||||
|
public function generateQRCodeFromEntity(QRCode $entity): string
|
||||||
|
{
|
||||||
|
$content = file_get_contents($this->imagePath);
|
||||||
|
|
||||||
|
return match ($content) {
|
||||||
|
false => throw new \InvalidArgumentException('Image path is invalid'),
|
||||||
|
default => base64_encode($content)
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
@ -2,6 +2,12 @@
|
|||||||
|
|
||||||
{% block body %}
|
{% block body %}
|
||||||
<div class="container">
|
<div class="container">
|
||||||
|
{% if qrCodeImage %}
|
||||||
|
<div class="d-flex p-3 justify-content-center qr-code-image">
|
||||||
|
<img src="data:image/png;base64,{{ qrCodeImage }}" alt="QR code" />
|
||||||
|
</div>
|
||||||
|
<h2 class="header-another-code">{{ "You can generate another QR code here" | trans }}:</h2>
|
||||||
|
{% endif %}
|
||||||
{{ form_start(form) }}
|
{{ form_start(form) }}
|
||||||
<div class="mb-3 col-auto">
|
<div class="mb-3 col-auto">
|
||||||
{{ form_label(form.iban) }}
|
{{ form_label(form.iban) }}
|
||||||
|
@ -8,3 +8,4 @@ Specific symbol: "Specifický symbol"
|
|||||||
Generate qr code: "Vygenerovat QR kód"
|
Generate qr code: "Vygenerovat QR kód"
|
||||||
Iban: "IBAN"
|
Iban: "IBAN"
|
||||||
QR code generator: "Generátor bankovních QR kódů"
|
QR code generator: "Generátor bankovních QR kódů"
|
||||||
|
You can generate another QR code here: "Další QR kód si můžete vygenerovat zde"
|
||||||
|
Loading…
Reference in New Issue
Block a user