Skip to content

Commit

Permalink
:octocat: check for loaded extensions
Browse files Browse the repository at this point in the history
  • Loading branch information
codemasher committed Nov 18, 2020
1 parent 6ecb09f commit dcf125a
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 1 deletion.
18 changes: 17 additions & 1 deletion src/Output/QRImage.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@

namespace chillerlan\QRCode\Output;

use chillerlan\QRCode\QRCode;
use chillerlan\QRCode\Data\QRMatrix;
use chillerlan\QRCode\{QRCode, QRCodeException};
use chillerlan\Settings\SettingsContainerInterface;
use Exception;

use function array_values, base64_encode, call_user_func, count, imagecolorallocate, imagecolortransparent,
Expand Down Expand Up @@ -42,6 +44,20 @@ class QRImage extends QROutputAbstract{
*/
protected $image;

/**
* @inheritDoc
*
* @throws \chillerlan\QRCode\QRCodeException
*/
public function __construct(SettingsContainerInterface $options, QRMatrix $matrix){

if(!extension_loaded('gd')){
throw new QRCodeException('ext-gd not loaded'); // @codeCoverageIgnore
}

parent::__construct($options, $matrix);
}

/**
* @inheritDoc
*/
Expand Down
16 changes: 16 additions & 0 deletions src/Output/QRImagick.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@

namespace chillerlan\QRCode\Output;

use chillerlan\QRCode\Data\QRMatrix;
use chillerlan\QRCode\QRCodeException;
use chillerlan\Settings\SettingsContainerInterface;
use Imagick, ImagickDraw, ImagickPixel;

use function is_string;
Expand All @@ -29,6 +32,19 @@ class QRImagick extends QROutputAbstract{
*/
protected $imagick;

/**
* @inheritDoc
* @throws \chillerlan\QRCode\QRCodeException
*/
public function __construct(SettingsContainerInterface $options, QRMatrix $matrix){

if(!extension_loaded('imagick')){
throw new QRCodeException('ext-imagick not loaded'); // @codeCoverageIgnore
}

parent::__construct($options, $matrix);
}

/**
* @inheritDoc
*/
Expand Down

0 comments on commit dcf125a

Please sign in to comment.