Ver Fonte

:sob: php 5.6 compat

codemasher há 8 anos atrás
pai
commit
1ba7f204e1

+ 2 - 4
composer.json

@@ -18,12 +18,10 @@
 		}
 	],
 	"require": {
-		"php": ">=7.0.3",
-		"chillerlan/php-traits": "1.1.*",
-		"chillerlan/php-authenticator": ">=2.0.0"
+		"php": ">=5.6.0"
 	},
 	"require-dev": {
-		"phpunit/phpunit": "6.5.*"
+		"phpunit/phpunit": "^5.7"
 	},
 	"suggest": {
 	},

+ 0 - 33
examples/MyAuthenticatorClass.php

@@ -1,33 +0,0 @@
-<?php
-/**
- * Class MyAuthenticatorClass
- *
- * @filesource   MyAuthenticatorClass.php
- * @created      24.12.2017
- * @package      chillerlan\QRCodeExamples
- * @author       Smiley <smiley@chillerlan.net>
- * @copyright    2017 Smiley
- * @license      MIT
- */
-
-namespace chillerlan\QRCodeExamples;
-
-use chillerlan\QRCode\{QRCode, QROptions, Traits\QRAuthenticator};
-
-/**
- * using the QRAuthenticator trait
- */
-class MyAuthenticatorClass{
-	use QRAuthenticator;
-
-	public function getQRCode(){
-		// data fetched from wherever
-		$this->authenticatorSecret = 'SECRETTEST234567';
-		$this->qrOptions = new QROptions(['outputType' => QRCode::OUTPUT_MARKUP_SVG]); // set options if needed
-		$label = 'my label';
-		$issuer = 'example.com';
-
-		return $this->getURIQRCode($label, $issuer);
-	}
-
-}

+ 0 - 17
examples/authenticator.php

@@ -1,17 +0,0 @@
-<?php
-/**
- *
- * @filesource   authenticator.php
- * @created      24.12.2017
- * @author       Smiley <smiley@chillerlan.net>
- * @copyright    2017 Smiley
- * @license      MIT
- */
-
-namespace chillerlan\QRCodeExamples;
-
-require_once '../vendor/autoload.php';
-
-header('Content-type: image/svg+xml');
-
-echo (new MyAuthenticatorClass)->getQRCode();

+ 2 - 1
examples/custom_output.php

@@ -10,7 +10,8 @@
 
 namespace chillerlan\QRCodeExamples;
 
-use chillerlan\QRCode\{QRCode, QROptions};
+use chillerlan\QRCode\QRCode;
+use chillerlan\QRCode\QROptions;
 
 require_once __DIR__.'/../vendor/autoload.php';
 

+ 2 - 1
examples/html.php

@@ -10,7 +10,8 @@
 
 namespace chillerlan\QRCodeExamples;
 
-use chillerlan\QRCode\{QRCode, QROptions};
+use chillerlan\QRCode\QRCode;
+use chillerlan\QRCode\QROptions;
 
 require_once '../vendor/autoload.php';
 

+ 2 - 1
examples/image.php

@@ -10,7 +10,8 @@
 
 namespace chillerlan\QRCodeExamples;
 
-use chillerlan\QRCode\{QRCode, QROptions};
+use chillerlan\QRCode\QRCode;
+use chillerlan\QRCode\QROptions;
 
 require_once __DIR__.'/../vendor/autoload.php';
 

+ 16 - 8
examples/svg.php

@@ -10,20 +10,23 @@
 
 namespace chillerlan\QRCodeExamples;
 
-use chillerlan\QRCode\{QRCode, QROptions};
+use chillerlan\QRCode\QRCode;
+use chillerlan\QRCode\QROptions;
 
 require_once __DIR__.'/../vendor/autoload.php';
 
 $data = 'https://www.youtube.com/watch?v=DLzxrzFCyOs&t=43s';
+$gzip = true;
 
 $options = new QROptions([
-	'version'      => 20,
+	'version'      => 5,
 	'outputType'   => QRCode::OUTPUT_MARKUP_SVG,
 	'eccLevel'     => QRCode::ECC_L,
 	'scale'        => 5,
-	'addQuietzone' => true,
-	'svgOpacity' => 0.8,
-	'svgDefs' => '
+	'addQuietzone' => false,
+	'cssClass'     => 'my-css-class',
+	'svgOpacity'   => 0.8,
+	'svgDefs'      => '
 		<linearGradient id="g2">
 			<stop offset="0%" stop-color="#39F" />
 			<stop offset="100%" stop-color="#F3F" />
@@ -61,9 +64,14 @@ $options = new QROptions([
 	],
 ]);
 
-#header('Content-type: image/svg+xml');
-
-echo (new QRCode($options))->render($data);
+header('Content-type: image/svg+xml');
 
+$qr = (new QRCode($options))->render($data);
 
+if($gzip === true){
+	header('Vary: Accept-Encoding');
+	header('Content-Encoding: gzip');
+	$qr = gzencode($qr ,9);
+}
 
+echo $qr;

+ 2 - 1
examples/text.php

@@ -10,7 +10,8 @@
 
 namespace chillerlan\QRCodeExamples;
 
-use chillerlan\QRCode\{QRCode, QROptions};
+use chillerlan\QRCode\QRCode;
+use chillerlan\QRCode\QROptions;
 
 require_once __DIR__.'/../vendor/autoload.php';
 

+ 10 - 3
public/qrcode.php

@@ -45,9 +45,16 @@ try{
 
 	$moduleValues = array_map(function($v){
 		if(preg_match('/[a-f\d]{6}/i', $v) === 1){
-			return in_array($_POST['output_type'], ['png', 'jpg', 'gif'])
-				? array_map('hexdec', str_split($v, 2))
-				: '#'.$v ;
+
+			if(in_array($_POST['output_type'], ['png', 'jpg', 'gif'])){
+				return array_map('hexdec', str_split($v, 2));
+			}
+			elseif(in_array($_POST['output_type'], ['html', 'svg'])){
+				return'#'.$v ;
+			}
+			elseif($_POST['output_type'] === 'text'){
+				return $v ; // @todo
+			}
 		}
 		return null;
 	}, $moduleValues);

+ 2 - 2
src/Data/AlphaNum.php

@@ -41,7 +41,7 @@ class AlphaNum extends QRDataAbstract{
 	/**
 	 * @inheritdoc
 	 */
-	protected function write(string $data){
+	protected function write($data){
 
 		for($i = 0; $i + 1 < $this->strlen; $i += 2){
 			$this->bitBuffer->put($this->getCharCode($data[$i]) * 45 + $this->getCharCode($data[$i + 1]), 11);
@@ -59,7 +59,7 @@ class AlphaNum extends QRDataAbstract{
 	 * @return int
 	 * @throws \chillerlan\QRCode\Data\QRCodeDataException
 	 */
-	protected function getCharCode(string $chr):int {
+	protected function getCharCode($chr) {
 		$i = array_search($chr, $this::CHAR_MAP);
 
 		if($i !== false){

+ 1 - 1
src/Data/Byte.php

@@ -32,7 +32,7 @@ class Byte extends QRDataAbstract{
 	/**
 	 * @inheritdoc
 	 */
-	protected function write(string $data){
+	protected function write($data){
 		$i = 0;
 
 		while($i < $this->strlen){

+ 2 - 2
src/Data/Kanji.php

@@ -32,7 +32,7 @@ class Kanji extends QRDataAbstract{
 	/**
 	 * @inheritdoc
 	 */
-	protected function getLength(string $data):int{
+	protected function getLength($data){
 		return mb_strlen($data, 'SJIS');
 	}
 
@@ -42,7 +42,7 @@ class Kanji extends QRDataAbstract{
 	 * @return void
 	 * @throws \chillerlan\QRCode\Data\QRCodeDataException
 	 */
-	protected function write(string $data){
+	protected function write($data){
 		$len = strlen($data);
 
 		for($i = 0; $i + 1 < $len; $i += 2){

+ 6 - 6
src/Data/MaskPatternTester.php

@@ -40,7 +40,7 @@ class MaskPatternTester{
 	 *
 	 * @return \chillerlan\QRCode\Data\MaskPatternTester
 	 */
-	public function setMatrix(QRMatrix $matrix):MaskPatternTester{
+	public function setMatrix(QRMatrix $matrix){
 		$this->matrix      = $matrix;
 		$this->moduleCount = $this->matrix->size();
 
@@ -56,7 +56,7 @@ class MaskPatternTester{
 	 *
 	 * @return int
 	 */
-	public function testPattern():int{
+	public function testPattern(){
 		$penalty  = 0;
 
 		for($level = 1; $level <= 4; $level++){
@@ -71,7 +71,7 @@ class MaskPatternTester{
 	 *
 	 * @return float
 	 */
-	protected function testLevel1():float{
+	protected function testLevel1(){
 		$penalty = 0;
 
 		foreach($this->matrix->matrix() as $y => $row){
@@ -112,7 +112,7 @@ class MaskPatternTester{
 	 *
 	 * @return float
 	 */
-	protected function testLevel2():float{
+	protected function testLevel2(){
 		$penalty = 0;
 
 		foreach($this->matrix->matrix() as $y => $row){
@@ -160,7 +160,7 @@ class MaskPatternTester{
 	 *
 	 * @return float
 	 */
-	protected function testLevel3():float{
+	protected function testLevel3(){
 		$penalty = 0;
 
 		foreach($this->matrix->matrix() as $y => $row){
@@ -205,7 +205,7 @@ class MaskPatternTester{
 	 *
 	 * @return float
 	 */
-	protected function testLevel4():float {
+	protected function testLevel4() {
 		$count = 0;
 
 		foreach($this->matrix->matrix() as $y => $row){

+ 2 - 2
src/Data/Number.php

@@ -32,7 +32,7 @@ class Number extends QRDataAbstract{
 	/**
 	 * @inheritdoc
 	 */
-	protected function write(string $data){
+	protected function write($data){
 		$i = 0;
 
 		while($i + 2 < $this->strlen){
@@ -61,7 +61,7 @@ class Number extends QRDataAbstract{
 	 * @return int
 	 * @throws \chillerlan\QRCode\Data\QRCodeDataException
 	 */
-	protected function parseInt(string $string):int {
+	protected function parseInt($string) {
 		$num = 0;
 		$map = str_split('0123456789');
 

+ 19 - 20
src/Data/QRDataAbstract.php

@@ -12,13 +12,12 @@
 
 namespace chillerlan\QRCode\Data;
 
-use chillerlan\QRCode\{
-	QRCode, QRCodeException, QROptions
-};
-use chillerlan\QRCode\Helpers\{
-	BitBuffer, Polynomial
-};
-use chillerlan\Traits\ClassLoader;
+use chillerlan\QRCode\QRCode;
+use chillerlan\QRCode\QRCodeException;
+use chillerlan\QRCode\QROptions;
+use chillerlan\QRCode\Helpers\BitBuffer;
+use chillerlan\QRCode\Helpers\Polynomial;
+use chillerlan\QRCode\Traits\ClassLoader;
 
 /**
  * Processes the binary data and maps it on a matrix which is then being returned
@@ -91,7 +90,7 @@ abstract class QRDataAbstract implements QRDataInterface{
 	 * @param \chillerlan\QRCode\QROptions $options
 	 * @param string|null                  $data
 	 */
-	public function __construct(QROptions $options, string $data = null){
+	public function __construct(QROptions $options, $data = null){
 		$this->options = $options;
 
 		if($data !== null){
@@ -106,7 +105,7 @@ abstract class QRDataAbstract implements QRDataInterface{
 	 *
 	 * @return \chillerlan\QRCode\Data\QRDataInterface
 	 */
-	public function setData(string $data):QRDataInterface{
+	public function setData($data){
 
 		if($this->datamode === QRCode::DATA_KANJI){
 			$data = mb_convert_encoding($data, 'SJIS', mb_detect_encoding($data));
@@ -133,7 +132,7 @@ abstract class QRDataAbstract implements QRDataInterface{
 	 *
 	 * @return \chillerlan\QRCode\Data\QRMatrix
 	 */
-	public function initMatrix(int $maskPattern, bool $test = null):QRMatrix{
+	public function initMatrix($maskPattern, $test = null){
 		/** @var \chillerlan\QRCode\Data\QRMatrix $matrix */
 		$matrix = $this->loadClass(QRMatrix::class, null, $this->version, $this->options->eccLevel);
 
@@ -156,7 +155,7 @@ abstract class QRDataAbstract implements QRDataInterface{
 	 * @throws \chillerlan\QRCode\Data\QRCodeDataException
 	 * @codeCoverageIgnore
 	 */
-	protected function getLengthBits():int {
+	protected function getLengthBits() {
 
 		 foreach([9, 26, 40] as $key => $breakpoint){
 			 if($this->version <= $breakpoint){
@@ -174,7 +173,7 @@ abstract class QRDataAbstract implements QRDataInterface{
 	 *
 	 * @return int
 	 */
-	protected function getLength(string $data):int{
+	protected function getLength($data){
 		return strlen($data);
 	}
 
@@ -184,11 +183,11 @@ abstract class QRDataAbstract implements QRDataInterface{
 	 * @return int
 	 * @throws \chillerlan\QRCode\Data\QRCodeDataException
 	 */
-	protected function getMinimumVersion():int{
+	protected function getMinimumVersion(){
 
 		// guess the version number within the given range
 		foreach(range(max(1, $this->options->versionMin), min($this->options->versionMax, 40)) as $version){
-			$maxlength = $this::MAX_LENGTH[$version][QRCode::DATA_MODES[$this->datamode]][QRCode::ECC_MODES[$this->options->eccLevel]];
+			$maxlength = self::MAX_LENGTH[$version][QRCode::DATA_MODES[$this->datamode]][QRCode::ECC_MODES[$this->options->eccLevel]];
 
 			if($this->strlen <= $maxlength){
 				return $version;
@@ -205,7 +204,7 @@ abstract class QRDataAbstract implements QRDataInterface{
 	 *
 	 * @return void
 	 */
-	abstract protected function write(string $data);
+	abstract protected function write($data);
 
 	/**
 	 * writes the string data to the BitBuffer
@@ -215,11 +214,11 @@ abstract class QRDataAbstract implements QRDataInterface{
 	 * @return \chillerlan\QRCode\Data\QRDataAbstract
 	 * @throws \chillerlan\QRCode\QRCodeException
 	 */
-	protected function writeBitBuffer(string $data):QRDataInterface {
+	protected function writeBitBuffer($data) {
 		$this->bitBuffer = new BitBuffer;
 
 		// @todo: fixme, get real length
-		$MAX_BITS = $this::MAX_BITS[$this->version][QRCode::ECC_MODES[$this->options->eccLevel]];
+		$MAX_BITS = self::MAX_BITS[$this->version][QRCode::ECC_MODES[$this->options->eccLevel]];
 
 		$this->bitBuffer
 			->clear()
@@ -272,8 +271,8 @@ abstract class QRDataAbstract implements QRDataInterface{
 	 *
 	 * @return array
 	 */
-	protected function maskECC():array {
-		list($l1, $l2, $b1, $b2) = $this::RSBLOCKS[$this->version][QRCode::ECC_MODES[$this->options->eccLevel]];
+	protected function maskECC() {
+		list($l1, $l2, $b1, $b2) = self::RSBLOCKS[$this->version][QRCode::ECC_MODES[$this->options->eccLevel]];
 
 		$rsBlocks       = array_fill(0, $l1, [$b1, $b2]);
 		$rsCount        = $l1 + $l2;
@@ -338,7 +337,7 @@ abstract class QRDataAbstract implements QRDataInterface{
 	 *
 	 * @return int[]
 	 */
-	protected function poly(int $key, int $count):array{
+	protected function poly($key, $count){
 		$rsPoly  = new Polynomial;
 		$modPoly = new Polynomial;
 

+ 2 - 2
src/Data/QRDataInterface.php

@@ -159,7 +159,7 @@ interface QRDataInterface{
 	 *
 	 * @return \chillerlan\QRCode\Data\QRDataInterface
 	 */
-	public function setData(string $data);
+	public function setData($data);
 
 	/**
 	 * @param int  $maskPattern
@@ -167,6 +167,6 @@ interface QRDataInterface{
 	 *
 	 * @return \chillerlan\QRCode\Data\QRMatrix
 	 */
-	public function initMatrix(int $maskPattern, bool $test = null):QRMatrix;
+	public function initMatrix($maskPattern, $test = null);
 
 }

+ 25 - 21
src/Data/QRMatrix.php

@@ -129,7 +129,7 @@ class QRMatrix{
 	 *
 	 * @throws \chillerlan\QRCode\Data\QRCodeDataException
 	 */
-	public function __construct(int $version, int $eclevel){
+	public function __construct($version, $eclevel){
 
 		if(!in_array($version, range(1, 40), true)){
 			throw new QRCodeDataException('invalid QR Code version');
@@ -148,28 +148,28 @@ class QRMatrix{
 	/**
 	 * @return array
 	 */
-	public function matrix():array {
+	public function matrix() {
 		return $this->matrix;
 	}
 
 	/**
 	 * @return int
 	 */
-	public function version():int {
+	public function version() {
 		return $this->version;
 	}
 
 	/**
 	 * @return int
 	 */
-	public function eccLevel():int {
+	public function eccLevel() {
 		return $this->eclevel;
 	}
 
 	/**
 	 * @return int
 	 */
-	public function maskPattern():int {
+	public function maskPattern() {
 		return $this->maskPattern;
 	}
 
@@ -180,7 +180,7 @@ class QRMatrix{
 	 *
 	 * @return int
 	 */
-	public function size():int{
+	public function size(){
 		return $this->moduleCount;
 	}
 
@@ -192,7 +192,7 @@ class QRMatrix{
 	 *
 	 * @return int
 	 */
-	public function get(int $x, int $y):int{
+	public function get($x, $y){
 		return $this->matrix[$y][$x];
 	}
 
@@ -209,7 +209,7 @@ class QRMatrix{
 	 *
 	 * @return \chillerlan\QRCode\Data\QRMatrix
 	 */
-	public function set(int $x, int $y, bool $value, int $M_TYPE):QRMatrix{
+	public function set($x, $y, $value, $M_TYPE){
 		$this->matrix[$y][$x] = $M_TYPE << ($value ? 8 : 0);
 
 		return $this;
@@ -229,7 +229,7 @@ class QRMatrix{
 	 *
 	 * @return bool
 	 */
-	public function check(int $x, int $y):bool{
+	public function check($x, $y){
 		return $this->matrix[$y][$x] >> 8 > 0;
 	}
 
@@ -239,7 +239,7 @@ class QRMatrix{
 	 *
 	 * @return \chillerlan\QRCode\Data\QRMatrix
 	 */
-	public function setDarkModule():QRMatrix{
+	public function setDarkModule(){
 		$this->set(8, 4 * $this->version + 9, true, $this::M_DARKMODULE);
 
 		return $this;
@@ -250,7 +250,7 @@ class QRMatrix{
 	 *
 	 * @return \chillerlan\QRCode\Data\QRMatrix
 	 */
-	public function setFinderPattern():QRMatrix{
+	public function setFinderPattern(){
 
 		$pos = [
 			[0, 0], // top left
@@ -279,7 +279,7 @@ class QRMatrix{
 	 *
 	 * @return \chillerlan\QRCode\Data\QRMatrix
 	 */
-	public function setSeparators():QRMatrix{
+	public function setSeparators(){
 
 		$h = [
 			[7, 0],
@@ -311,7 +311,7 @@ class QRMatrix{
 	 *
 	 * @return \chillerlan\QRCode\Data\QRMatrix
 	 */
-	public function setAlignmentPattern():QRMatrix{
+	public function setAlignmentPattern(){
 		$pattern = $this::alignmentPattern[$this->version];
 
 		foreach($pattern as $y){
@@ -342,7 +342,7 @@ class QRMatrix{
 	 *
 	 * @return \chillerlan\QRCode\Data\QRMatrix
 	 */
-	public function setTimingPattern():QRMatrix{
+	public function setTimingPattern(){
 
 		foreach(range(8, $this->moduleCount - 8 - 1) as $i){
 
@@ -367,10 +367,10 @@ class QRMatrix{
 	 *
 	 * @return \chillerlan\QRCode\Data\QRMatrix
 	 */
-	public function setVersionNumber(bool $test = null):QRMatrix{
+	public function setVersionNumber($test = null){
 		$test = $test !== null ? $test : false;
 
-		$bits = $this::versionPattern[$this->version] ?? false;
+		$bits = array_key_exists($this->version, self::versionPattern) ? self::versionPattern[$this->version] : false;
 
 		if($bits !== false){
 
@@ -397,9 +397,11 @@ class QRMatrix{
 	 *
 	 * @return \chillerlan\QRCode\Data\QRMatrix
 	 */
-	public function setFormatInfo(int $maskPattern, bool $test = null):QRMatrix{
+	public function setFormatInfo($maskPattern, $test = null){
 		$test = $test !== null ? $test : false;
-		$bits = $this::formatPattern[QRCode::ECC_MODES[$this->eclevel]][$maskPattern] ?? 0;
+		$bits = array_key_exists($this->eclevel, QRCode::ECC_MODES) && array_key_exists($maskPattern, self::formatPattern[QRCode::ECC_MODES[$this->eclevel]])
+			? self::formatPattern[QRCode::ECC_MODES[$this->eclevel]][$maskPattern] : 0;
+
 		$t    = $this::M_FORMAT;
 
 		for($i = 0; $i < 15; $i++){
@@ -438,8 +440,9 @@ class QRMatrix{
 	 * @param int|null $size
 	 *
 	 * @return \chillerlan\QRCode\Data\QRMatrix
+	 * @throws \chillerlan\QRCode\Data\QRCodeDataException
 	 */
-	public function setQuietZone(int $size = null):QRMatrix{
+	public function setQuietZone($size = null){
 
 		if($this->matrix[$this->moduleCount - 1][$this->moduleCount - 1] === $this::M_NULL){
 			throw new QRCodeDataException('use only after writing data');
@@ -476,7 +479,7 @@ class QRMatrix{
 	 *
 	 * @return \chillerlan\QRCode\Data\QRMatrix
 	 */
-	public function mapData(array $data, int $maskPattern):QRMatrix{
+	public function mapData(array $data, $maskPattern){
 		$this->maskPattern = $maskPattern;
 		$byteCount = count($data);
 		$size      = $this->moduleCount - 1;
@@ -539,8 +542,9 @@ class QRMatrix{
 	 * @param int $maskPattern
 	 *
 	 * @return int
+	 * @throws \chillerlan\QRCode\Data\QRCodeDataException
 	 */
-	protected function getMask(int $x, int $y, int $maskPattern):int {
+	protected function getMask($x, $y, $maskPattern) {
 		$a = $y + $x;
 		$m = $y * $x;
 

+ 5 - 5
src/Helpers/BitBuffer.php

@@ -31,7 +31,7 @@ class BitBuffer{
 	/**
 	 * @return \chillerlan\QRCode\Helpers\BitBuffer
 	 */
-	public function clear():BitBuffer{
+	public function clear(){
 		$this->buffer = [];
 		$this->length = 0;
 
@@ -44,12 +44,11 @@ class BitBuffer{
 	 *
 	 * @return \chillerlan\QRCode\Helpers\BitBuffer
 	 */
-	public function put(int $num, int $length):BitBuffer{
+	public function put($num, $length){
 
 		for($i = 0; $i < $length; $i++){
 			$this->putBit(($num >> ($length - $i - 1))&1 === 1);
 		}
-
 		return $this;
 	}
 
@@ -58,14 +57,15 @@ class BitBuffer{
 	 *
 	 * @return \chillerlan\QRCode\Helpers\BitBuffer
 	 */
-	public function putBit(bool $bit):BitBuffer{
+	public function putBit($bit){
+		var_dump(func_get_args());
 		$bufIndex = floor($this->length / 8);
 
 		if(count($this->buffer) <= $bufIndex){
 			$this->buffer[] = 0;
 		}
 
-		if($bit === true){
+		if($bit){
 			$this->buffer[(int)$bufIndex] |= (0x80 >> ($this->length % 8));
 		}
 

+ 7 - 7
src/Helpers/Polynomial.php

@@ -68,14 +68,14 @@ class Polynomial{
 	 * @param array $num
 	 * @param int   $shift
 	 */
-	public function __construct(array $num = [1], int $shift = 0){
+	public function __construct(array $num = [1], $shift = 0){
 		$this->setNum($num, $shift);
 	}
 
 	/**
 	 * @return array
 	 */
-	public function getNum():array {
+	public function getNum() {
 		return $this->num;
 	}
 
@@ -85,7 +85,7 @@ class Polynomial{
 	 *
 	 * @return \chillerlan\QRCode\Helpers\Polynomial
 	 */
-	public function setNum(array $num, int $shift = 0):Polynomial {
+	public function setNum(array $num, $shift = 0) {
 		$offset = 0;
 		$numCount = count($num);
 
@@ -107,7 +107,7 @@ class Polynomial{
 	 *
 	 * @return \chillerlan\QRCode\Helpers\Polynomial
 	 */
-	public function multiply(array $e):Polynomial {
+	public function multiply(array $e) {
 		$n = array_fill(0, count($this->num) + count($e) - 1, 0);
 
 		foreach($this->num as $i => $vi){
@@ -129,7 +129,7 @@ class Polynomial{
 	 *
 	 * @return \chillerlan\QRCode\Helpers\Polynomial
 	 */
-	public function mod(array $e):Polynomial{
+	public function mod(array $e){
 		$n = $this->num;
 
 		if(count($n) - count($e) < 0){
@@ -153,7 +153,7 @@ class Polynomial{
 	 * @return int
 	 * @throws \chillerlan\QRCode\QRCodeException
 	 */
-	public function glog(int $n):int {
+	public function glog($n) {
 
 		if($n < 1){
 			throw new QRCodeException('log('.$n.')');
@@ -167,7 +167,7 @@ class Polynomial{
 	 *
 	 * @return int
 	 */
-	public function gexp(int $n):int {
+	public function gexp($n) {
 
 		if($n < 0){
 			$n += 255;

+ 6 - 5
src/Output/QRImage.php

@@ -12,7 +12,8 @@
 
 namespace chillerlan\QRCode\Output;
 
-use chillerlan\QRCode\{QRCode, Data\QRMatrix};
+use chillerlan\QRCode\QRCode;
+use chillerlan\QRCode\Data\QRMatrix;
 
 /**
  * Converts the matrix into images, raw or base64 output
@@ -72,7 +73,7 @@ class QRImage extends QROutputAbstract{
 	 * @return string
 	 * @throws \chillerlan\QRCode\Output\QRCodeOutputException
 	 */
-	public function dump():string{
+	public function dump(){
 
 		if($this->options->cachefile !== null && !is_writable(dirname($this->options->cachefile))){
 			throw new QRCodeOutputException('Could not write data to cache file: '.$this->options->cachefile);
@@ -80,7 +81,7 @@ class QRImage extends QROutputAbstract{
 
 		$this->setImage();
 
-		$moduleValues = is_array($this->options->moduleValues[$this->matrix::M_DATA])
+		$moduleValues = is_array($this->options->moduleValues[QRMatrix::M_DATA])
 			? $this->options->moduleValues // @codeCoverageIgnore
 			: $this->moduleValues;
 
@@ -136,11 +137,11 @@ class QRImage extends QROutputAbstract{
 	 * @return string
 	 * @throws \chillerlan\QRCode\Output\QRCodeOutputException
 	 */
-	protected function dumpImage():string {
+	protected function dumpImage() {
 		ob_start();
 
 		try{
-			call_user_func([$this, $this->options->outputType ?? QRCode::OUTPUT_IMAGE_PNG]);
+			call_user_func([$this, $this->options->outputType !== null ? $this->options->outputType : QRCode::OUTPUT_IMAGE_PNG]);
 		}
 		// not going to cover edge cases
 		// @codeCoverageIgnoreStart

+ 4 - 3
src/Output/QRMarkup.php

@@ -85,7 +85,7 @@ class QRMarkup extends QROutputAbstract{
 				$value = $value ? '#000' : '#fff';
 			}
 
-			$path = '';
+			$path = $this->options->eol;
 
 			foreach($matrix as $y => $row){
 				//we'll combine active blocks within a single row as a lightweight compression technique
@@ -101,14 +101,14 @@ class QRMarkup extends QROutputAbstract{
 							$start = $x * $scale;
 						}
 
-						if($row[$x + 1] ?? false){
+						if(isset($row[$x + 1]) && $row[$x + 1] === $M_TYPE){
 							continue;
 						}
 					}
 
 					if($count > 0){
 						$len = $count * $scale;
-						$path .= 'M' .$start. ' ' .($y * $scale). ' h'.$len.' v'.$scale.' h-'.$len.'Z ';
+						$path .= 'M' .$start. ' ' .($y * $scale). ' h'.$len.' v'.$scale.' h-'.$len.'Z '.$this->options->eol;
 
 						// reset count
 						$count = 0;
@@ -123,6 +123,7 @@ class QRMarkup extends QROutputAbstract{
 				$svg .= '<path class="qr-'.$M_TYPE.' '.$this->options->cssClass.'" stroke="transparent" fill="'.$value.'" fill-opacity="'.$this->options->svgOpacity.'" d="'.$path.'" />';
 			}
 
+			break;
 		}
 
 		// close svg

+ 3 - 2
src/Output/QROutputAbstract.php

@@ -12,7 +12,8 @@
 
 namespace chillerlan\QRCode\Output;
 
-use chillerlan\QRCode\{Data\QRMatrix, QROptions};
+use chillerlan\QRCode\Data\QRMatrix;
+use chillerlan\QRCode\QROptions;
 
 /**
  *
@@ -53,7 +54,7 @@ abstract class QROutputAbstract implements QROutputInterface{
 
 	 * @return bool|int
 	 */
-	protected function saveToFile(string $data) {
+	protected function saveToFile($data) {
 		return file_put_contents($this->options->cachefile, $data);
 	}
 

+ 3 - 2
src/Output/QRString.php

@@ -21,8 +21,9 @@ class QRString extends QROutputAbstract{
 
 	/**
 	 * @return string
+	 * @throws \chillerlan\QRCode\Output\QRCodeOutputException
 	 */
-	public function dump():string{
+	public function dump(){
 
 		$data = $this->options->outputType === QRCode::OUTPUT_STRING_JSON
 			? json_encode($this->matrix->matrix())
@@ -43,7 +44,7 @@ class QRString extends QROutputAbstract{
 	/**
 	 * @return string
 	 */
-	protected function toString():string{
+	protected function toString(){
 		$str = [];
 
 		foreach($this->matrix->matrix() as $row){

+ 24 - 18
src/QRCode.php

@@ -12,13 +12,19 @@
 
 namespace chillerlan\QRCode;
 
-use chillerlan\QRCode\Data\{
-	AlphaNum, Byte, Kanji, MaskPatternTester, Number, QRCodeDataException, QRDataInterface, QRMatrix
-};
-use chillerlan\QRCode\Output\{
-	QRCodeOutputException, QRImage, QRMarkup, QROutputInterface, QRString
-};
-use chillerlan\Traits\ClassLoader;
+use chillerlan\QRCode\Data\AlphaNum;
+use chillerlan\QRCode\Data\Byte;
+use chillerlan\QRCode\Data\Kanji;
+use chillerlan\QRCode\Data\MaskPatternTester;
+use chillerlan\QRCode\Data\Number;
+use chillerlan\QRCode\Data\QRCodeDataException;
+use chillerlan\QRCode\Data\QRDataInterface;
+use chillerlan\QRCode\Output\QRCodeOutputException;
+use chillerlan\QRCode\Output\QRImage;
+use chillerlan\QRCode\Output\QRMarkup;
+use chillerlan\QRCode\Output\QROutputInterface;
+use chillerlan\QRCode\Output\QRString;
+use chillerlan\QRCode\Traits\ClassLoader;
 
 /**
  * Turns a text string into a Model 2 QR Code
@@ -107,7 +113,7 @@ class QRCode{
 	public function __construct(QROptions $options = null){
 		mb_internal_encoding('UTF-8');
 
-		$this->setOptions($options ?? new QROptions);
+		$this->setOptions($options instanceof QROptions ? $options : new QROptions);
 	}
 
 	/**
@@ -118,7 +124,7 @@ class QRCode{
 	 * @return \chillerlan\QRCode\QRCode
 	 * @throws \chillerlan\QRCode\QRCodeException
 	 */
-	public function setOptions(QROptions $options):QRCode{
+	public function setOptions(QROptions $options){
 
 		if(!array_key_exists($options->eccLevel, $this::ECC_MODES)){
 			throw new QRCodeException('Invalid error correct level: '.$options->eccLevel);
@@ -146,7 +152,7 @@ class QRCode{
 	 *
 	 * @return mixed
 	 */
-	public function render(string $data){
+	public function render($data){
 		return $this->initOutputInterface($data)->dump();
 	}
 
@@ -158,7 +164,7 @@ class QRCode{
 	 * @return \chillerlan\QRCode\Data\QRMatrix
 	 * @throws \chillerlan\QRCode\Data\QRCodeDataException
 	 */
-	public function getMatrix(string $data):QRMatrix {
+	public function getMatrix($data) {
 		$data = trim($data);
 
 		if(empty($data)){
@@ -190,7 +196,7 @@ class QRCode{
 	 *
 	 * @return int
 	 */
-	protected function getBestMaskPattern():int{
+	protected function getBestMaskPattern(){
 		$penalties = [];
 
 		$tester = new MaskPatternTester;
@@ -216,7 +222,7 @@ class QRCode{
 	 * @return \chillerlan\QRCode\Data\QRDataInterface
 	 * @throws \chillerlan\QRCode\Data\QRCodeDataException
 	 */
-	public function initDataInterface(string $data):QRDataInterface{
+	public function initDataInterface($data){
 
 		$DATA_MODES = [
 			Number::class   => 'Number',
@@ -244,7 +250,7 @@ class QRCode{
 	 * @return \chillerlan\QRCode\Output\QROutputInterface
 	 * @throws \chillerlan\QRCode\Output\QRCodeOutputException
 	 */
-	protected function initOutputInterface(string $data):QROutputInterface{
+	protected function initOutputInterface($data){
 
 		if($this->options->outputType === $this::OUTPUT_CUSTOM && $this->options->outputInterface !== null){
 			return $this->loadClass($this->options->outputInterface, QROutputInterface::class, $this->options, $this->getMatrix($data));
@@ -268,7 +274,7 @@ class QRCode{
 	 *
 	 * @return bool
 	 */
-	public function isNumber(string $string):bool {
+	public function isNumber($string) {
 		$len = strlen($string);
 		$map = str_split('0123456789');
 
@@ -288,7 +294,7 @@ class QRCode{
 	 *
 	 * @return bool
 	 */
-	public function isAlphaNum(string $string):bool {
+	public function isAlphaNum($string) {
 		$len = strlen($string);
 
 		for($i = 0; $i < $len; $i++){
@@ -307,7 +313,7 @@ class QRCode{
 	 *
 	 * @return bool
 	 */
-	public function isKanji(string $string):bool {
+	public function isKanji($string) {
 		$i   = 0;
 		$len = strlen($string);
 
@@ -331,7 +337,7 @@ class QRCode{
 	 *
 	 * @return bool
 	 */
-	protected function isByte(string $data):bool{
+	protected function isByte($data){
 		return !empty($data);
 	}
 

+ 1 - 1
src/QROptions.php

@@ -13,7 +13,7 @@
 namespace chillerlan\QRCode;
 
 use chillerlan\QRCode\Data\QRMatrix;
-use chillerlan\Traits\Container;
+use chillerlan\QRCode\Traits\Container;
 
 /**
  * @property int    $version

+ 76 - 0
src/Traits/ClassLoader.php

@@ -0,0 +1,76 @@
+<?php
+/**
+ * Trait ClassLoader
+ *
+ * @filesource   ClassLoader.php
+ * @created      13.11.2017
+ * @package      chillerlan\Traits
+ * @author       Smiley <smiley@chillerlan.net>
+ * @copyright    2017 Smiley
+ * @license      MIT
+ */
+
+namespace chillerlan\QRCode\Traits;
+
+use chillerlan\QRCode\QRCodeException;
+use Exception;
+use ReflectionClass;
+
+trait ClassLoader{
+
+	/**
+	 * Instances an object of $class/$type with an arbitrary number of $params
+	 *
+	 * @param string $class  class FQCN
+	 * @param string $type   class/parent/interface FQCN
+	 *
+	 * @param mixed $params [optional] the following arguments will be passed to the $class constructor
+	 *
+	 * @return mixed of type $type
+	 * @throws \Exception
+	 */
+	public function loadClass($class, $type = null, ...$params){
+		$type = $type === null ? $class : $type;
+
+		try{
+			$reflectionClass = new ReflectionClass($class);
+			$reflectionType  = new ReflectionClass($type);
+
+			if($reflectionType->isTrait()){
+				trigger_error($class.' cannot be an instance of trait '.$type);
+			}
+
+			if($reflectionClass->isAbstract()){
+				trigger_error('cannot instance abstract class '.$class);
+			}
+
+			if($reflectionClass->isTrait()){
+				trigger_error('cannot instance trait '.$class);
+			}
+
+			if($class !== $type){
+
+				if($reflectionType->isInterface() && !$reflectionClass->implementsInterface($type)){
+					trigger_error($class.' does not implement '.$type);
+				}
+				elseif(!$reflectionClass->isSubclassOf($type)) {
+					trigger_error($class.' does not inherit '.$type);
+				}
+
+			}
+
+			$object = $reflectionClass->newInstanceArgs($params);
+
+			if(!$object instanceof $type){
+				trigger_error('how did u even get here?'); // @codeCoverageIgnore
+			}
+
+			return $object;
+		}
+		catch(Exception $e){
+			throw new QRCodeException('ClassLoader: '.$e->getMessage());
+		}
+
+	}
+
+}

+ 123 - 0
src/Traits/Container.php

@@ -0,0 +1,123 @@
+<?php
+/**
+ * Trait Container
+ *
+ * @filesource   Container.php
+ * @created      13.11.2017
+ * @package      chillerlan\Traits
+ * @author       Smiley <smiley@chillerlan.net>
+ * @copyright    2017 Smiley
+ * @license      MIT
+ */
+
+namespace chillerlan\QRCode\Traits;
+
+use ReflectionProperty;
+
+/**
+ * a generic container with magic getter and setter
+ */
+trait Container{
+
+	/**
+	 * @param array                          $properties
+	 */
+	public function __construct(array $properties = null){
+
+		if(!empty($properties)){
+
+			foreach($properties as $key => $value){
+				$this->__set($key, $value);
+			}
+
+		}
+
+	}
+
+	/**
+	 * @param string $property
+	 *
+	 * @return mixed
+	 */
+	public function __get($property){
+
+		if($this->__isset($property)){
+			return $this->{$property};
+		}
+
+		return null;
+	}
+
+	/**
+	 * @param string $property
+	 * @param mixed  $value
+	 *
+	 * @return void
+	 */
+	public function __set($property, $value){
+
+		// avoid overwriting private properties
+		if(!property_exists($this, $property) || !$this->__isPrivate($property)){
+			$this->{$property} = $value;
+		}
+
+	}
+
+	/**
+	 * @param string $property
+	 *
+	 * @return bool
+	 */
+	public function __isset($property){
+		return (property_exists($this, $property) && !$this->__isPrivate($property)) || ($this->env instanceof DotEnv && $this->env->get($property));
+	}
+
+	/**
+	 * @param string $property
+	 *
+	 * @return bool
+	 */
+	protected function __isPrivate($property){
+		return (new ReflectionProperty($this, $property))->isPrivate();
+	}
+
+	/**
+	 * @param string $property
+	 *
+	 * @return void
+	 */
+	public function __unset($property){
+
+		// avoid unsetting private properties
+		if($this->__isPrivate($property)){
+			unset($this->{$property});
+		}
+
+	}
+
+	/**
+	 * @return string
+	 */
+	public function __toString(){
+		return json_encode($this->__toArray());
+	}
+
+	/**
+	 * @return array
+	 */
+	public function __toArray(){
+		$data = [];
+
+		foreach($this as $property => $value){
+
+			// exclude private properties
+			if($this->__isset($property)){
+				$data[$property] = $value;
+			}
+
+		}
+
+		return $data;
+	}
+
+}

+ 0 - 77
src/Traits/QRAuthenticator.php

@@ -1,77 +0,0 @@
-<?php
-/**
- * Trait QRAuthenticator
- *
- * @filesource   QRAuthenticator.php
- * @created      21.12.2017
- * @package      chillerlan\QRCode\Traits
- * @author       Smiley <smiley@chillerlan.net>
- * @copyright    2017 Smiley
- * @license      MIT
- */
-
-namespace chillerlan\QRCode\Traits;
-
-use chillerlan\Authenticator\Authenticator;
-use chillerlan\QRCode\QRCode;
-
-/**
- * Creates URI QR Codes for use with mmobile authenticators
- */
-trait QRAuthenticator{
-
-	/**
-	 * @var \chillerlan\QRCode\QROptions
-	 */
-	protected $qrOptions;
-
-	/**
-	 * @var string
-	 */
-	protected $authenticatorSecret;
-
-	/**
-	 * @var int
-	 */
-	protected $authenticatorDigits = Authenticator::DEFAULT_DIGITS;
-
-	/**
-	 * @var int
-	 */
-	protected $authenticatorPeriod = Authenticator::DEFAULT_PERIOD;
-
-	/**
-	 * @var string
-	 */
-	protected $authenticatorMode   = Authenticator::DEFAULT_AUTH_MODE;
-
-	/**
-	 * @var string
-	 */
-	protected $authenticatorAlgo   = Authenticator::DEFAULT_HASH_ALGO;
-
-	/**
-	 * @param string $label
-	 * @param string $issuer
-	 *
-	 * @return mixed
-	 */
-	protected function getURIQRCode(string $label, string $issuer) {
-		$uri = $this->getAuthenticator()->setSecret($this->authenticatorSecret)->getUri($label, $issuer);
-
-		return (new QRCode($this->qrOptions))->render($uri);
-	}
-
-	/**
-	 * @return \chillerlan\Authenticator\Authenticator
-	 */
-	protected function getAuthenticator():Authenticator {
-		return (new Authenticator)
-			->setPeriod($this->authenticatorPeriod)
-			->setDigits($this->authenticatorDigits)
-			->setMode($this->authenticatorMode)
-			->setAlgorithm($this->authenticatorAlgo)
-		;
-	}
-
-}

+ 3 - 3
tests/QRTestAbstract.php

@@ -38,7 +38,7 @@ abstract class QRTestAbstract extends TestCase{
 	 *
 	 * @return \ReflectionMethod
 	 */
-	protected function getMethod(string $method):ReflectionMethod {
+	protected function getMethod($method) {
 		$method = $this->reflection->getMethod($method);
 		$method->setAccessible(true);
 
@@ -50,7 +50,7 @@ abstract class QRTestAbstract extends TestCase{
 	 *
 	 * @return \ReflectionProperty
 	 */
-	protected function getProperty(string $property):ReflectionProperty{
+	protected function getProperty($property){
 		$property = $this->reflection->getProperty($property);
 		$property->setAccessible(true);
 
@@ -64,7 +64,7 @@ abstract class QRTestAbstract extends TestCase{
 	 *
 	 * @return void
 	 */
-	protected function setProperty($object, string $property, $value){
+	protected function setProperty($object, $property, $value){
 		$property = $this->getProperty($property);
 		$property->setAccessible(true);
 		$property->setValue($object, $value);

Diff do ficheiro suprimidas por serem muito extensas
+ 0 - 25
tests/Traits/QRAuthenticatorTest.php


Alguns ficheiros não foram mostrados porque muitos ficheiros mudaram neste diff