From ae1c1f56ca9eace88f66feb090cad39224bfb63a Mon Sep 17 00:00:00 2001 From: smiley Date: Fri, 15 Jul 2022 19:20:58 +0200 Subject: [PATCH] :shower: extract OUTPUT_* constants from QRCode to QROutputInterface and mark QRCode::OUTPUT_* as deprecated --- examples/custom_output.php | 4 +- examples/eps.php | 3 +- examples/fpdf.php | 5 +- examples/html.php | 5 +- examples/image.php | 5 +- examples/imageWithText.php | 6 +- examples/imagick.php | 5 +- examples/svg.php | 5 +- examples/svgMeltedModules.php | 4 +- examples/svgRandomColoredDots.php | 4 +- examples/svgRoundQuietzone.php | 4 +- examples/svgWithLogo.php | 4 +- examples/text.php | 5 +- src/Output/QRGdImage.php | 9 +-- src/Output/QROutputInterface.php | 44 +++++++++++ src/Output/QRString.php | 6 +- src/QRCode.php | 123 +++++++++++++++++++---------- src/QROptionsTrait.php | 14 ++-- tests/Data/QRMatrixTest.php | 4 +- tests/Output/QRFpdfTest.php | 5 +- tests/Output/QRGdImageGIFTest.php | 4 +- tests/Output/QRGdImageJPGTest.php | 4 +- tests/Output/QRGdImagePNGTest.php | 4 +- tests/Output/QRImagickTest.php | 5 +- tests/Output/QRMarkupHTMLTest.php | 5 +- tests/Output/QRMarkupSVGTest.php | 5 +- tests/Output/QRStringJSONTest.php | 4 +- tests/Output/QRStringTEXTTest.php | 4 +- tests/QRCodeReaderTestAbstract.php | 11 +-- 29 files changed, 200 insertions(+), 110 deletions(-) diff --git a/examples/custom_output.php b/examples/custom_output.php index 05b032d47..dd9441679 100644 --- a/examples/custom_output.php +++ b/examples/custom_output.php @@ -10,7 +10,7 @@ use chillerlan\QRCode\{QRCode, QROptions}; use chillerlan\QRCode\Common\EccLevel; -use chillerlan\QRCode\Output\QROutputAbstract; +use chillerlan\QRCode\Output\{QROutputAbstract, QROutputInterface}; require_once __DIR__.'/../vendor/autoload.php'; @@ -88,7 +88,7 @@ var_dump($qrOutputInterface->dump()); $options = new QROptions([ 'version' => 5, 'eccLevel' => EccLevel::L, - 'outputType' => QRCode::OUTPUT_CUSTOM, + 'outputType' => QROutputInterface::CUSTOM, 'outputInterface' => MyCustomOutput::class, ]); diff --git a/examples/eps.php b/examples/eps.php index 84e06db06..10b7dfe3b 100644 --- a/examples/eps.php +++ b/examples/eps.php @@ -9,12 +9,13 @@ use chillerlan\QRCode\{QRCode, QROptions}; use chillerlan\QRCode\Common\EccLevel; use chillerlan\QRCode\Data\QRMatrix; +use chillerlan\QRCode\Output\QROutputInterface; require_once __DIR__.'/../vendor/autoload.php'; $options = new QROptions([ 'version' => 7, - 'outputType' => QRCode::OUTPUT_EPS, + 'outputType' => QROutputInterface::EPS, 'eccLevel' => EccLevel::L, 'scale' => 5, 'addQuietzone' => true, diff --git a/examples/fpdf.php b/examples/fpdf.php index de9606777..1c9b523f6 100644 --- a/examples/fpdf.php +++ b/examples/fpdf.php @@ -6,14 +6,15 @@ */ use chillerlan\QRCode\{QRCode, QROptions}; -use chillerlan\QRCode\Data\QRMatrix; use chillerlan\QRCode\Common\EccLevel; +use chillerlan\QRCode\Data\QRMatrix; +use chillerlan\QRCode\Output\QROutputInterface; require_once __DIR__ . '/../vendor/autoload.php'; $options = new QROptions([ 'version' => 7, - 'outputType' => QRCode::OUTPUT_FPDF, + 'outputType' => QROutputInterface::FPDF, 'eccLevel' => EccLevel::L, 'scale' => 5, 'imageBase64' => false, diff --git a/examples/html.php b/examples/html.php index a8f8924e3..4ef9e71f3 100644 --- a/examples/html.php +++ b/examples/html.php @@ -7,8 +7,9 @@ */ use chillerlan\QRCode\{QRCode, QROptions}; -use chillerlan\QRCode\Data\QRMatrix; use chillerlan\QRCode\Common\EccLevel; +use chillerlan\QRCode\Data\QRMatrix; +use chillerlan\QRCode\Output\QROutputInterface; require_once '../vendor/autoload.php'; @@ -16,7 +17,7 @@ header('Content-Type: text/html; charset=utf-8'); $options = new QROptions([ 'version' => 5, - 'outputType' => QRCode::OUTPUT_MARKUP_HTML, + 'outputType' => QROutputInterface::MARKUP_HTML, 'eccLevel' => EccLevel::L, 'cssClass' => 'qrcode', 'moduleValues' => [ diff --git a/examples/image.php b/examples/image.php index 66a90a17b..afa362ab3 100644 --- a/examples/image.php +++ b/examples/image.php @@ -7,14 +7,15 @@ */ use chillerlan\QRCode\{QRCode, QROptions}; -use chillerlan\QRCode\Data\QRMatrix; use chillerlan\QRCode\Common\EccLevel; +use chillerlan\QRCode\Data\QRMatrix; +use chillerlan\QRCode\Output\QROutputInterface; require_once __DIR__.'/../vendor/autoload.php'; $options = new QROptions([ 'version' => 7, - 'outputType' => QRCode::OUTPUT_IMAGE_PNG, + 'outputType' => QROutputInterface::GDIMAGE_PNG, 'eccLevel' => EccLevel::L, 'scale' => 10, 'imageBase64' => false, diff --git a/examples/imageWithText.php b/examples/imageWithText.php index 5d8c89ad2..b7e85c397 100644 --- a/examples/imageWithText.php +++ b/examples/imageWithText.php @@ -12,7 +12,7 @@ */ use chillerlan\QRCode\{QRCode, QROptions}; -use chillerlan\QRCode\Output\QRGdImage; +use chillerlan\QRCode\Output\{QROutputInterface, QRGdImage}; require_once __DIR__.'/../vendor/autoload.php'; @@ -70,7 +70,7 @@ class QRImageWithText extends QRGdImage{ $background = imagecolorallocate($this->image, ...$textBG); // allow transparency - if($this->options->imageTransparent && $this->options->outputType !== QRCode::OUTPUT_IMAGE_JPG){ + if($this->options->imageTransparent && $this->options->outputType !== QROutputInterface::GDIMAGE_JPG){ imagecolortransparent($this->image, $background); } @@ -100,7 +100,7 @@ class QRImageWithText extends QRGdImage{ $options = new QROptions([ 'version' => 7, - 'outputType' => QRCode::OUTPUT_IMAGE_PNG, + 'outputType' => QROutputInterface::GDIMAGE_PNG, 'scale' => 3, 'imageBase64' => false, ]); diff --git a/examples/imagick.php b/examples/imagick.php index 5376d08bb..8ef8d6462 100644 --- a/examples/imagick.php +++ b/examples/imagick.php @@ -7,14 +7,15 @@ */ use chillerlan\QRCode\{QRCode, QROptions}; -use chillerlan\QRCode\Data\QRMatrix; use chillerlan\QRCode\Common\EccLevel; +use chillerlan\QRCode\Data\QRMatrix; +use chillerlan\QRCode\Output\QROutputInterface; require_once __DIR__.'/../vendor/autoload.php'; $options = new QROptions([ 'version' => 7, - 'outputType' => QRCode::OUTPUT_IMAGICK, + 'outputType' => QROutputInterface::IMAGICK, 'eccLevel' => EccLevel::L, 'imagickBG' => '#FFFFFF', 'scale' => 20, diff --git a/examples/svg.php b/examples/svg.php index 94748d190..05eda19c6 100644 --- a/examples/svg.php +++ b/examples/svg.php @@ -10,14 +10,15 @@ */ use chillerlan\QRCode\{QRCode, QROptions}; -use chillerlan\QRCode\Data\QRMatrix; use chillerlan\QRCode\Common\EccLevel; +use chillerlan\QRCode\Data\QRMatrix; +use chillerlan\QRCode\Output\QROutputInterface; require_once __DIR__.'/../vendor/autoload.php'; $options = new QROptions([ 'version' => 7, - 'outputType' => QRCode::OUTPUT_MARKUP_SVG, + 'outputType' => QROutputInterface::MARKUP_SVG, 'imageBase64' => false, 'eccLevel' => EccLevel::L, 'addQuietzone' => true, diff --git a/examples/svgMeltedModules.php b/examples/svgMeltedModules.php index 7cb173bf1..ec480d69d 100644 --- a/examples/svgMeltedModules.php +++ b/examples/svgMeltedModules.php @@ -9,7 +9,7 @@ use chillerlan\QRCode\Common\EccLevel; use chillerlan\QRCode\Data\QRMatrix; -use chillerlan\QRCode\Output\QRMarkupSVG; +use chillerlan\QRCode\Output\{QROutputInterface, QRMarkupSVG}; use chillerlan\QRCode\{QRCode, QROptions}; require_once __DIR__.'/../vendor/autoload.php'; @@ -249,7 +249,7 @@ $options = new MeltedOutputOptions([ 'connectPaths' => true, 'imageBase64' => false, - 'outputType' => QRCode::OUTPUT_CUSTOM, + 'outputType' => QROutputInterface::CUSTOM, 'outputInterface' => MeltedSVGQRCodeOutput::class, 'excludeFromConnect' => [ QRMatrix::M_FINDER|QRMatrix::IS_DARK, diff --git a/examples/svgRandomColoredDots.php b/examples/svgRandomColoredDots.php index 867dcc88c..b18ca6b20 100644 --- a/examples/svgRandomColoredDots.php +++ b/examples/svgRandomColoredDots.php @@ -12,7 +12,7 @@ use chillerlan\QRCode\Common\EccLevel; use chillerlan\QRCode\Data\QRMatrix; -use chillerlan\QRCode\Output\QRMarkupSVG; +use chillerlan\QRCode\Output\{QROutputInterface, QRMarkupSVG}; use chillerlan\QRCode\{QRCode, QROptions}; require_once __DIR__.'/../vendor/autoload.php'; @@ -120,7 +120,7 @@ $options = new RandomDotsOptions([ 'eccLevel' => EccLevel::H, 'addQuietzone' => true, 'imageBase64' => false, - 'outputType' => QRCode::OUTPUT_CUSTOM, + 'outputType' => QROutputInterface::CUSTOM, 'outputInterface' => RandomDotsSVGOutput::class, 'markupDark' => '', 'markupLight' => '', diff --git a/examples/svgRoundQuietzone.php b/examples/svgRoundQuietzone.php index 4e3ed3257..16c68ec38 100644 --- a/examples/svgRoundQuietzone.php +++ b/examples/svgRoundQuietzone.php @@ -12,7 +12,7 @@ use chillerlan\QRCode\Common\EccLevel; use chillerlan\QRCode\Data\QRMatrix; -use chillerlan\QRCode\Output\QRMarkupSVG; +use chillerlan\QRCode\Output\{QROutputInterface, QRMarkupSVG}; use chillerlan\QRCode\{QRCode, QROptions}; require_once __DIR__.'/../vendor/autoload.php'; @@ -170,7 +170,7 @@ $options = new RoundQuietzoneOptions([ 'eccLevel' => EccLevel::H, // maximum error correction capacity, esp. for print 'addQuietzone' => false, // we're not adding a quiet zone, this is done internally in our own module 'imageBase64' => false, // avoid base64 URI output - 'outputType' => QRCode::OUTPUT_CUSTOM, + 'outputType' => QROutputInterface::CUSTOM, 'outputInterface' => RoundQuietzoneSVGoutput::class, // load our own output class 'markupDark' => '', // avoid "fill" attributes on paths 'markupLight' => '', diff --git a/examples/svgWithLogo.php b/examples/svgWithLogo.php index 1900f27e3..1a1b7f513 100644 --- a/examples/svgWithLogo.php +++ b/examples/svgWithLogo.php @@ -11,7 +11,7 @@ use chillerlan\QRCode\{QRCode, QRCodeException, QROptions}; use chillerlan\QRCode\Common\EccLevel; use chillerlan\QRCode\Data\QRMatrix; -use chillerlan\QRCode\Output\QRMarkupSVG; +use chillerlan\QRCode\Output\{QROutputInterface, QRMarkupSVG}; require_once __DIR__.'/../vendor/autoload.php'; @@ -102,7 +102,7 @@ $options = new SVGWithLogoOptions([ 'svgLogoCssClass' => 'dark', // QROptions 'version' => 5, - 'outputType' => QRCode::OUTPUT_CUSTOM, + 'outputType' => QROutputInterface::CUSTOM, 'outputInterface' => QRSvgWithLogo::class, 'imageBase64' => false, // ECC level H is necessary when using logos diff --git a/examples/text.php b/examples/text.php index 1aef82ab1..8ca0c76cd 100644 --- a/examples/text.php +++ b/examples/text.php @@ -9,15 +9,16 @@ */ use chillerlan\QRCode\{QRCode, QROptions}; -use chillerlan\QRCode\Data\QRMatrix; use chillerlan\QRCode\Common\EccLevel; +use chillerlan\QRCode\Data\QRMatrix; +use chillerlan\QRCode\Output\QROutputInterface; use PHPUnit\Util\Color; require_once __DIR__.'/../vendor/autoload.php'; $options = new QROptions([ 'version' => 7, - 'outputType' => QRCode::OUTPUT_STRING_TEXT, + 'outputType' => QROutputInterface::STRING_TEXT, 'eccLevel' => EccLevel::L, 'eol' => Color::colorize('reset', "\x00\n"), 'moduleValues' => [ diff --git a/src/Output/QRGdImage.php b/src/Output/QRGdImage.php index 7893dd901..71f5def02 100644 --- a/src/Output/QRGdImage.php +++ b/src/Output/QRGdImage.php @@ -13,7 +13,6 @@ namespace chillerlan\QRCode\Output; use chillerlan\QRCode\Data\QRMatrix; -use chillerlan\QRCode\QRCode; use chillerlan\Settings\SettingsContainerInterface; use ErrorException, Throwable; use function array_values, count, extension_loaded, imagecolorallocate, imagecolortransparent, imagecreatetruecolor, @@ -102,7 +101,7 @@ class QRGdImage extends QROutputAbstract{ /** @phan-suppress-next-line PhanParamTooFewInternalUnpack */ $background = imagecolorallocate($this->image, ...$tbg); - if($this->options->imageTransparent && $this->options->outputType !== QRCode::OUTPUT_IMAGE_JPG){ + if($this->options->imageTransparent && $this->options->outputType !== QROutputInterface::GDIMAGE_JPG){ imagecolortransparent($this->image, $background); } @@ -177,14 +176,14 @@ class QRGdImage extends QROutputAbstract{ try{ switch($this->options->outputType){ - case QRCode::OUTPUT_IMAGE_GIF: + case QROutputInterface::GDIMAGE_GIF: imagegif($this->image); break; - case QRCode::OUTPUT_IMAGE_JPG: + case QROutputInterface::GDIMAGE_JPG: imagejpeg($this->image, null, max(0, min(100, $this->options->jpegQuality))); break; // silently default to png output - case QRCode::OUTPUT_IMAGE_PNG: + case QROutputInterface::GDIMAGE_PNG: default: imagepng($this->image, null, max(-1, min(9, $this->options->pngCompression))); } diff --git a/src/Output/QROutputInterface.php b/src/Output/QROutputInterface.php index 32b1bf6e8..dae431b7f 100644 --- a/src/Output/QROutputInterface.php +++ b/src/Output/QROutputInterface.php @@ -17,6 +17,50 @@ use chillerlan\QRCode\Data\QRMatrix; */ interface QROutputInterface{ + /** @var string */ + const MARKUP_HTML = 'html'; + /** @var string */ + const MARKUP_SVG = 'svg'; + /** @var string */ + const GDIMAGE_PNG = 'png'; + /** @var string */ + const GDIMAGE_JPG = 'jpg'; + /** @var string */ + const GDIMAGE_GIF = 'gif'; + /** @var string */ + const STRING_JSON = 'json'; + /** @var string */ + const STRING_TEXT = 'text'; + /** @var string */ + const IMAGICK = 'imagick'; + /** @var string */ + const FPDF = 'fpdf'; + /** @var string */ + const EPS = 'eps'; + /** @var string */ + const CUSTOM = 'custom'; + + /** + * Map of built-in output modes => modules + * + * @var string[] + */ + const MODES = [ + self::MARKUP_SVG => QRMarkupSVG::class, + self::MARKUP_HTML => QRMarkupHTML::class, + self::GDIMAGE_PNG => QRGdImage::class, + self::GDIMAGE_GIF => QRGdImage::class, + self::GDIMAGE_JPG => QRGdImage::class, + self::STRING_JSON => QRString::class, + self::STRING_TEXT => QRString::class, + self::IMAGICK => QRImagick::class, + self::FPDF => QRFpdf::class, + self::EPS => QREps::class, + ]; + + /** + * @var bool[] + */ const DEFAULT_MODULE_VALUES = [ // light QRMatrix::M_NULL => false, diff --git a/src/Output/QRString.php b/src/Output/QRString.php index 0732bcc7d..efb335d26 100644 --- a/src/Output/QRString.php +++ b/src/Output/QRString.php @@ -13,8 +13,6 @@ namespace chillerlan\QRCode\Output; -use chillerlan\QRCode\QRCode; - use function implode, is_string, json_encode; /** @@ -50,10 +48,10 @@ class QRString extends QROutputAbstract{ $file ??= $this->options->cachefile; switch($this->options->outputType){ - case QRCode::OUTPUT_STRING_TEXT: + case QROutputInterface::STRING_TEXT: $data = $this->text(); break; - case QRCode::OUTPUT_STRING_JSON: + case QROutputInterface::STRING_JSON: default: $data = $this->json(); } diff --git a/src/QRCode.php b/src/QRCode.php index fa0b5d318..d74242aa1 100755 --- a/src/QRCode.php +++ b/src/QRCode.php @@ -13,9 +13,7 @@ namespace chillerlan\QRCode; use chillerlan\QRCode\Common\{EccLevel, ECICharset, MaskPattern, Mode, Version}; use chillerlan\QRCode\Data\{AlphaNum, Byte, ECI, Kanji, Number, QRCodeDataException, QRData, QRDataModeInterface, QRMatrix}; use chillerlan\QRCode\Decoder\{Decoder, DecoderResult, LuminanceSourceInterface}; -use chillerlan\QRCode\Output\{ - QRCodeOutputException, QRFpdf, QRGdImage, QRImagick, QRMarkupHTML, QRMarkupSVG, QREps, QROutputInterface, QRString -}; +use chillerlan\QRCode\Output\{QRCodeOutputException, QROutputInterface}; use chillerlan\Settings\SettingsContainerInterface; use function class_exists, class_implements, in_array, mb_convert_encoding, mb_detect_encoding; @@ -72,46 +70,89 @@ class QRCode{ */ public const ECC_H = EccLevel::H; - /** @var string */ - public const OUTPUT_MARKUP_HTML = 'html'; - /** @var string */ - public const OUTPUT_MARKUP_SVG = 'svg'; - /** @var string */ - public const OUTPUT_IMAGE_PNG = 'png'; - /** @var string */ - public const OUTPUT_IMAGE_JPG = 'jpg'; - /** @var string */ - public const OUTPUT_IMAGE_GIF = 'gif'; - /** @var string */ - public const OUTPUT_STRING_JSON = 'json'; - /** @var string */ - public const OUTPUT_STRING_TEXT = 'text'; - /** @var string */ - public const OUTPUT_IMAGICK = 'imagick'; - /** @var string */ - public const OUTPUT_FPDF = 'fpdf'; - /** @var string */ - public const OUTPUT_EPS = 'eps'; - /** @var string */ - public const OUTPUT_CUSTOM = 'custom'; + /** + * @deprecated 5.0.0 use QROutputInterface::MARKUP_HTML instead + * @see \chillerlan\QRCode\Output\QROutputInterface::MARKUP_HTML + * @var string + */ + public const OUTPUT_MARKUP_HTML = QROutputInterface::MARKUP_HTML; /** - * Map of built-in output modes => modules - * + * @deprecated 5.0.0 use QROutputInterface::MARKUP_SVG instead + * @see \chillerlan\QRCode\Output\QROutputInterface::MARKUP_SVG + * @var string + */ + public const OUTPUT_MARKUP_SVG = QROutputInterface::MARKUP_SVG; + + /** + * @deprecated 5.0.0 use QROutputInterface::GDIMAGE_PNG instead + * @see \chillerlan\QRCode\Output\QROutputInterface::GDIMAGE_PNG + * @var string + */ + public const OUTPUT_IMAGE_PNG = QROutputInterface::GDIMAGE_PNG; + + /** + * @deprecated 5.0.0 use QROutputInterface::GDIMAGE_JPG instead + * @see \chillerlan\QRCode\Output\QROutputInterface::GDIMAGE_JPG + * @var string + */ + public const OUTPUT_IMAGE_JPG = QROutputInterface::GDIMAGE_JPG; + + /** + * @deprecated 5.0.0 use QROutputInterface::GDIMAGE_GIF instead + * @see \chillerlan\QRCode\Output\QROutputInterface::GDIMAGE_GIF + * @var string + */ + public const OUTPUT_IMAGE_GIF = QROutputInterface::GDIMAGE_GIF; + + /** + * @deprecated 5.0.0 use QROutputInterface::STRING_JSON instead + * @see \chillerlan\QRCode\Output\QROutputInterface::STRING_JSON + * @var string + */ + public const OUTPUT_STRING_JSON = QROutputInterface::STRING_JSON; + + /** + * @deprecated 5.0.0 use QROutputInterface::STRING_TEXT instead + * @see \chillerlan\QRCode\Output\QROutputInterface::STRING_TEXT + * @var string + */ + public const OUTPUT_STRING_TEXT = QROutputInterface::STRING_TEXT; + + /** + * @deprecated 5.0.0 use QROutputInterface::IMAGICK instead + * @see \chillerlan\QRCode\Output\QROutputInterface::IMAGICK + * @var string + */ + public const OUTPUT_IMAGICK = QROutputInterface::IMAGICK; + + /** + * @deprecated 5.0.0 use QROutputInterface::FPDF instead + * @see \chillerlan\QRCode\Output\QROutputInterface::FPDF + * @var string + */ + public const OUTPUT_FPDF = QROutputInterface::FPDF; + + /** + * @deprecated 5.0.0 use QROutputInterface::EPS instead + * @see \chillerlan\QRCode\Output\QROutputInterface::EPS + * @var string + */ + public const OUTPUT_EPS = QROutputInterface::EPS; + + /** + * @deprecated 5.0.0 use QROutputInterface::CUSTOM instead + * @see \chillerlan\QRCode\Output\QROutputInterface::CUSTOM + * @var string + */ + public const OUTPUT_CUSTOM = QROutputInterface::CUSTOM; + + /** + * @deprecated 5.0.0 use QROutputInterface::MODES instead + * @see \chillerlan\QRCode\Output\QROutputInterface::MODES * @var string[] */ - public const OUTPUT_MODES = [ - self::OUTPUT_MARKUP_SVG => QRMarkupSVG::class, - self::OUTPUT_MARKUP_HTML => QRMarkupHTML::class, - self::OUTPUT_IMAGE_PNG => QRGdImage::class, - self::OUTPUT_IMAGE_GIF => QRGdImage::class, - self::OUTPUT_IMAGE_JPG => QRGdImage::class, - self::OUTPUT_STRING_JSON => QRString::class, - self::OUTPUT_STRING_TEXT => QRString::class, - self::OUTPUT_IMAGICK => QRImagick::class, - self::OUTPUT_FPDF => QRFpdf::class, - self::OUTPUT_EPS => QREps::class, - ]; + public const OUTPUT_MODES = QROutputInterface::MODES; /** * The settings container @@ -202,11 +243,11 @@ class QRCode{ */ protected function initOutputInterface():QROutputInterface{ - if($this->options->outputType === $this::OUTPUT_CUSTOM){ + if($this->options->outputType === QROutputInterface::CUSTOM){ return $this->initCustomOutputInterface(); } - $outputInterface = $this::OUTPUT_MODES[$this->options->outputType] ?? false; + $outputInterface = QROutputInterface::MODES[$this->options->outputType] ?? false; if($outputInterface){ return new $outputInterface($this->options, $this->getMatrix()); diff --git a/src/QROptionsTrait.php b/src/QROptionsTrait.php index f92b64908..8d40e2acf 100644 --- a/src/QROptionsTrait.php +++ b/src/QROptionsTrait.php @@ -12,6 +12,7 @@ namespace chillerlan\QRCode; +use chillerlan\QRCode\Output\QROutputInterface; use chillerlan\QRCode\Common\{EccLevel, MaskPattern, Version}; use chillerlan\QRCode\Decoder\{GDLuminanceSource, IMagickLuminanceSource}; use function array_values, count, extension_loaded, in_array, is_numeric, max, min, sprintf, strtolower; @@ -76,12 +77,15 @@ trait QROptionsTrait{ /** * The output type * - * - QRCode::OUTPUT_MARKUP_XXXX where XXXX = HTML, SVG - * - QRCode::OUTPUT_IMAGE_XXX where XXX = PNG, GIF, JPG - * - QRCode::OUTPUT_STRING_XXXX where XXXX = TEXT, JSON - * - QRCode::OUTPUT_CUSTOM + * - QROutputInterface::MARKUP_XXXX where XXXX = HTML, SVG + * - QROutputInterface::GDIMAGE_XXX where XXX = PNG, GIF, JPG + * - QROutputInterface::STRING_XXXX where XXXX = TEXT, JSON + * - QROutputInterface::IMAGICK + * - QROutputInterface::EPS + * - QROutputInterface::FPDF + * - QROutputInterface::CUSTOM */ - protected string $outputType = QRCode::OUTPUT_MARKUP_SVG; + protected string $outputType = QROutputInterface::MARKUP_SVG; /** * the FQCN of the custom QROutputInterface if $outputType is set to QRCode::OUTPUT_CUSTOM diff --git a/tests/Data/QRMatrixTest.php b/tests/Data/QRMatrixTest.php index 888882c3b..69b429b3f 100755 --- a/tests/Data/QRMatrixTest.php +++ b/tests/Data/QRMatrixTest.php @@ -13,7 +13,7 @@ namespace chillerlan\QRCodeTest\Data; use chillerlan\QRCode\{QRCode, QROptions}; use chillerlan\QRCode\Common\{EccLevel, MaskPattern, Version}; use chillerlan\QRCode\Data\{QRCodeDataException, QRMatrix}; -use chillerlan\QRCode\Output\QRString; +use chillerlan\QRCode\Output\{QROutputInterface, QRString}; use PHPUnit\Framework\TestCase; use PHPUnit\Util\Color; use Generator; @@ -42,7 +42,7 @@ final class QRMatrixTest extends TestCase{ */ public static function debugMatrix(QRMatrix $matrix):void{ $opt = new QROptions; - $opt->outputType = QRCode::OUTPUT_STRING_TEXT; + $opt->outputType = QROutputInterface::STRING_TEXT; $opt->eol = Color::colorize('reset', "\x00\n"); $opt->moduleValues = [ // finder diff --git a/tests/Output/QRFpdfTest.php b/tests/Output/QRFpdfTest.php index 6248406b3..673fef243 100644 --- a/tests/Output/QRFpdfTest.php +++ b/tests/Output/QRFpdfTest.php @@ -11,9 +11,8 @@ namespace chillerlan\QRCodeTest\Output; use FPDF; -use chillerlan\QRCode\QRCode; use chillerlan\QRCode\Data\QRMatrix; -use chillerlan\QRCode\Output\QRFpdf; +use chillerlan\QRCode\Output\{QRFpdf, QROutputInterface}; use function class_exists; @@ -23,7 +22,7 @@ use function class_exists; final class QRFpdfTest extends QROutputTestAbstract{ protected string $FQN = QRFpdf::class; - protected string $type = QRCode::OUTPUT_FPDF; + protected string $type = QROutputInterface::FPDF; /** * @inheritDoc diff --git a/tests/Output/QRGdImageGIFTest.php b/tests/Output/QRGdImageGIFTest.php index 1a2694752..a9ce24e6e 100644 --- a/tests/Output/QRGdImageGIFTest.php +++ b/tests/Output/QRGdImageGIFTest.php @@ -10,13 +10,13 @@ namespace chillerlan\QRCodeTest\Output; -use chillerlan\QRCode\QRCode; +use chillerlan\QRCode\Output\QROutputInterface; /** * */ final class QRGdImageGIFTest extends QRGdImageTestAbstract{ - protected string $type = QRCode::OUTPUT_IMAGE_GIF; + protected string $type = QROutputInterface::GDIMAGE_GIF; } diff --git a/tests/Output/QRGdImageJPGTest.php b/tests/Output/QRGdImageJPGTest.php index 27fd5b43b..69b8ba85a 100644 --- a/tests/Output/QRGdImageJPGTest.php +++ b/tests/Output/QRGdImageJPGTest.php @@ -10,13 +10,13 @@ namespace chillerlan\QRCodeTest\Output; -use chillerlan\QRCode\QRCode; +use chillerlan\QRCode\Output\QROutputInterface; /** * */ final class QRGdImageJPGTest extends QRGdImageTestAbstract{ - protected string $type = QRCode::OUTPUT_IMAGE_JPG; + protected string $type = QROutputInterface::GDIMAGE_JPG; } diff --git a/tests/Output/QRGdImagePNGTest.php b/tests/Output/QRGdImagePNGTest.php index 61d221612..5a5901271 100644 --- a/tests/Output/QRGdImagePNGTest.php +++ b/tests/Output/QRGdImagePNGTest.php @@ -10,13 +10,13 @@ namespace chillerlan\QRCodeTest\Output; -use chillerlan\QRCode\QRCode; +use chillerlan\QRCode\Output\QROutputInterface; /** * */ final class QRGdImagePNGTest extends QRGdImageTestAbstract{ - protected string $type = QRCode::OUTPUT_IMAGE_PNG; + protected string $type = QROutputInterface::GDIMAGE_PNG; } diff --git a/tests/Output/QRImagickTest.php b/tests/Output/QRImagickTest.php index ab2792e2d..3a012b50c 100644 --- a/tests/Output/QRImagickTest.php +++ b/tests/Output/QRImagickTest.php @@ -13,9 +13,8 @@ namespace chillerlan\QRCodeTest\Output; -use chillerlan\QRCode\QRCode; use chillerlan\QRCode\Data\QRMatrix; -use chillerlan\QRCode\Output\QRImagick; +use chillerlan\QRCode\Output\{QRImagick, QROutputInterface}; use Imagick; /** @@ -24,7 +23,7 @@ use Imagick; final class QRImagickTest extends QROutputTestAbstract{ protected string $FQN = QRImagick::class; - protected string $type = QRCode::OUTPUT_IMAGICK; + protected string $type = QROutputInterface::IMAGICK; /** * @inheritDoc diff --git a/tests/Output/QRMarkupHTMLTest.php b/tests/Output/QRMarkupHTMLTest.php index cd390c614..a35cd07c6 100644 --- a/tests/Output/QRMarkupHTMLTest.php +++ b/tests/Output/QRMarkupHTMLTest.php @@ -10,8 +10,7 @@ namespace chillerlan\QRCodeTest\Output; -use chillerlan\QRCode\Output\QRMarkupHTML; -use chillerlan\QRCode\QRCode; +use chillerlan\QRCode\Output\{QRMarkupHTML, QROutputInterface}; /** * @@ -19,6 +18,6 @@ use chillerlan\QRCode\QRCode; final class QRMarkupHTMLTest extends QRMarkupTestAbstract{ protected string $FQN = QRMarkupHTML::class; - protected string $type = QRCode::OUTPUT_MARKUP_HTML; + protected string $type = QROutputInterface::MARKUP_HTML; } diff --git a/tests/Output/QRMarkupSVGTest.php b/tests/Output/QRMarkupSVGTest.php index 435cc9b00..b8fe7d494 100644 --- a/tests/Output/QRMarkupSVGTest.php +++ b/tests/Output/QRMarkupSVGTest.php @@ -10,8 +10,7 @@ namespace chillerlan\QRCodeTest\Output; -use chillerlan\QRCode\Output\QRMarkupSVG; -use chillerlan\QRCode\QRCode; +use chillerlan\QRCode\Output\{QRMarkupSVG, QROutputInterface}; /** * @@ -19,6 +18,6 @@ use chillerlan\QRCode\QRCode; final class QRMarkupSVGTest extends QRMarkupTestAbstract{ protected string $FQN = QRMarkupSVG::class; - protected string $type = QRCode::OUTPUT_MARKUP_SVG; + protected string $type = QROutputInterface::MARKUP_SVG; } diff --git a/tests/Output/QRStringJSONTest.php b/tests/Output/QRStringJSONTest.php index ccc3b9fa0..b3a73eda9 100644 --- a/tests/Output/QRStringJSONTest.php +++ b/tests/Output/QRStringJSONTest.php @@ -10,7 +10,7 @@ namespace chillerlan\QRCodeTest\Output; -use chillerlan\QRCode\QRCode; +use chillerlan\QRCode\Output\QROutputInterface; use function extension_loaded; /** @@ -18,7 +18,7 @@ use function extension_loaded; */ final class QRStringJSONTest extends QRStringTestAbstract{ - protected string $type = QRCode::OUTPUT_STRING_JSON; + protected string $type = QROutputInterface::STRING_JSON; /** * @inheritDoc diff --git a/tests/Output/QRStringTEXTTest.php b/tests/Output/QRStringTEXTTest.php index 2ef223835..025d12f31 100644 --- a/tests/Output/QRStringTEXTTest.php +++ b/tests/Output/QRStringTEXTTest.php @@ -11,14 +11,14 @@ namespace chillerlan\QRCodeTest\Output; use chillerlan\QRCode\Data\QRMatrix; -use chillerlan\QRCode\QRCode; +use chillerlan\QRCode\Output\QROutputInterface; /** * */ final class QRStringTEXTTest extends QRStringTestAbstract{ - protected string $type = QRCode::OUTPUT_STRING_TEXT; + protected string $type = QROutputInterface::STRING_TEXT; /** * @inheritDoc diff --git a/tests/QRCodeReaderTestAbstract.php b/tests/QRCodeReaderTestAbstract.php index d9b25d939..f7622853f 100644 --- a/tests/QRCodeReaderTestAbstract.php +++ b/tests/QRCodeReaderTestAbstract.php @@ -12,11 +12,12 @@ namespace chillerlan\QRCodeTest; -use chillerlan\Settings\SettingsContainerInterface; -use Exception, Generator; -use chillerlan\QRCode\Common\{EccLevel, Mode, Version}; use chillerlan\QRCode\{QRCode, QROptions}; +use chillerlan\QRCode\Common\{EccLevel, Mode, Version}; +use chillerlan\QRCode\Output\QROutputInterface; +use chillerlan\Settings\SettingsContainerInterface; use PHPUnit\Framework\TestCase; +use Exception, Generator; use function range, sprintf, str_repeat, substr; /** @@ -82,7 +83,7 @@ abstract class QRCodeReaderTestAbstract extends TestCase{ } public function testReaderMultiSegment():void{ - $this->options->outputType = QRCode::OUTPUT_IMAGE_PNG; + $this->options->outputType = QROutputInterface::GDIMAGE_PNG; $this->options->imageBase64 = false; $numeric = '123456789012345678901234567890'; @@ -122,7 +123,7 @@ abstract class QRCodeReaderTestAbstract extends TestCase{ * @dataProvider dataTestProvider */ public function testReadData(Version $version, EccLevel $ecc, string $expected):void{ - $this->options->outputType = QRCode::OUTPUT_IMAGE_PNG; + $this->options->outputType = QROutputInterface::GDIMAGE_PNG; $this->options->imageTransparent = false; $this->options->eccLevel = $ecc->getLevel(); $this->options->version = $version->getVersionNumber();