feat: add stub implementation for image
QRCodeFromEntity fix: base64 StubQRCodeGenerator
This commit is contained in:
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)
|
||||
};
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user