From 0d66c5a2f360ea337c379ad09c69d0ab6a7df963 Mon Sep 17 00:00:00 2001 From: codemasher Date: Sun, 5 Apr 2020 02:21:14 +0200 Subject: [PATCH] :shower: QROptions::$dataMode -> $dataModeOverride --- src/QRCode.php | 12 ++++++------ src/QROptions.php | 2 +- src/QROptionsTrait.php | 4 ++-- tests/QRCodeTest.php | 2 +- 4 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/QRCode.php b/src/QRCode.php index b736d17f6..4048754da 100755 --- a/src/QRCode.php +++ b/src/QRCode.php @@ -20,7 +20,7 @@ use chillerlan\QRCode\Output\{ }; use chillerlan\Settings\SettingsContainerInterface; -use function call_user_func_array, class_exists, in_array, mb_internal_encoding, ord, strlen; +use function call_user_func_array, class_exists, in_array, mb_internal_encoding, ord, strlen, strtolower; /** * Turns a text string into a Model 2 QR Code @@ -139,10 +139,10 @@ class QRCode{ * @var string[] */ protected const DATA_INTERFACES = [ - 'Number' => Number::class, - 'AlphaNum' => AlphaNum::class, - 'Kanji' => Kanji::class, - 'Byte' => Byte::class, + 'number' => Number::class, + 'alphanum' => AlphaNum::class, + 'kanji' => Kanji::class, + 'byte' => Byte::class, ]; /** @@ -231,7 +231,7 @@ class QRCode{ // allow forcing the data mode // see https://github.com/chillerlan/php-qrcode/issues/39 - $interface = $this::DATA_INTERFACES[$this->options->dataMode] ?? null; + $interface = $this::DATA_INTERFACES[strtolower($this->options->dataModeOverride)] ?? null; if($interface !== null){ return new $interface($this->options, $data); diff --git a/src/QROptions.php b/src/QROptions.php index 79242245d..985c304dd 100644 --- a/src/QROptions.php +++ b/src/QROptions.php @@ -24,7 +24,7 @@ use chillerlan\Settings\SettingsContainerAbstract; * @property int $maskPattern * @property bool $addQuietzone * @property int $quietzoneSize - * @property string|null $dataMode + * @property string|null $dataModeOverride * @property string $outputType * @property string|null $outputInterface * @property string|null $cachefile diff --git a/src/QROptionsTrait.php b/src/QROptionsTrait.php index f1bc71665..0a2fd8247 100644 --- a/src/QROptionsTrait.php +++ b/src/QROptionsTrait.php @@ -74,11 +74,11 @@ trait QROptionsTrait{ /** * Use this to circumvent the data mode detection and force the usage of the given mode. * - * valid modes are: Number, AlphaNum, Kanji, Byte + * valid modes are: Number, AlphaNum, Kanji, Byte (case insensitive) * * @see https://github.com/chillerlan/php-qrcode/issues/39 */ - protected ?string $dataMode = null; + protected ?string $dataModeOverride = null; /** * The output type diff --git a/tests/QRCodeTest.php b/tests/QRCodeTest.php index fee448146..6d624931d 100755 --- a/tests/QRCodeTest.php +++ b/tests/QRCodeTest.php @@ -132,7 +132,7 @@ class QRCodeTest extends QRTestAbstract{ $this->expectException(QRCodeDataException::class); $this->expectExceptionMessage('illegal char:'); - $this->qrcode = $this->reflection->newInstanceArgs([new QROptions(['dataMode' => 'AlphaNum'])]); + $this->qrcode = $this->reflection->newInstanceArgs([new QROptions(['dataModeOverride' => 'AlphaNum'])]); $this->qrcode->initDataInterface(random_bytes(32)); }