-
-
Notifications
You must be signed in to change notification settings - Fork 330
Expand file tree
/
Copy pathQRPbm.php
More file actions
50 lines (42 loc) · 1.23 KB
/
QRPbm.php
File metadata and controls
50 lines (42 loc) · 1.23 KB
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
<?php
/**
* Class QRPbm
*
* @created 11.12.2025
* @author wgevaert
* @copyright 2025 wgevaert
* @license MIT
*/
declare(strict_types=1);
namespace chillerlan\QRCode\Output;
use chillerlan\QRCode\Output\QROutputAbstract;
class QRPbm extends QROutputAbstract {
private const LIGHT_DARK = [ '0', '1' ];
protected function prepareModuleValue( mixed $value ): mixed {
return $value;
}
protected function getDefaultModuleValue( bool $isDark ): mixed {
return $isDark ? self::LIGHT_DARK[1] : self::LIGHT_DARK[0];
}
public static function moduleValueIsValid( mixed $value): bool {
return is_string( $value ) && in_array( $value, self::LIGHT_DARK, true );
}
public function dump( string|null $file = null ): mixed {
$size = $this->matrix->getSize();
$qrString = "P1\n"
.$size.' '.$size."\n";
foreach($this->matrix->getBooleanMatrix() as $row) {
foreach ($row as $isDark) {
$qrString .= $this->getDefaultModuleValue( $isDark );
}
$qrString .= "\n";
}
if ( is_string($file) ) {
$writeResult = file_put_contents($file,$qrString);
if ( $writeResult === false ) {
throw new QRCodeOutputException('Cannot write data to cache file: '.$file);
}
}
return $qrString;
}
}