1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace chillerlan\QRCode\Output; |
6
|
|
|
|
7
|
|
|
use chillerlan\QRCode\Data\QRMatrix; |
|
|
|
|
8
|
|
|
use chillerlan\Settings\SettingsContainerInterface; |
9
|
|
|
|
10
|
|
|
/** |
11
|
|
|
* QRFpdf output module (requires fpdf) |
12
|
|
|
* |
13
|
|
|
* @see https://github.com/Setasign/FPDF |
14
|
|
|
* @see http://www.fpdf.org/ |
15
|
|
|
*/ |
16
|
|
|
class QRFpdf extends QROutputAbstract |
17
|
|
|
{ |
18
|
|
|
public function __construct(SettingsContainerInterface $options, QRMatrix $matrix) |
19
|
|
|
{ |
20
|
|
|
parent::__construct($options, $matrix); |
21
|
|
|
|
22
|
|
|
if (!\class_exists(\FPDF::class)) { |
23
|
|
|
throw new \BadMethodCallException( |
24
|
|
|
'The QRFpdf output requires FPDF as dependency but the class "\FPDF" couldn\'t be found.' |
25
|
|
|
); |
26
|
|
|
} |
27
|
|
|
} |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* @inheritDoc |
31
|
|
|
*/ |
32
|
|
|
protected function setModuleValues(): void |
33
|
|
|
{ |
34
|
|
|
foreach ($this::DEFAULT_MODULE_VALUES as $M_TYPE => $defaultValue) { |
35
|
|
|
$v = $this->options->moduleValues[$M_TYPE] ?? null; |
36
|
|
|
|
37
|
|
|
if (!\is_array($v) || \count($v) < 3) { |
38
|
|
|
$this->moduleValues[$M_TYPE] = $defaultValue |
39
|
|
|
? [0, 0, 0] |
40
|
|
|
: [255, 255, 255]; |
41
|
|
|
} else { |
42
|
|
|
$this->moduleValues[$M_TYPE] = \array_values($v); |
43
|
|
|
} |
44
|
|
|
} |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* @inheritDoc |
49
|
|
|
*/ |
50
|
|
|
public function dump(string $file = null): string |
51
|
|
|
{ |
52
|
|
|
$file ??= $this->options->cachefile; |
53
|
|
|
|
54
|
|
|
$fpdf = new \FPDF('P', 'pt', [$this->length, $this->length]); |
55
|
|
|
$fpdf->AddPage(); |
56
|
|
|
|
57
|
|
|
$prevColor = null; |
58
|
|
|
foreach ($this->matrix->matrix() as $y => $row) { |
59
|
|
|
foreach ($row as $x => $M_TYPE) { |
60
|
|
|
/** |
61
|
|
|
* @var int $M_TYPE |
62
|
|
|
*/ |
63
|
|
|
$color = $this->moduleValues[$M_TYPE]; |
64
|
|
|
if ($prevColor === null || $prevColor !== $color) { |
65
|
|
|
$fpdf->SetFillColor(...$color); |
|
|
|
|
66
|
|
|
$prevColor = $color; |
67
|
|
|
} |
68
|
|
|
$fpdf->Rect($x * $this->scale, $y * $this->scale, 1 * $this->scale, 1 * $this->scale, 'F'); |
69
|
|
|
} |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
$pdfData = $fpdf->Output('S'); |
73
|
|
|
|
74
|
|
|
if ($file !== null) { |
75
|
|
|
$this->saveToFile($pdfData, $file); |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
return $pdfData; |
79
|
|
|
} |
80
|
|
|
} |
81
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths