20
20
use Flarum \Settings \SettingsRepositoryInterface ;
21
21
use Illuminate \Contracts \Filesystem \Cloud ;
22
22
use Illuminate \Contracts \Filesystem \Factory ;
23
+ use Psr \Log \LoggerInterface ;
23
24
24
25
class QrCodeGenerator
25
26
{
26
27
protected Cloud $ assetsFilesystem ;
27
28
28
- public function __construct (protected SettingsRepositoryInterface $ settings , Factory $ filesystemFactory )
29
+ public function __construct (protected SettingsRepositoryInterface $ settings , Factory $ filesystemFactory, protected LoggerInterface $ logger )
29
30
{
30
31
$ this ->assetsFilesystem = $ filesystemFactory ->disk ('flarum-assets ' );
31
32
}
@@ -44,11 +45,16 @@ public function generate(string $text, bool $asDataUri = false): string
44
45
->validateResult (false )
45
46
->backgroundColor (new Color (255 , 255 , 255 , 1 ));
46
47
47
- if ($ this ->settings ->get ('ianm-twofactor.admin.settings.forum_logo_qr ' ) && $ this ->getLogoUrl ()) {
48
- $ builder
49
- ->logoPath ($ this ->getLogoUrl ())
50
- ->logoResizeToWidth ($ this ->settings ->get ('ianm-twofactor.admin.settings.forum_logo_qr_width ' ) ?? 100 )
51
- ->logoPunchoutBackground (true );
48
+ try {
49
+ if ($ this ->settings ->get ('ianm-twofactor.admin.settings.forum_logo_qr ' ) && $ this ->getLogoUrl ()) {
50
+ $ builder
51
+ ->logoPath ($ this ->getLogoUrl ())
52
+ ->logoResizeToWidth ($ this ->settings ->get ('ianm-twofactor.admin.settings.forum_logo_qr_width ' ) ?? 100 )
53
+ ->logoPunchoutBackground (true );
54
+ }
55
+ }
56
+ catch (\Exception $ e ) {
57
+ $ this ->logger ->error ('[ianm/twofactor] Could not add logo to QR code: ' .$ e ->getMessage ());
52
58
}
53
59
54
60
$ result = $ builder ->build ();
0 commit comments