|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* Class QRString |
|
4
|
|
|
* |
|
5
|
|
|
* @created 05.12.2015 |
|
6
|
|
|
* @author Smiley <[email protected]> |
|
7
|
|
|
* @copyright 2015 Smiley |
|
8
|
|
|
* @license MIT |
|
9
|
|
|
* |
|
10
|
|
|
* @noinspection PhpUnusedParameterInspection |
|
11
|
|
|
* @noinspection PhpComposerExtensionStubsInspection |
|
12
|
|
|
*/ |
|
13
|
|
|
|
|
14
|
|
|
namespace chillerlan\QRCode\Output; |
|
15
|
|
|
|
|
16
|
|
|
use chillerlan\QRCode\QRCode; |
|
17
|
|
|
|
|
18
|
|
|
use function implode, is_string, json_encode; |
|
19
|
|
|
|
|
20
|
|
|
/** |
|
21
|
|
|
* Converts the matrix data into string types |
|
22
|
|
|
*/ |
|
23
|
|
|
class QRString extends QROutputAbstract{ |
|
24
|
|
|
|
|
25
|
|
|
protected string $defaultMode = QRCode::OUTPUT_STRING_TEXT; |
|
26
|
|
|
|
|
27
|
|
|
/** |
|
28
|
|
|
* @inheritDoc |
|
29
|
|
|
*/ |
|
30
|
|
|
protected function moduleValueIsValid($value):bool{ |
|
31
|
|
|
return is_string($value); |
|
32
|
|
|
} |
|
33
|
|
|
|
|
34
|
|
|
/** |
|
35
|
|
|
* @inheritDoc |
|
36
|
|
|
*/ |
|
37
|
|
|
protected function getModuleValue($value):string{ |
|
38
|
|
|
return $value; |
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
|
|
/** |
|
42
|
|
|
* @inheritDoc |
|
43
|
|
|
*/ |
|
44
|
|
|
protected function getDefaultModuleValue(bool $isDark):string{ |
|
45
|
|
|
return $isDark ? $this->options->textDark : $this->options->textLight; |
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
|
|
/** |
|
49
|
|
|
* @inheritDoc |
|
50
|
|
|
*/ |
|
51
|
|
|
public function dump(string $file = null):string{ |
|
52
|
|
|
$file ??= $this->options->cachefile; |
|
53
|
|
|
|
|
54
|
|
|
switch($this->options->outputType){ |
|
55
|
|
|
case QRCode::OUTPUT_STRING_TEXT: |
|
56
|
|
|
$data = $this->text(); |
|
57
|
|
|
break; |
|
58
|
|
|
case QRCode::OUTPUT_STRING_JSON: |
|
59
|
|
|
default: |
|
60
|
|
|
$data = $this->json(); |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
|
|
if($file !== null){ |
|
64
|
|
|
$this->saveToFile($data, $file); |
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
|
|
return $data; |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
|
/** |
|
71
|
|
|
* string output |
|
72
|
|
|
*/ |
|
73
|
|
|
protected function text():string{ |
|
74
|
|
|
$str = []; |
|
75
|
|
|
|
|
76
|
|
|
foreach($this->matrix->matrix() as $row){ |
|
77
|
|
|
$r = []; |
|
78
|
|
|
|
|
79
|
|
|
foreach($row as $M_TYPE){ |
|
80
|
|
|
$r[] = $this->moduleValues[$M_TYPE]; |
|
81
|
|
|
} |
|
82
|
|
|
|
|
83
|
|
|
$str[] = implode('', $r); |
|
84
|
|
|
} |
|
85
|
|
|
|
|
86
|
|
|
return implode($this->options->eol, $str); |
|
|
|
|
|
|
87
|
|
|
} |
|
88
|
|
|
|
|
89
|
|
|
/** |
|
90
|
|
|
* JSON output |
|
91
|
|
|
*/ |
|
92
|
|
|
protected function json():string{ |
|
93
|
|
|
return json_encode($this->matrix->matrix()); |
|
94
|
|
|
} |
|
95
|
|
|
|
|
96
|
|
|
} |
|
97
|
|
|
|