Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
75.00% |
3 / 4 |
|
66.67% |
2 / 3 |
CRAP | |
0.00% |
0 / 1 |
| PdfBlockRegistry | |
66.67% |
2 / 3 |
|
66.67% |
2 / 3 |
3.33 | |
0.00% |
0 / 1 |
| getAll | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| has | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| get | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| 1 | <?php |
| 2 | |
| 3 | declare(strict_types=1); |
| 4 | |
| 5 | /** @license For full copyright and license information, please see the LICENSE.md file. */ |
| 6 | |
| 7 | namespace App\Modules\Pdf\Domain\Service; |
| 8 | |
| 9 | defined('AMMONLY_APP') || exit('Direct script access is forbidden.'); |
| 10 | |
| 11 | /** |
| 12 | * Domain Registry for PDF Template Block Definitions. |
| 13 | * |
| 14 | * Exclusively defines block types with the "pdf_" prefix tailored for printable A4 media. |
| 15 | * |
| 16 | * @package App\Modules\Pdf\Domain\Service |
| 17 | */ |
| 18 | final class PdfBlockRegistry |
| 19 | { |
| 20 | /** @var array<string, array<string, mixed>> */ |
| 21 | private static array $definitions = [ |
| 22 | 'pdf_brand_header' => [ |
| 23 | 'type' => 'pdf_brand_header', |
| 24 | 'label' => 'Nagłówek dokumentu & Logo', |
| 25 | 'icon' => 'bi bi-building', |
| 26 | 'category' => 'header', |
| 27 | 'description' => 'Document title, organization logo, and reference number', |
| 28 | 'defaultProps' => [ |
| 29 | 'title' => 'DOKUMENT OFICJALNY', |
| 30 | 'subtitle' => '{{ record.prefix_number|default(record.name) }}', |
| 31 | ], |
| 32 | ], |
| 33 | 'pdf_page_header' => [ |
| 34 | 'type' => 'pdf_page_header', |
| 35 | 'label' => 'Bieżący nagłówek strony (Header)', |
| 36 | 'icon' => 'bi bi-arrow-up-square', |
| 37 | 'category' => 'paged', |
| 38 | 'description' => 'Running top header printed on every page', |
| 39 | 'defaultProps' => [ |
| 40 | 'left_text' => '{{ app_name }}', |
| 41 | 'right_text' => 'Data: {{ "now"|date("Y-m-d") }}', |
| 42 | ], |
| 43 | ], |
| 44 | 'pdf_page_footer' => [ |
| 45 | 'type' => 'pdf_page_footer', |
| 46 | 'label' => 'Stopka stron z numeracją (Footer)', |
| 47 | 'icon' => 'bi bi-arrow-down-square', |
| 48 | 'category' => 'paged', |
| 49 | 'description' => 'Running bottom footer with page counter (Strona {PAGENO} z {nbpg})', |
| 50 | 'defaultProps' => [ |
| 51 | 'center_text' => 'Strona {PAGENO} z {nbpg}', |
| 52 | ], |
| 53 | ], |
| 54 | 'pdf_line_items_table' => [ |
| 55 | 'type' => 'pdf_line_items_table', |
| 56 | 'label' => 'Tabela pozycji / towarów', |
| 57 | 'icon' => 'bi bi-table', |
| 58 | 'category' => 'tables', |
| 59 | 'description' => 'Multi-column repeating table with running header', |
| 60 | 'defaultProps' => [ |
| 61 | 'relation' => 'line_items', |
| 62 | ], |
| 63 | ], |
| 64 | 'pdf_financial_summary' => [ |
| 65 | 'type' => 'pdf_financial_summary', |
| 66 | 'label' => 'Podsumowanie finansowe (VAT/Netto/Brutto)', |
| 67 | 'icon' => 'bi bi-cash-stack', |
| 68 | 'category' => 'financial', |
| 69 | 'description' => 'Total amounts box formatted in document currency', |
| 70 | 'defaultProps' => [ |
| 71 | 'show_tax_table' => true, |
| 72 | ], |
| 73 | ], |
| 74 | 'pdf_key_value_grid' => [ |
| 75 | 'type' => 'pdf_key_value_grid', |
| 76 | 'label' => 'Siatka danych kontrahentów', |
| 77 | 'icon' => 'bi bi-grid-3x2', |
| 78 | 'category' => 'layout', |
| 79 | 'description' => 'Two-box grid with seller and buyer details', |
| 80 | 'defaultProps' => [], |
| 81 | ], |
| 82 | 'pdf_text_block' => [ |
| 83 | 'type' => 'pdf_text_block', |
| 84 | 'label' => 'Blok tekstu drukowanego', |
| 85 | 'icon' => 'bi bi-textarea-t', |
| 86 | 'category' => 'content', |
| 87 | 'description' => 'Formatted typography block with pt font sizing', |
| 88 | 'defaultProps' => [ |
| 89 | 'content' => '{{ record.description }}', |
| 90 | 'font_size' => '10pt', |
| 91 | ], |
| 92 | ], |
| 93 | 'pdf_sign_box' => [ |
| 94 | 'type' => 'pdf_sign_box', |
| 95 | 'label' => 'Miejsce na podpis i pieczęć', |
| 96 | 'icon' => 'bi bi-pen', |
| 97 | 'category' => 'signatures', |
| 98 | 'description' => 'Signatures section for issuer and receiver', |
| 99 | 'defaultProps' => [ |
| 100 | 'left_label' => 'Osoba upoważniona do wystawienia', |
| 101 | 'right_label' => 'Osoba upoważniona do odbioru', |
| 102 | ], |
| 103 | ], |
| 104 | 'pdf_qr_code' => [ |
| 105 | 'type' => 'pdf_qr_code', |
| 106 | 'label' => 'Kod QR weryfikacji', |
| 107 | 'icon' => 'bi bi-qr-code', |
| 108 | 'category' => 'media', |
| 109 | 'description' => 'Scannable QR code linking to verification URL', |
| 110 | 'defaultProps' => [ |
| 111 | 'data_source' => 'record_url', |
| 112 | 'size' => 120, |
| 113 | ], |
| 114 | ], |
| 115 | 'pdf_page_break' => [ |
| 116 | 'type' => 'pdf_page_break', |
| 117 | 'label' => 'Podział strony (Page Break)', |
| 118 | 'icon' => 'bi bi-file-break', |
| 119 | 'category' => 'paged', |
| 120 | 'description' => 'Forces subsequent content onto a new A4 printed sheet', |
| 121 | 'defaultProps' => [], |
| 122 | ], |
| 123 | ]; |
| 124 | |
| 125 | /** |
| 126 | * Returns all registered PDF block definitions. |
| 127 | * |
| 128 | * @return array<string, array<string, mixed>> |
| 129 | */ |
| 130 | public static function getAll(): array |
| 131 | { |
| 132 | return self::$definitions; |
| 133 | } |
| 134 | |
| 135 | /** |
| 136 | * Checks if a block type is a valid PDF block. |
| 137 | * |
| 138 | * @param string $type Block type identifier. |
| 139 | * @return bool |
| 140 | */ |
| 141 | public static function has(string $type): bool |
| 142 | { |
| 143 | return isset(self::$definitions[$type]); |
| 144 | } |
| 145 | |
| 146 | /** |
| 147 | * Obtains definition for specific block type. |
| 148 | * |
| 149 | * @param string $type Block type. |
| 150 | * @return array<string, mixed>|null |
| 151 | */ |
| 152 | public static function get(string $type): ?array |
| 153 | { |
| 154 | return self::$definitions[$type] ?? null; |
| 155 | } |
| 156 | } |