1 | <?php |
||
32 | class QRCode{ |
||
33 | |||
34 | /** |
||
35 | * API constants |
||
36 | */ |
||
37 | public const OUTPUT_MARKUP_HTML = 'html'; |
||
38 | public const OUTPUT_MARKUP_SVG = 'svg'; |
||
39 | public const OUTPUT_IMAGE_PNG = 'png'; |
||
40 | public const OUTPUT_IMAGE_JPG = 'jpg'; |
||
41 | public const OUTPUT_IMAGE_GIF = 'gif'; |
||
42 | public const OUTPUT_STRING_JSON = 'json'; |
||
43 | public const OUTPUT_STRING_TEXT = 'text'; |
||
44 | public const OUTPUT_IMAGICK = 'imagick'; |
||
45 | public const OUTPUT_FPDF = 'fpdf'; |
||
46 | public const OUTPUT_CUSTOM = 'custom'; |
||
47 | |||
48 | public const VERSION_AUTO = -1; |
||
49 | public const MASK_PATTERN_AUTO = -1; |
||
50 | |||
51 | public const ECC_L = 0b01; // 7%. |
||
52 | public const ECC_M = 0b00; // 15%. |
||
53 | public const ECC_Q = 0b11; // 25%. |
||
54 | public const ECC_H = 0b10; // 30%. |
||
55 | |||
56 | public const DATA_NUMBER = 0b0001; |
||
57 | public const DATA_ALPHANUM = 0b0010; |
||
58 | public const DATA_BYTE = 0b0100; |
||
59 | public const DATA_KANJI = 0b1000; |
||
60 | |||
61 | public const ECC_MODES = [ |
||
62 | self::ECC_L => 0, |
||
63 | self::ECC_M => 1, |
||
64 | self::ECC_Q => 2, |
||
65 | self::ECC_H => 3, |
||
66 | ]; |
||
67 | |||
68 | public const DATA_MODES = [ |
||
69 | self::DATA_NUMBER => 0, |
||
70 | self::DATA_ALPHANUM => 1, |
||
71 | self::DATA_BYTE => 2, |
||
72 | self::DATA_KANJI => 3, |
||
73 | ]; |
||
74 | |||
75 | public const OUTPUT_MODES = [ |
||
76 | QRMarkup::class => [ |
||
77 | self::OUTPUT_MARKUP_SVG, |
||
78 | self::OUTPUT_MARKUP_HTML, |
||
79 | ], |
||
80 | QRImage::class => [ |
||
81 | self::OUTPUT_IMAGE_PNG, |
||
82 | self::OUTPUT_IMAGE_GIF, |
||
83 | self::OUTPUT_IMAGE_JPG, |
||
84 | ], |
||
85 | QRString::class => [ |
||
86 | self::OUTPUT_STRING_JSON, |
||
87 | self::OUTPUT_STRING_TEXT, |
||
88 | ], |
||
89 | QRImagick::class => [ |
||
90 | self::OUTPUT_IMAGICK, |
||
91 | ], |
||
92 | QRFpdf::class => [ |
||
93 | self::OUTPUT_FPDF |
||
94 | ] |
||
95 | ]; |
||
96 | |||
97 | /** |
||
98 | * @var \chillerlan\QRCode\QROptions|\chillerlan\Settings\SettingsContainerInterface |
||
99 | */ |
||
100 | protected $options; |
||
101 | |||
102 | /** |
||
103 | * @var \chillerlan\QRCode\Data\QRDataInterface |
||
104 | */ |
||
105 | protected $dataInterface; |
||
106 | |||
107 | /** |
||
108 | * QRCode constructor. |
||
109 | * |
||
110 | * @param \chillerlan\Settings\SettingsContainerInterface|null $options |
||
111 | */ |
||
112 | public function __construct(SettingsContainerInterface $options = null){ |
||
115 | |||
116 | /** |
||
117 | * Renders a QR Code for the given $data and QROptions |
||
118 | * |
||
119 | * @param string $data |
||
120 | * @param string|null $file |
||
121 | * |
||
122 | * @return mixed |
||
123 | */ |
||
124 | public function render(string $data, string $file = null){ |
||
127 | |||
128 | /** |
||
129 | * Returns a QRMatrix object for the given $data and current QROptions |
||
130 | * |
||
131 | * @param string $data |
||
132 | * |
||
133 | * @return \chillerlan\QRCode\Data\QRMatrix |
||
134 | * @throws \chillerlan\QRCode\Data\QRCodeDataException |
||
135 | */ |
||
136 | public function getMatrix(string $data):QRMatrix{ |
||
156 | |||
157 | /** |
||
158 | * shoves a QRMatrix through the MaskPatternTester to find the lowest penalty mask pattern |
||
159 | * |
||
160 | * @see \chillerlan\QRCode\Data\MaskPatternTester |
||
161 | * |
||
162 | * @return int |
||
163 | */ |
||
164 | protected function getBestMaskPattern():int{ |
||
175 | |||
176 | /** |
||
177 | * returns a fresh QRDataInterface for the given $data |
||
178 | * |
||
179 | * @param string $data |
||
180 | * |
||
181 | * @return \chillerlan\QRCode\Data\QRDataInterface |
||
182 | * @throws \chillerlan\QRCode\Data\QRCodeDataException |
||
183 | */ |
||
184 | public function initDataInterface(string $data):QRDataInterface{ |
||
207 | |||
208 | /** |
||
209 | * returns a fresh (built-in) QROutputInterface |
||
210 | * |
||
211 | * @param string $data |
||
212 | * |
||
213 | * @return \chillerlan\QRCode\Output\QROutputInterface |
||
214 | * @throws \chillerlan\QRCode\Output\QRCodeOutputException |
||
215 | */ |
||
216 | protected function initOutputInterface(string $data):QROutputInterface{ |
||
232 | |||
233 | /** |
||
234 | * checks if a string qualifies as numeric |
||
235 | * |
||
236 | * @param string $string |
||
237 | * |
||
238 | * @return bool |
||
239 | */ |
||
240 | public function isNumber(string $string):bool{ |
||
243 | |||
244 | /** |
||
245 | * checks if a string qualifies as alphanumeric |
||
246 | * |
||
247 | * @param string $string |
||
248 | * |
||
249 | * @return bool |
||
250 | */ |
||
251 | public function isAlphaNum(string $string):bool{ |
||
254 | |||
255 | /** |
||
256 | * checks is a given $string matches the characters of a given $charmap, returns false on the first invalid occurence. |
||
257 | * |
||
258 | * @param string $string |
||
259 | * @param array $charmap |
||
260 | * |
||
261 | * @return bool |
||
262 | */ |
||
263 | protected function checkString(string $string, array $charmap):bool{ |
||
274 | |||
275 | /** |
||
276 | * checks if a string qualifies as Kanji |
||
277 | * |
||
278 | * @param string $string |
||
279 | * |
||
280 | * @return bool |
||
281 | */ |
||
282 | public function isKanji(string $string):bool{ |
||
298 | |||
299 | /** |
||
300 | * a dummy |
||
301 | * |
||
302 | * @param $data |
||
303 | * |
||
304 | * @return bool |
||
305 | */ |
||
306 | protected function isByte(string $data):bool{ |
||
309 | |||
310 | } |
||
311 |