1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Class DecoderResult |
4
|
|
|
* |
5
|
|
|
* @created 17.01.2021 |
6
|
|
|
* @author ZXing Authors |
7
|
|
|
* @author Smiley <[email protected]> |
8
|
|
|
* @copyright 2021 Smiley |
9
|
|
|
* @license Apache-2.0 |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace chillerlan\QRCode\Decoder; |
13
|
|
|
|
14
|
|
|
use chillerlan\QRCode\Data\QRMatrix; |
15
|
|
|
use chillerlan\QRCode\Common\{BitBuffer, EccLevel, MaskPattern, Version}; |
16
|
|
|
use function property_exists; |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* Encapsulates the result of decoding a matrix of bits. This typically |
20
|
|
|
* applies to 2D barcode formats. For now, it contains the raw bytes obtained |
21
|
|
|
* as well as a String interpretation of those bytes, if applicable. |
22
|
|
|
* |
23
|
|
|
* @property \chillerlan\QRCode\Common\BitBuffer $rawBytes |
24
|
|
|
* @property string $data |
25
|
|
|
* @property \chillerlan\QRCode\Common\Version $version |
26
|
|
|
* @property \chillerlan\QRCode\Common\EccLevel $eccLevel |
27
|
|
|
* @property \chillerlan\QRCode\Common\MaskPattern $maskPattern |
28
|
|
|
* @property int $structuredAppendParity |
29
|
|
|
* @property int $structuredAppendSequence |
30
|
|
|
*/ |
31
|
|
|
final class DecoderResult{ |
32
|
|
|
|
33
|
|
|
private BitBuffer $rawBytes; |
34
|
|
|
private Version $version; |
35
|
|
|
private EccLevel $eccLevel; |
36
|
|
|
private MaskPattern $maskPattern; |
37
|
|
|
private string $data = ''; |
38
|
|
|
private int $structuredAppendParity = -1; |
39
|
|
|
private int $structuredAppendSequence = -1; |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* DecoderResult constructor. |
43
|
|
|
*/ |
44
|
|
|
public function __construct(iterable $properties = null){ |
45
|
|
|
|
46
|
|
|
if(!empty($properties)){ |
47
|
|
|
|
48
|
|
|
foreach($properties as $property => $value){ |
49
|
|
|
|
50
|
|
|
if(!property_exists($this, $property)){ |
51
|
|
|
continue; |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
$this->{$property} = $value; |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
/** |
62
|
|
|
* @return mixed|null |
63
|
|
|
*/ |
64
|
|
|
public function __get(string $property){ |
65
|
|
|
|
66
|
|
|
if(property_exists($this, $property)){ |
67
|
|
|
return $this->{$property}; |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
return null; |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
/** |
74
|
|
|
* |
75
|
|
|
*/ |
76
|
|
|
public function __toString():string{ |
77
|
|
|
return $this->data; |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
/** |
81
|
|
|
* |
82
|
|
|
*/ |
83
|
|
|
public function hasStructuredAppend():bool{ |
84
|
|
|
return $this->structuredAppendParity >= 0 && $this->structuredAppendSequence >= 0; |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
/** |
88
|
|
|
* Returns a QRMatrix instance with thesettings and data of the reader result |
89
|
|
|
*/ |
90
|
|
|
public function getQRMatrix():QRMatrix{ |
91
|
|
|
return (new QRMatrix($this->version, $this->eccLevel)) |
92
|
|
|
->initFunctionalPatterns() |
93
|
|
|
->writeCodewords($this->rawBytes) |
94
|
|
|
->setFormatInfo($this->maskPattern) |
95
|
|
|
->mask($this->maskPattern) |
96
|
|
|
; |
97
|
|
|
} |
98
|
|
|
|
99
|
|
|
} |
100
|
|
|
|