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\Common\{EccLevel, MaskPattern, Version}; |
15
|
|
|
use function property_exists; |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* Encapsulates the result of decoding a matrix of bits. This typically |
19
|
|
|
* applies to 2D barcode formats. For now it contains the raw bytes obtained, |
20
|
|
|
* as well as a String interpretation of those bytes, if applicable. |
21
|
|
|
* |
22
|
|
|
* @property int[] $rawBytes |
23
|
|
|
* @property string $data |
24
|
|
|
* @property \chillerlan\QRCode\Common\Version $version |
25
|
|
|
* @property \chillerlan\QRCode\Common\EccLevel $eccLevel |
26
|
|
|
* @property \chillerlan\QRCode\Common\MaskPattern $maskPattern |
27
|
|
|
* @property int $structuredAppendParity |
28
|
|
|
* @property int $structuredAppendSequence |
29
|
|
|
*/ |
30
|
|
|
final class DecoderResult{ |
31
|
|
|
|
32
|
|
|
protected array $rawBytes; |
33
|
|
|
protected string $data; |
34
|
|
|
protected Version $version; |
35
|
|
|
protected EccLevel $eccLevel; |
36
|
|
|
protected MaskPattern $maskPattern; |
37
|
|
|
protected int $structuredAppendParity = -1; |
38
|
|
|
protected int $structuredAppendSequence = -1; |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* DecoderResult constructor. |
42
|
|
|
*/ |
43
|
|
|
public function __construct(iterable $properties = null){ |
44
|
|
|
|
45
|
|
|
if(!empty($properties)){ |
46
|
|
|
|
47
|
|
|
foreach($properties as $property => $value){ |
48
|
|
|
|
49
|
|
|
if(!property_exists($this, $property)){ |
50
|
|
|
continue; |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
$this->{$property} = $value; |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* @return mixed|null |
62
|
|
|
*/ |
63
|
|
|
public function __get(string $property){ |
64
|
|
|
|
65
|
|
|
if(property_exists($this, $property)){ |
66
|
|
|
return $this->{$property}; |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
return null; |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
/** |
73
|
|
|
* |
74
|
|
|
*/ |
75
|
|
|
public function __toString():string{ |
76
|
|
|
return $this->data; |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
/** |
80
|
|
|
* |
81
|
|
|
*/ |
82
|
|
|
public function hasStructuredAppend():bool{ |
83
|
|
|
return $this->structuredAppendParity >= 0 && $this->structuredAppendSequence >= 0; |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
} |
87
|
|
|
|