-
-
Notifications
You must be signed in to change notification settings - Fork 307
/
Copy pathcustom_output.php
84 lines (60 loc) · 1.87 KB
/
custom_output.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
<?php
/**
* custom output example
*
* @created 24.12.2017
* @author Smiley <[email protected]>
* @copyright 2017 Smiley
* @license MIT
*
* @noinspection PhpIllegalPsrClassPathInspection
*/
declare(strict_types=1);
use chillerlan\QRCode\{QRCode, QROptions};
use chillerlan\QRCode\Output\QROutputAbstract;
require_once __DIR__.'/../vendor/autoload.php';
/*
* Class definition
*/
class MyCustomOutput extends QROutputAbstract{
public static function moduleValueIsValid(mixed $value):bool{
// TODO: Implement moduleValueIsValid() method. (interface)
return false;
}
protected function prepareModuleValue(mixed $value):mixed{
// TODO: Implement prepareModuleValue() method. (abstract)
return null;
}
protected function getDefaultModuleValue(bool $isDark):mixed{
// TODO: Implement getDefaultModuleValue() method. (abstract)
return null;
}
public function dump(string|null $file = null):string{
$output = '';
for($y = 0; $y < $this->moduleCount; $y++){
for($x = 0; $x < $this->moduleCount; $x++){
$output .= (int)$this->matrix->check($x, $y);
}
$output .= $this->options->eol;
}
return $output;
}
}
/*
* Runtime
*/
$options = new QROptions;
$options->version = 5;
$options->eccLevel = 'L';
$data = 'https://www.youtube.com/watch?v=dQw4w9WgXcQ';
// invoke the QROutputInterface manually
// please note that an QROutputInterface invoked this way might become unusable after calling dump().
// the clean way would be to extend the QRCode class to ensure a new QROutputInterface instance on each call to render().
$qrcode = new QRCode($options);
$qrcode->addByteSegment($data);
$qrOutputInterface = new MyCustomOutput($options, $qrcode->getQRMatrix());
var_dump($qrOutputInterface->dump());
// or just via the options
$options->outputInterface = MyCustomOutput::class;
var_dump((new QRCode($options))->render($data));
exit;