Просмотр исходного кода

:octocat: +QROptions::$textLineStart and QROptions::$jsonAsBooleans output options

smiley 2 лет назад
Родитель
Сommit
f1008bd674
2 измененных файлов с 17 добавлено и 7 удалено
  1. 6 5
      src/Output/QRString.php
  2. 11 2
      src/QROptionsTrait.php

+ 6 - 5
src/Output/QRString.php

@@ -7,7 +7,6 @@
  * @copyright    2015 Smiley
  * @license      MIT
  *
- * @noinspection PhpUnusedParameterInspection
  * @noinspection PhpComposerExtensionStubsInspection
  */
 
@@ -65,7 +64,7 @@ class QRString extends QROutputAbstract{
 	 * string output
 	 */
 	protected function text():string{
-		$str = [];
+		$lines = [];
 
 		for($y = 0; $y < $this->moduleCount; $y++){
 			$r = [];
@@ -74,17 +73,19 @@ class QRString extends QROutputAbstract{
 				$r[] = $this->getModuleValueAt($x, $y);
 			}
 
-			$str[] = implode('', $r);
+			$lines[] = $this->options->textLineStart.implode('', $r);
 		}
 
-		return implode($this->options->eol, $str);
+		return implode($this->options->eol, $lines);
 	}
 
 	/**
 	 * JSON output
+	 *
+	 * @throws \JsonException
 	 */
 	protected function json():string{
-		return json_encode($this->matrix->getMatrix(), JSON_THROW_ON_ERROR);
+		return json_encode($this->matrix->getMatrix($this->options->jsonAsBooleans), JSON_THROW_ON_ERROR);
 	}
 
 	//

+ 11 - 2
src/QROptionsTrait.php

@@ -371,13 +371,22 @@ trait QROptionsTrait{
 	/**
 	 * String substitute for dark
 	 */
-	protected string $textDark = '🔴';
+	protected string $textDark = '██';
 
 	/**
 	 * String substitute for light
 	 */
-	protected string $textLight = '';
+	protected string $textLight = '░░';
 
+	/**
+	 * An optional line prefix, e.g. empty space to align the QR Code in a console
+	 */
+	protected string $textLineStart = '';
+
+	/**
+	 * Whether to return matrix values in JSON as booleans or $M_TYPE integers
+	 */
+	protected bool $jsonAsBooleans = false;
 
 	/*
 	 * QRFpdf settings