1 | <?php |
||
22 | class AlphaNum extends QRDataAbstract{ |
||
23 | |||
24 | protected int $datamode = QRCode::DATA_ALPHANUM; |
||
|
|||
25 | |||
26 | protected array $lengthBits = [9, 11, 13]; |
||
27 | |||
28 | /** |
||
29 | * @inheritdoc |
||
30 | */ |
||
31 | protected function write(string $data):void{ |
||
32 | |||
33 | for($i = 0; $i + 1 < $this->strlen; $i += 2){ |
||
34 | $this->bitBuffer->put($this->getCharCode($data[$i]) * 45 + $this->getCharCode($data[$i + 1]), 11); |
||
35 | } |
||
36 | |||
37 | if($i < $this->strlen){ |
||
38 | $this->bitBuffer->put($this->getCharCode($data[$i]), 6); |
||
39 | } |
||
40 | |||
41 | } |
||
42 | |||
43 | /** |
||
44 | * @throws \chillerlan\QRCode\Data\QRCodeDataException |
||
45 | */ |
||
46 | protected function getCharCode(string $chr):int{ |
||
47 | $i = array_search($chr, $this::ALPHANUM_CHAR_MAP); |
||
48 | |||
49 | if($i !== false){ |
||
50 | return $i; |
||
51 | } |
||
52 | |||
53 | throw new QRCodeDataException(sprintf('illegal char: "%s" [%d]', $chr, ord($chr))); |
||
54 | } |
||
55 | |||
56 | } |
||
57 |