Skip to content

Commit 7205be1

Browse files
author
Martin Brecht-Precht
committed
Added some exception handling.
1 parent 4eb37e0 commit 7205be1

File tree

3 files changed

+14
-3
lines changed

3 files changed

+14
-3
lines changed

QrRender/QrCodeRendererEps.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,10 @@ public function render(QrCode $qrCode, $filename)
7373
$epsSource[] = 'eofill';
7474
$epsSource[] = '%%EOF';
7575

76-
file_put_contents($filename, implode("\n", $epsSource));
76+
$bytes = @file_put_contents($filename, implode("\n", $epsSource));
77+
if ($bytes === false) {
78+
throw new IoException('QR code output file not writable.');
79+
}
7780
}
7881

7982
/**

QrRender/QrCodeRendererPng.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,13 @@ public function render(QrCode $qrCode, $filename)
6464
$canvas->drawImage($draw);
6565

6666
// Write out the image
67-
$canvas->writeImage($filename);
67+
$writeSuccess = @$canvas->writeImage($filename);
6868
$canvas->clear();
6969
$canvas->destroy();
70+
71+
if($writeSuccess !== true){
72+
throw new IoException('QR code output file not writable.');
73+
}
7074
}
7175

7276
}

QrRender/QrCodeRendererTiff.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,11 +67,15 @@ public function render(QrCode $qrCode, $filename)
6767
}
6868

6969
// Write out the image
70-
$canvas->writeImage($filename);
70+
$writeSuccess = @$canvas->writeImage($filename);
7171
$canvas->clear();
7272
$canvas->destroy();
7373
$block->clear();
7474
$block->destroy();
75+
76+
if ($writeSuccess !== true) {
77+
throw new IoException('QR code output file not writable');
78+
}
7579
}
7680

7781
}

0 commit comments

Comments
 (0)