Jelajahi Sumber

moved API constants to QRCode

smiley 10 tahun lalu
induk
melakukan
b589215f97
7 mengubah file dengan 56 tambahan dan 52 penghapusan
  1. 3 4
      examples/custom.php
  2. 4 6
      examples/html.php
  3. 4 4
      src/Output/QRString.php
  4. 2 2
      src/Output/QRStringOptions.php
  5. 28 0
      src/QRCode.php
  6. 14 35
      src/QRConst.php
  7. 1 1
      src/QROptions.php

+ 3 - 4
examples/custom.php

@@ -3,7 +3,6 @@
 require_once '../vendor/autoload.php';
 require_once '../vendor/autoload.php';
 
 
 use chillerlan\QRCode\QRCode;
 use chillerlan\QRCode\QRCode;
-use chillerlan\QRCode\QRConst;
 use chillerlan\QRCode\QROptions;
 use chillerlan\QRCode\QROptions;
 use chillerlan\QRCode\Output\QRString;
 use chillerlan\QRCode\Output\QRString;
 use chillerlan\QRCode\Output\QRStringOptions;
 use chillerlan\QRCode\Output\QRStringOptions;
@@ -11,11 +10,11 @@ use chillerlan\QRCode\Output\QRStringOptions;
 $starttime = microtime(true);
 $starttime = microtime(true);
 
 
 $qrOptions = new QROptions;
 $qrOptions = new QROptions;
-$qrOptions->typeNumber = QRConst::TYPE_05;
-$qrOptions->errorCorrectLevel = QRConst::ERROR_CORRECT_LEVEL_M;
+$qrOptions->typeNumber = QRCode::TYPE_05;
+$qrOptions->errorCorrectLevel = QRCode::ERROR_CORRECT_LEVEL_M;
 
 
 $qrStringOptions = new QRStringOptions;
 $qrStringOptions = new QRStringOptions;
-$qrStringOptions->type = QRConst::OUTPUT_STRING_TEXT;
+$qrStringOptions->type = QRCode::OUTPUT_STRING_TEXT;
 $qrStringOptions->textDark  = '+';
 $qrStringOptions->textDark  = '+';
 $qrStringOptions->textLight = '-';
 $qrStringOptions->textLight = '-';
 
 

+ 4 - 6
examples/html.php

@@ -5,7 +5,6 @@ require_once '../vendor/autoload.php';
 use chillerlan\QRCode\Output\QRString;
 use chillerlan\QRCode\Output\QRString;
 use chillerlan\QRCode\Output\QRStringOptions;
 use chillerlan\QRCode\Output\QRStringOptions;
 use chillerlan\QRCode\QRCode;
 use chillerlan\QRCode\QRCode;
-use chillerlan\QRCode\QRConst;
 use chillerlan\QRCode\QROptions;
 use chillerlan\QRCode\QROptions;
 
 
 //---------------------------------------------------------
 //---------------------------------------------------------
@@ -44,13 +43,12 @@ echo '<style>
 </style>';
 </style>';
 
 
 $qrStringOptions = new QRStringOptions;
 $qrStringOptions = new QRStringOptions;
-$qrStringOptions->type = QRConst::OUTPUT_STRING_HTML;
+$qrStringOptions->type = QRCode::OUTPUT_STRING_HTML;
 
 
 $qrOptions = new QROptions;
 $qrOptions = new QROptions;
-$qrOptions->typeNumber = QRConst::TYPE_05;
-$qrOptions->errorCorrectLevel = QRConst::ERROR_CORRECT_LEVEL_M;
-$qrOptions->output = new QRString($qrStringOptions);
+$qrOptions->typeNumber = QRCode::TYPE_05;
+$qrOptions->errorCorrectLevel = QRCode::ERROR_CORRECT_LEVEL_M;
 
 
-$qr = new QRCode('skype://callto:echo123', $qrOptions);
+$qr = new QRCode('skype://callto:echo123', new QRString($qrStringOptions), $qrOptions);
 
 
 echo '<div class="qrcode">'.$qr->output().'</div>';
 echo '<div class="qrcode">'.$qr->output().'</div>';

+ 4 - 4
src/Output/QRString.php

@@ -11,7 +11,7 @@
  */
  */
 
 
 namespace chillerlan\QRCode\Output;
 namespace chillerlan\QRCode\Output;
-use chillerlan\QRCode\QRConst;
+use chillerlan\QRCode\QRCode;
 
 
 /**
 /**
  *
  *
@@ -42,9 +42,9 @@ class QRString extends QROutputBase implements QROutputInterface{
 	public function dump(){
 	public function dump(){
 
 
 		switch($this->options->type){
 		switch($this->options->type){
-			case QRConst::OUTPUT_STRING_TEXT: return $this->toText();
-			case QRConst::OUTPUT_STRING_JSON: return $this->toJSON();
-			case QRConst::OUTPUT_STRING_HTML: return $this->toHTML();
+			case QRCode::OUTPUT_STRING_TEXT: return $this->toText();
+			case QRCode::OUTPUT_STRING_JSON: return $this->toJSON();
+			case QRCode::OUTPUT_STRING_HTML: return $this->toHTML();
 			default:
 			default:
 				throw new QRCodeOutputException('Invalid string output type!');
 				throw new QRCodeOutputException('Invalid string output type!');
 		}
 		}

+ 2 - 2
src/Output/QRStringOptions.php

@@ -11,14 +11,14 @@
  */
  */
 
 
 namespace chillerlan\QRCode\Output;
 namespace chillerlan\QRCode\Output;
-use chillerlan\QRCode\QRConst;
+use chillerlan\QRCode\QRCode;
 
 
 /**
 /**
  *
  *
  */
  */
 class QRStringOptions{
 class QRStringOptions{
 
 
-	public $type = QRConst::OUTPUT_STRING_TEXT;
+	public $type = QRCode::OUTPUT_STRING_TEXT;
 
 
 	public $textDark = '#';
 	public $textDark = '#';
 
 

+ 28 - 0
src/QRCode.php

@@ -19,6 +19,34 @@ use chillerlan\QRCode\Output\QROutputInterface;
  */
  */
 class QRCode{
 class QRCode{
 
 
+	/**
+	 * API constants
+	 */
+	const OUTPUT_STRING_TEXT = 0;
+	const OUTPUT_STRING_JSON = 1;
+	const OUTPUT_STRING_HTML = 2;
+
+	const OUTPUT_IMAGE_PNG = 0;
+	const OUTPUT_IMAGE_JPG = 1;
+	const OUTPUT_IMAGE_GIF = 2;
+
+	const ERROR_CORRECT_LEVEL_L = 1; // 7%.
+	const ERROR_CORRECT_LEVEL_M = 0; // 15%.
+	const ERROR_CORRECT_LEVEL_Q = 3; // 25%.
+	const ERROR_CORRECT_LEVEL_H = 2; // 30%.
+
+	// max bits @ ec level L:07 M:15 Q:25 H:30 %
+	const TYPE_01 =  1; //  152  128  104   72
+	const TYPE_02 =  2; //  272  224  176  128
+	const TYPE_03 =  3; //  440  352  272  208
+	const TYPE_04 =  4; //  640  512  384  288
+	const TYPE_05 =  5; //  864  688  496  368
+	const TYPE_06 =  6; // 1088  864  608  480
+	const TYPE_07 =  7; // 1248  992  704  528
+	const TYPE_08 =  8; // 1552 1232  880  688
+	const TYPE_09 =  9; // 1856 1456 1056  800
+	const TYPE_10 = 10; // 2192 1728 1232  976
+
 	/**
 	/**
 	 * @var array
 	 * @var array
 	 */
 	 */

+ 14 - 35
src/QRConst.php

@@ -17,45 +17,24 @@ namespace chillerlan\QRCode;
  */
  */
 class QRConst{
 class QRConst{
 
 
-	const OUTPUT_STRING_TEXT = 0;
-	const OUTPUT_STRING_JSON = 1;
-	const OUTPUT_STRING_HTML = 2;
-
-	const ERROR_CORRECT_LEVEL_L = 1; // 7%.
-	const ERROR_CORRECT_LEVEL_M = 0; // 15%.
-	const ERROR_CORRECT_LEVEL_Q = 3; // 25%.
-	const ERROR_CORRECT_LEVEL_H = 2; // 30%.
-
 	const RSBLOCK = [
 	const RSBLOCK = [
-		self::ERROR_CORRECT_LEVEL_L => 0,
-		self::ERROR_CORRECT_LEVEL_M => 1,
-		self::ERROR_CORRECT_LEVEL_Q => 2,
-		self::ERROR_CORRECT_LEVEL_H => 3,
+		QRCode::ERROR_CORRECT_LEVEL_L => 0,
+		QRCode::ERROR_CORRECT_LEVEL_M => 1,
+		QRCode::ERROR_CORRECT_LEVEL_Q => 2,
+		QRCode::ERROR_CORRECT_LEVEL_H => 3,
 	];
 	];
 
 
-	// max bits @ ec level L:07 M:15 Q:25 H:30 %
-	const TYPE_01 =  1; //  152  128  104   72
-	const TYPE_02 =  2; //  272  224  176  128
-	const TYPE_03 =  3; //  440  352  272  208
-	const TYPE_04 =  4; //  640  512  384  288
-	const TYPE_05 =  5; //  864  688  496  368
-	const TYPE_06 =  6; // 1088  864  608  480
-	const TYPE_07 =  7; // 1248  992  704  528
-	const TYPE_08 =  8; // 1552 1232  880  688
-	const TYPE_09 =  9; // 1856 1456 1056  800
-	const TYPE_10 = 10; // 2192 1728 1232  976
-
 	const MAX_BITS = [
 	const MAX_BITS = [
-		self::TYPE_01 => [ 128,  152,   72,  104],
-		self::TYPE_02 => [ 224,  272,  128,  176],
-		self::TYPE_03 => [ 352,  440,  208,  272],
-		self::TYPE_04 => [ 512,  640,  288,  384],
-		self::TYPE_05 => [ 688,  864,  368,  496],
-		self::TYPE_06 => [ 864, 1088,  480,  608],
-		self::TYPE_07 => [ 992, 1248,  528,  704],
-		self::TYPE_08 => [1232, 1552,  688,  880],
-		self::TYPE_09 => [1456, 1856,  800, 1056],
-		self::TYPE_10 => [1728, 2192,  976, 1232],
+		QRCode::TYPE_01 => [ 128,  152,   72,  104],
+		QRCode::TYPE_02 => [ 224,  272,  128,  176],
+		QRCode::TYPE_03 => [ 352,  440,  208,  272],
+		QRCode::TYPE_04 => [ 512,  640,  288,  384],
+		QRCode::TYPE_05 => [ 688,  864,  368,  496],
+		QRCode::TYPE_06 => [ 864, 1088,  480,  608],
+		QRCode::TYPE_07 => [ 992, 1248,  528,  704],
+		QRCode::TYPE_08 => [1232, 1552,  688,  880],
+		QRCode::TYPE_09 => [1456, 1856,  800, 1056],
+		QRCode::TYPE_10 => [1728, 2192,  976, 1232],
 	];
 	];
 
 
 	const MODE_NUMBER   = 1 << 0;
 	const MODE_NUMBER   = 1 << 0;

+ 1 - 1
src/QROptions.php

@@ -20,7 +20,7 @@ class QROptions{
 	/**
 	/**
 	 * @var int
 	 * @var int
 	 */
 	 */
-	public $errorCorrectLevel = QRConst::ERROR_CORRECT_LEVEL_M;
+	public $errorCorrectLevel = QRCode::ERROR_CORRECT_LEVEL_M;
 
 
 	/**
 	/**
 	 * @var int
 	 * @var int