The module is now compatible with all:

- bacon/bacon-qr-code: ^1.0 || ^2.0
- oxid-esales/oxideshop-metapackage-ce: "~6.0.3 || ~6.1.0 || ~6.2.0 || ~6.3.0  || ~6.4.0  || ~6.5.0"
This commit is contained in:
Tobias Matthaiou 2022-09-12 15:16:14 +02:00
parent 219427fb75
commit 96f6de6300
4 changed files with 108 additions and 63 deletions

View File

@ -38,7 +38,8 @@
},
"require": {
"php": ">=5.6",
"oxid-esales/oxideshop-metapackage-ce": "~6.0.3 || ~6.1.0 || ~6.2.0",
"ext-xmlwriter": "*",
"oxid-esales/oxideshop-metapackage-ce": "~6.0.3 || ~6.1.0 || ~6.2.0 || ~6.3.0 || ~6.4.0 || ~6.5.0",
"spomky-labs/otphp": "^8.3",
"bacon/bacon-qr-code": "^1.0 || ^2.0",
"zendframework/zend-math": "^3.2"

View File

@ -0,0 +1,47 @@
<?php
declare(strict_types=1);
namespace D3\Totp\Application\Factory;
use BaconQrCode\Renderer\RendererInterface;
use BaconQrCode\Renderer\Image\Svg; // v1.0.3
use BaconQrCode\Renderer\ImageRenderer; // v2.0.0
use BaconQrCode\Renderer\Image\SvgImageBackEnd; // v2.0.0
use BaconQrCode\Renderer\RendererStyle\RendererStyle; // v2.0.0
class BaconQrCodeFactory
{
/**
* @return RendererInterface
*/
public static function renderer($size)
{
if (class_exists(Svg::class)) {
return self::v100($size);
}
return self::v200($size);
}
private static function v200($size)
{
$renderer = oxNew(
ImageRenderer::class,
oxNew(RendererStyle::class, $size),
oxNew(SvgImageBackEnd::class),
);
return $renderer;
}
private static function v100($size)
{
$renderer = oxNew(Svg::class);
$renderer->setHeight($size);
$renderer->setWidth($size);
return $renderer;
}
}

View File

@ -15,9 +15,9 @@
namespace D3\Totp\Application\Model;
use BaconQrCode\Renderer\Image\Svg;
use BaconQrCode\Renderer\RendererInterface;
use BaconQrCode\Writer;
use D3\Totp\Application\Factory\BaconQrCodeFactory;
use D3\Totp\Application\Model\Exceptions\d3totp_wrongOtpException;
use Doctrine\DBAL\DBALException;
use OTPHP\TOTP;
@ -177,10 +177,7 @@ class d3totp extends BaseModel
*/
public function getQrCodeElement()
{
$renderer = oxNew(Svg::class);
$renderer->setHeight(200);
$renderer->setWidth(200);
$renderer = BaconQrCodeFactory::renderer(200);
$writer = $this->d3GetWriter($renderer);
return $writer->writeString($this->getTotp()->getProvisioningUri());
}

View File

@ -17,8 +17,8 @@
namespace D3\Totp\tests\unit\Application\Model;
use BaconQrCode\Renderer\Image\Svg;
use BaconQrCode\Writer;
use D3\Totp\Application\Factory\BaconQrCodeFactory;
use D3\Totp\Application\Model\d3backupcodelist;
use D3\Totp\Application\Model\d3totp;
use D3\Totp\Application\Model\Exceptions\d3totp_wrongOtpException;
@ -562,7 +562,7 @@ class d3totpTest extends d3TotpUnitTestCase
*/
public function getQrCodeElement()
{
$renderer = oxNew(Svg::class);
$renderer = BaconQrCodeFactory::renderer(200);
/** @var d3totp|PHPUnit_Framework_MockObject_MockObject $oTotpMock */
$oTotpMock = $this->getMock(d3totp::class, array(
@ -595,7 +595,7 @@ class d3totpTest extends d3TotpUnitTestCase
*/
public function d3GetWriterReturnsRightInstance()
{
$renderer = oxNew(Svg::class);
$renderer = BaconQrCodeFactory::renderer(200);;
$this->assertInstanceOf(
Writer::class,