فهرست منبع

:shower: QROptions::$dataMode -> $dataModeOverride

codemasher 5 سال پیش
والد
کامیت
0d66c5a2f3
4فایلهای تغییر یافته به همراه10 افزوده شده و 10 حذف شده
  1. 6 6
      src/QRCode.php
  2. 1 1
      src/QROptions.php
  3. 2 2
      src/QROptionsTrait.php
  4. 1 1
      tests/QRCodeTest.php

+ 6 - 6
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);

+ 1 - 1
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

+ 2 - 2
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

+ 1 - 1
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));
 	}