diff --git a/src/PeratX/SFQRCode/QRCode.php b/src/PeratX/SFQRCode/QRCode.php index 8110996..b165d80 100644 --- a/src/PeratX/SFQRCode/QRCode.php +++ b/src/PeratX/SFQRCode/QRCode.php @@ -19,7 +19,6 @@ class QRCode{ public $width; public $data; - public function encodeMask(QRInput $input, $mask){ if($input->getVersion() < 0 || $input->getVersion() > SFQRCode::QRSPEC_VERSION_MAX){ throw new \Exception('wrong version'); @@ -92,7 +91,6 @@ public function encodeString8bit($string, $version, $level){ } $input = new QRInput($version, $level); - if($input == NULL) return NULL; $ret = $input->append(SFQRCode::QR_MODE_8, strlen($string), str_split($string)); if($ret < 0){ diff --git a/src/PeratX/SFQRCode/QRMask.php b/src/PeratX/SFQRCode/QRMask.php index e65d4bb..5d22de8 100644 --- a/src/PeratX/SFQRCode/QRMask.php +++ b/src/PeratX/SFQRCode/QRMask.php @@ -18,12 +18,10 @@ class QRMask{ public $runLength = array(); - public function __construct(){ $this->runLength = array_fill(0, SFQRCode::QRSPEC_WIDTH_MAX + 1, 0); } - public function writeFormatInformation($width, &$frame, $mask, $level){ $blacks = 0; $format = QRSpec::getFormatInfo($mask, $level); @@ -118,7 +116,6 @@ private function generateMaskNo($maskNo, $width, $frame){ return $bitMask; } - public static function serial($bitFrame){ $codeArr = array(); @@ -128,7 +125,6 @@ public static function serial($bitFrame){ return gzcompress(join("\n", $codeArr), 9); } - public static function unserial($code){ $codeArr = array(); @@ -139,13 +135,12 @@ public static function unserial($code){ return $codeArr; } - public function makeMaskNo($maskNo, $width, $s, &$d, $maskGenOnly = false){ $b = 0; $fileName = SFQRCode::getInstance()->getDataFolder() . 'mask_' . $maskNo . DIRECTORY_SEPARATOR . 'mask_' . $width . '_' . $maskNo . '.dat'; - if(SFQRCode::QR_CACHEABLE){ + if(SFQRCode::isCacheable()){ if(file_exists($fileName)){ $bitMask = self::unserial(file_get_contents($fileName)); }else{ @@ -176,7 +171,6 @@ public function makeMaskNo($maskNo, $width, $s, &$d, $maskGenOnly = false){ return $b; } - public function makeMask($width, $frame, $maskNo, $level){ $masked = array_fill(0, $width, str_repeat("\0", $width)); $this->makeMaskNo($maskNo, $width, $frame, $masked); @@ -185,7 +179,6 @@ public function makeMask($width, $frame, $maskNo, $level){ return $masked; } - public function calcN1N3($length){ $demerit = 0; @@ -214,7 +207,6 @@ public function calcN1N3($length){ return $demerit; } - public function evaluateSymbol($width, $frame){ $demerit = 0; @@ -280,7 +272,6 @@ public function evaluateSymbol($width, $frame){ return $demerit; } - public function mask($width, $frame, $level){ $minDemerit = PHP_INT_MAX; @@ -316,6 +307,4 @@ public function mask($width, $frame, $level){ return $bestMask; } - - } diff --git a/src/PeratX/SFQRCode/QRSpec.php b/src/PeratX/SFQRCode/QRSpec.php index 3a1e19c..6845f28 100644 --- a/src/PeratX/SFQRCode/QRSpec.php +++ b/src/PeratX/SFQRCode/QRSpec.php @@ -435,16 +435,14 @@ public static function createFrame($version){ return $frame; } - public static function serial($frame){ + public static function serialize($frame){ return gzcompress(join("\n", $frame), 9); } - - public static function unserial($code){ + public static function deserialize($code){ return explode("\n", gzuncompress($code)); } - public static function newFrame($version){ if($version < 1 || $version > SFQRCode::QRSPEC_VERSION_MAX) return null; @@ -453,12 +451,12 @@ public static function newFrame($version){ $fileName = SFQRCode::getInstance()->getDataFolder() . 'frame_' . $version . '.dat'; - if(SFQRCode::QR_CACHEABLE){ + if(SFQRCode::isCacheable()){ if(file_exists($fileName)){ - self::$frames[$version] = self::unserial(file_get_contents($fileName)); + self::$frames[$version] = self::deserialize(file_get_contents($fileName)); }else{ self::$frames[$version] = self::createFrame($version); - file_put_contents($fileName, self::serial(self::$frames[$version])); + file_put_contents($fileName, self::serialize(self::$frames[$version])); } }else{ self::$frames[$version] = self::createFrame($version); @@ -471,7 +469,6 @@ public static function newFrame($version){ return self::$frames[$version]; } - public static function rsBlockNum($spec){ return $spec[0] + $spec[3]; } diff --git a/src/PeratX/SFQRCode/QRTools.php b/src/PeratX/SFQRCode/QRTools.php index 9b5d61c..7adead6 100644 --- a/src/PeratX/SFQRCode/QRTools.php +++ b/src/PeratX/SFQRCode/QRTools.php @@ -15,7 +15,6 @@ class QRTools{ - public static function binarize($frame){ $len = count($frame); foreach($frame as &$frameLine){ @@ -28,7 +27,6 @@ public static function binarize($frame){ return $frame; } - public static function tcPdfBarcodeArray($code, $mode = 'QR,L'){ $barcode_array = array(); diff --git a/src/PeratX/SFQRCode/SFQRCode.php b/src/PeratX/SFQRCode/SFQRCode.php index a881674..d68013f 100644 --- a/src/PeratX/SFQRCode/SFQRCode.php +++ b/src/PeratX/SFQRCode/SFQRCode.php @@ -16,7 +16,6 @@ use PeratX\SimpleFramework\Module\Module; class SFQRCode extends Module{ - const QR_CACHEABLE = true; const QR_FIND_BEST_MASK = true; const QR_FIND_FROM_RANDOM = false; const QR_DEFAULT_MASK = 2; @@ -58,6 +57,8 @@ class SFQRCode extends Module{ const QRCAP_REMINDER = 2; const QRCAP_EC = 3; + private static $cacheable = false; + private static $obj; public function load(){ @@ -65,6 +66,14 @@ public function load(){ @mkdir($this->getDataFolder()); } + public static function isCacheable(): bool{ + return self::$cacheable; + } + + public static function setCacheable(bool $cacheable){ + self::$cacheable = $cacheable; + } + public static function getInstance(): SFQRCode{ return self::$obj; }