|
1 | 1 | <?php
|
| 2 | +declare(strict_types=1); |
| 3 | + |
2 | 4 | /**
|
3 |
| - * Pdf generator abstract class |
4 |
| - * |
5 | 5 | * @section LICENSE
|
6 | 6 | * This file is created by vianetz <[email protected]>.
|
7 | 7 | * The code is distributed under the GPL license.
|
|
19 | 19 |
|
20 | 20 | namespace Vianetz\Pdf\Model\Generator;
|
21 | 21 |
|
| 22 | +use Vianetz\Pdf\Model\Config; |
22 | 23 | use Vianetz\Pdf\Model\GeneratorInterface;
|
23 | 24 |
|
24 | 25 | /**
|
25 |
| - * Class Vianetz_Pdf_Model_Abstract |
26 |
| - * |
27 | 26 | * A note on PDF merging:
|
28 | 27 | * - each generator instance generates the PDF of one source
|
29 | 28 | * - the merge() method in this class takes care of the merging of the single files
|
30 | 29 | * This is necessary because the documents may contain source dependent information in header/footer like invoice id,
|
31 | 30 | * addresses, etc. that cannot be determined correctly if you put all in one file.
|
32 | 31 | *
|
33 | 32 | * A note on naming convention:
|
34 |
| - * - "document" means the PDF representation of a source that serves as input for the generator |
| 33 | + * - "document" is the PDF contents of a source that serves as input for the generator (e.g. html string) |
35 | 34 | */
|
36 | 35 | abstract class AbstractGenerator implements GeneratorInterface
|
37 | 36 | {
|
38 |
| - /** @var string */ |
39 |
| - const DEBUG_FILE_NAME = 'vianetz_pdf_generator_debug.html'; |
| 37 | + public const DEBUG_FILE_NAME = 'vianetz_pdf_generator_debug.html'; |
| 38 | + protected Config $config; |
40 | 39 |
|
41 |
| - /** @var \Vianetz\Pdf\Model\Config $config */ |
42 |
| - protected $config; |
43 |
| - |
44 |
| - /** |
45 |
| - * Constructor initializes configuration values. |
46 |
| - * |
47 |
| - * @param \Vianetz\Pdf\Model\Config|null $config |
48 |
| - */ |
49 |
| - public function __construct(\Vianetz\Pdf\Model\Config $config = null) |
| 40 | + public function __construct(?Config $config = null) |
50 | 41 | {
|
51 |
| - if (empty($config) === true) { |
52 |
| - $config = new \Vianetz\Pdf\Model\Config(); |
53 |
| - } |
54 |
| - |
55 |
| - $this->config = $config; |
56 |
| - |
57 |
| - $this->initGenerator(); |
| 42 | + $this->config = $config ?? new Config(); |
58 | 43 | }
|
59 | 44 |
|
60 |
| - /** |
61 |
| - * Initialize the generator instance. |
62 |
| - * |
63 |
| - * @return \Vianetz\Pdf\Model\Generator\AbstractGenerator |
64 |
| - */ |
65 |
| - protected function initGenerator() |
| 45 | + protected function replaceSpecialChars(string $htmlContents): string |
66 | 46 | {
|
67 |
| - // By default we do nothing.. |
68 |
| - return $this; |
69 |
| - } |
70 |
| - |
71 |
| - /** |
72 |
| - * Replace special characters for DomPDF library. |
73 |
| - * |
74 |
| - * @param string $htmlContents |
75 |
| - * |
76 |
| - * @return string |
77 |
| - */ |
78 |
| - protected function replaceSpecialChars($htmlContents) |
79 |
| - { |
80 |
| - // Nothing to do at the moment. |
81 |
| - |
82 | 47 | return $htmlContents;
|
83 | 48 | }
|
84 | 49 |
|
85 | 50 | protected function writeDebugFile(string $fileContents): bool
|
86 | 51 | {
|
87 |
| - if ($this->config->isDebugMode() === false) { |
| 52 | + if (! $this->config->isDebugMode()) { |
88 | 53 | return false;
|
89 | 54 | }
|
90 | 55 |
|
|
0 commit comments