1 | <?php |
||
30 | class QRCode{ |
||
31 | |||
32 | /** |
||
33 | * API constants |
||
34 | */ |
||
35 | public const OUTPUT_MARKUP_HTML = 'html'; |
||
36 | public const OUTPUT_MARKUP_SVG = 'svg'; |
||
37 | public const OUTPUT_IMAGE_PNG = 'png'; |
||
38 | public const OUTPUT_IMAGE_JPG = 'jpg'; |
||
39 | public const OUTPUT_IMAGE_GIF = 'gif'; |
||
40 | public const OUTPUT_STRING_JSON = 'json'; |
||
41 | public const OUTPUT_STRING_TEXT = 'text'; |
||
42 | public const OUTPUT_IMAGICK = 'imagick'; |
||
43 | public const OUTPUT_CUSTOM = 'custom'; |
||
44 | |||
45 | public const VERSION_AUTO = -1; |
||
46 | public const MASK_PATTERN_AUTO = -1; |
||
47 | |||
48 | public const ECC_L = 0b01; // 7%. |
||
49 | public const ECC_M = 0b00; // 15%. |
||
50 | public const ECC_Q = 0b11; // 25%. |
||
51 | public const ECC_H = 0b10; // 30%. |
||
52 | |||
53 | public const DATA_NUMBER = 0b0001; |
||
54 | public const DATA_ALPHANUM = 0b0010; |
||
55 | public const DATA_BYTE = 0b0100; |
||
56 | public const DATA_KANJI = 0b1000; |
||
57 | |||
58 | public const ECC_MODES = [ |
||
59 | self::ECC_L => 0, |
||
60 | self::ECC_M => 1, |
||
61 | self::ECC_Q => 2, |
||
62 | self::ECC_H => 3, |
||
63 | ]; |
||
64 | |||
65 | public const DATA_MODES = [ |
||
66 | self::DATA_NUMBER => 0, |
||
67 | self::DATA_ALPHANUM => 1, |
||
68 | self::DATA_BYTE => 2, |
||
69 | self::DATA_KANJI => 3, |
||
70 | ]; |
||
71 | |||
72 | public const OUTPUT_MODES = [ |
||
73 | QRMarkup::class => [ |
||
74 | self::OUTPUT_MARKUP_SVG, |
||
75 | self::OUTPUT_MARKUP_HTML, |
||
76 | ], |
||
77 | QRImage::class => [ |
||
78 | self::OUTPUT_IMAGE_PNG, |
||
79 | self::OUTPUT_IMAGE_GIF, |
||
80 | self::OUTPUT_IMAGE_JPG, |
||
81 | ], |
||
82 | QRString::class => [ |
||
83 | self::OUTPUT_STRING_JSON, |
||
84 | self::OUTPUT_STRING_TEXT, |
||
85 | ], |
||
86 | QRImagick::class => [ |
||
87 | self::OUTPUT_IMAGICK, |
||
88 | ], |
||
89 | ]; |
||
90 | |||
91 | /** |
||
92 | * @var \chillerlan\QRCode\QROptions |
||
93 | */ |
||
94 | protected $options; |
||
95 | |||
96 | /** |
||
97 | * @var \chillerlan\QRCode\Data\QRDataInterface |
||
98 | */ |
||
99 | protected $dataInterface; |
||
100 | |||
101 | /** |
||
102 | * @see http://php.net/manual/function.mb-internal-encoding.php |
||
103 | * @var string |
||
104 | */ |
||
105 | protected $mbCurrentEncoding; |
||
106 | |||
107 | /** |
||
108 | * QRCode constructor. |
||
109 | * |
||
110 | * @param \chillerlan\Settings\SettingsContainerInterface|null $options |
||
111 | */ |
||
112 | public function __construct(SettingsContainerInterface $options = null){ |
||
120 | |||
121 | /** |
||
122 | * @return void |
||
123 | */ |
||
124 | public function __destruct(){ |
||
128 | |||
129 | /** |
||
130 | * Renders a QR Code for the given $data and QROptions |
||
131 | * |
||
132 | * @param string $data |
||
133 | * @param string|null $file |
||
134 | * |
||
135 | * @return mixed |
||
136 | */ |
||
137 | public function render(string $data, string $file = null){ |
||
140 | |||
141 | /** |
||
142 | * Returns a QRMatrix object for the given $data and current QROptions |
||
143 | * |
||
144 | * @param string $data |
||
145 | * |
||
146 | * @return \chillerlan\QRCode\Data\QRMatrix |
||
147 | * @throws \chillerlan\QRCode\Data\QRCodeDataException |
||
148 | */ |
||
149 | public function getMatrix(string $data):QRMatrix{ |
||
169 | |||
170 | /** |
||
171 | * shoves a QRMatrix through the MaskPatternTester to find the lowest penalty mask pattern |
||
172 | * |
||
173 | * @see \chillerlan\QRCode\Data\MaskPatternTester |
||
174 | * |
||
175 | * @return int |
||
176 | */ |
||
177 | protected function getBestMaskPattern():int{ |
||
188 | |||
189 | /** |
||
190 | * returns a fresh QRDataInterface for the given $data |
||
191 | * |
||
192 | * @param string $data |
||
193 | * |
||
194 | * @return \chillerlan\QRCode\Data\QRDataInterface |
||
195 | * @throws \chillerlan\QRCode\Data\QRCodeDataException |
||
196 | */ |
||
197 | public function initDataInterface(string $data):QRDataInterface{ |
||
210 | |||
211 | /** |
||
212 | * returns a fresh (built-in) QROutputInterface |
||
213 | * |
||
214 | * @param string $data |
||
215 | * |
||
216 | * @return \chillerlan\QRCode\Output\QROutputInterface |
||
217 | * @throws \chillerlan\QRCode\Output\QRCodeOutputException |
||
218 | */ |
||
219 | protected function initOutputInterface(string $data):QROutputInterface{ |
||
235 | |||
236 | /** |
||
237 | * checks if a string qualifies as numeric |
||
238 | * |
||
239 | * @param string $string |
||
240 | * |
||
241 | * @return bool |
||
242 | */ |
||
243 | public function isNumber(string $string):bool{ |
||
246 | |||
247 | /** |
||
248 | * checks if a string qualifies as alphanumeric |
||
249 | * |
||
250 | * @param string $string |
||
251 | * |
||
252 | * @return bool |
||
253 | */ |
||
254 | public function isAlphaNum(string $string):bool{ |
||
257 | |||
258 | /** |
||
259 | * checks is a given $string matches the characters of a given $charmap, returns false on the first invalid occurence. |
||
260 | * |
||
261 | * @param string $string |
||
262 | * @param array $charmap |
||
263 | * |
||
264 | * @return bool |
||
265 | */ |
||
266 | protected function checkString(string $string, array $charmap):bool{ |
||
277 | |||
278 | /** |
||
279 | * checks if a string qualifies as Kanji |
||
280 | * |
||
281 | * @param string $string |
||
282 | * |
||
283 | * @return bool |
||
284 | */ |
||
285 | public function isKanji(string $string):bool{ |
||
301 | |||
302 | /** |
||
303 | * a dummy |
||
304 | * |
||
305 | * @param $data |
||
306 | * |
||
307 | * @return bool |
||
308 | */ |
||
309 | protected function isByte(string $data):bool{ |
||
312 | |||
313 | } |
||
314 |
Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a given class or a super-class is assigned to a property that is type hinted more strictly.
Either this assignment is in error or an instanceof check should be added for that assignment.