Skip to content

Commit

Permalink
😭 php 5.6 compat
Browse files Browse the repository at this point in the history
  • Loading branch information
codemasher committed Jan 19, 2018
1 parent 03bd062 commit 1ba7f20
Show file tree
Hide file tree
Showing 30 changed files with 350 additions and 284 deletions.
6 changes: 2 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
},
Expand Down
33 changes: 0 additions & 33 deletions examples/MyAuthenticatorClass.php

This file was deleted.

17 changes: 0 additions & 17 deletions examples/authenticator.php

This file was deleted.

3 changes: 2 additions & 1 deletion examples/custom_output.php
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down
3 changes: 2 additions & 1 deletion examples/html.php
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down
3 changes: 2 additions & 1 deletion examples/image.php
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down
24 changes: 16 additions & 8 deletions examples/svg.php
Original file line number Diff line number Diff line change
Expand Up @@ -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" />
Expand Down Expand Up @@ -61,9 +64,14 @@
],
]);

#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;
3 changes: 2 additions & 1 deletion examples/text.php
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down
13 changes: 10 additions & 3 deletions public/qrcode.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,16 @@

$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);
Expand Down
4 changes: 2 additions & 2 deletions src/Data/AlphaNum.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -59,7 +59,7 @@ protected function write(string $data){
* @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){
Expand Down
2 changes: 1 addition & 1 deletion src/Data/Byte.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class Byte extends QRDataAbstract{
/**
* @inheritdoc
*/
protected function write(string $data){
protected function write($data){
$i = 0;

while($i < $this->strlen){
Expand Down
4 changes: 2 additions & 2 deletions src/Data/Kanji.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class Kanji extends QRDataAbstract{
/**
* @inheritdoc
*/
protected function getLength(string $data):int{
protected function getLength($data){
return mb_strlen($data, 'SJIS');
}

Expand All @@ -42,7 +42,7 @@ protected function getLength(string $data):int{
* @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){
Expand Down
12 changes: 6 additions & 6 deletions src/Data/MaskPatternTester.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand All @@ -56,7 +56,7 @@ public function setMatrix(QRMatrix $matrix):MaskPatternTester{
*
* @return int
*/
public function testPattern():int{
public function testPattern(){
$penalty = 0;

for($level = 1; $level <= 4; $level++){
Expand All @@ -71,7 +71,7 @@ public function testPattern():int{
*
* @return float
*/
protected function testLevel1():float{
protected function testLevel1(){
$penalty = 0;

foreach($this->matrix->matrix() as $y => $row){
Expand Down Expand Up @@ -112,7 +112,7 @@ protected function testLevel1():float{
*
* @return float
*/
protected function testLevel2():float{
protected function testLevel2(){
$penalty = 0;

foreach($this->matrix->matrix() as $y => $row){
Expand Down Expand Up @@ -160,7 +160,7 @@ protected function testLevel2():float{
*
* @return float
*/
protected function testLevel3():float{
protected function testLevel3(){
$penalty = 0;

foreach($this->matrix->matrix() as $y => $row){
Expand Down Expand Up @@ -205,7 +205,7 @@ protected function testLevel3():float{
*
* @return float
*/
protected function testLevel4():float {
protected function testLevel4() {
$count = 0;

foreach($this->matrix->matrix() as $y => $row){
Expand Down
4 changes: 2 additions & 2 deletions src/Data/Number.php
Original file line number Diff line number Diff line change
Expand Up @@ -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){
Expand Down Expand Up @@ -61,7 +61,7 @@ protected function write(string $data){
* @return int
* @throws \chillerlan\QRCode\Data\QRCodeDataException
*/
protected function parseInt(string $string):int {
protected function parseInt($string) {
$num = 0;
$map = str_split('0123456789');

Expand Down

0 comments on commit 1ba7f20

Please sign in to comment.