| 1 |
<?php |
| 2 |
|
| 3 |
/** |
| 4 |
* Class QRDataModeAbstract |
| 5 |
* |
| 6 |
* @created 19.11.2020 |
| 7 |
* @author smiley <[email protected]> |
| 8 |
* @copyright 2020 smiley |
| 9 |
* @license MIT |
| 10 |
*/ |
| 11 |
namespace WCPOS\Vendor\chillerlan\QRCode\Data; |
| 12 |
|
| 13 |
use WCPOS\Vendor\chillerlan\QRCode\Common\Mode; |
| 14 |
/** |
| 15 |
* abstract methods for the several data modes |
| 16 |
*/ |
| 17 |
abstract class QRDataModeAbstract implements QRDataModeInterface |
| 18 |
{ |
| 19 |
/** |
| 20 |
* The data to write |
| 21 |
*/ |
| 22 |
protected string $data; |
| 23 |
/** |
| 24 |
* QRDataModeAbstract constructor. |
| 25 |
* |
| 26 |
* @throws \chillerlan\QRCode\Data\QRCodeDataException |
| 27 |
*/ |
| 28 |
public function __construct(string $data) |
| 29 |
{ |
| 30 |
$data = $this::convertEncoding($data); |
| 31 |
if (!$this::validateString($data)) { |
| 32 |
throw new QRCodeDataException('invalid data'); |
| 33 |
} |
| 34 |
$this->data = $data; |
| 35 |
} |
| 36 |
/** |
| 37 |
* returns the character count of the $data string |
| 38 |
*/ |
| 39 |
protected function getCharCount() : int |
| 40 |
{ |
| 41 |
return \strlen($this->data); |
| 42 |
} |
| 43 |
/** |
| 44 |
* @inheritDoc |
| 45 |
*/ |
| 46 |
public static function convertEncoding(string $string) : string |
| 47 |
{ |
| 48 |
return $string; |
| 49 |
} |
| 50 |
/** |
| 51 |
* shortcut |
| 52 |
*/ |
| 53 |
protected static function getLengthBits(int $versionNumber) : int |
| 54 |
{ |
| 55 |
return Mode::getLengthBitsForVersion(static::DATAMODE, $versionNumber); |
| 56 |
} |
| 57 |
} |
| 58 |
|