Переглянути джерело

:octocat: check for loaded extensions

codemasher 5 роки тому
батько
коміт
dcf125a8b9
2 змінених файлів з 33 додано та 1 видалено
  1. 17 1
      src/Output/QRImage.php
  2. 16 0
      src/Output/QRImagick.php

+ 17 - 1
src/Output/QRImage.php

@@ -12,7 +12,9 @@
 
 
 namespace chillerlan\QRCode\Output;
 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 Exception;
 
 
 use function array_values, base64_encode, call_user_func, count, imagecolorallocate, imagecolortransparent,
 use function array_values, base64_encode, call_user_func, count, imagecolorallocate, imagecolortransparent,
@@ -42,6 +44,20 @@ class QRImage extends QROutputAbstract{
 	 */
 	 */
 	protected $image;
 	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
 	 * @inheritDoc
 	 */
 	 */

+ 16 - 0
src/Output/QRImagick.php

@@ -12,6 +12,9 @@
 
 
 namespace chillerlan\QRCode\Output;
 namespace chillerlan\QRCode\Output;
 
 
+use chillerlan\QRCode\Data\QRMatrix;
+use chillerlan\QRCode\QRCodeException;
+use chillerlan\Settings\SettingsContainerInterface;
 use Imagick, ImagickDraw, ImagickPixel;
 use Imagick, ImagickDraw, ImagickPixel;
 
 
 use function is_string;
 use function is_string;
@@ -29,6 +32,19 @@ class QRImagick extends QROutputAbstract{
 	 */
 	 */
 	protected $imagick;
 	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
 	 * @inheritDoc
 	 */
 	 */