Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
7 / 7 |
|
100.00% |
3 / 3 |
CRAP | |
100.00% |
1 / 1 |
| ClassMap | |
100.00% |
7 / 7 |
|
100.00% |
3 / 3 |
4 | |
100.00% |
1 / 1 |
| set | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 | |||
| toDictionary | |
100.00% |
4 / 4 |
|
100.00% |
1 / 1 |
2 | |||
| toPdf | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| 1 | <?php |
| 2 | |
| 3 | declare(strict_types=1); |
| 4 | |
| 5 | namespace Phpdftk\Pdf\Core\Document; |
| 6 | |
| 7 | use Phpdftk\Pdf\Core\PdfArray; |
| 8 | use Phpdftk\Pdf\Core\PdfDictionary; |
| 9 | use Phpdftk\Pdf\Core\PdfReference; |
| 10 | use Phpdftk\Pdf\Core\PdfVersion; |
| 11 | use Phpdftk\Pdf\Core\RequiresPdfVersion; |
| 12 | use Phpdftk\Pdf\Core\Serializable; |
| 13 | |
| 14 | /** |
| 15 | * ClassMap dictionary — ISO 32000-2 §14.7.4. |
| 16 | * |
| 17 | * Maps class names to structure-attribute objects (or arrays of them). |
| 18 | * Lives inline on `StructTreeRoot::$classMap`. |
| 19 | */ |
| 20 | #[RequiresPdfVersion(PdfVersion::V1_3)] |
| 21 | class ClassMap implements Serializable |
| 22 | { |
| 23 | /** @var array<string, StructAttribute|PdfReference|PdfArray> */ |
| 24 | public array $entries = []; |
| 25 | |
| 26 | public function set(string $className, StructAttribute|PdfReference|PdfArray $value): self |
| 27 | { |
| 28 | $this->entries[$className] = $value; |
| 29 | return $this; |
| 30 | } |
| 31 | |
| 32 | public function toDictionary(): PdfDictionary |
| 33 | { |
| 34 | $dict = new PdfDictionary(); |
| 35 | foreach ($this->entries as $name => $value) { |
| 36 | $dict->set($name, $value); |
| 37 | } |
| 38 | return $dict; |
| 39 | } |
| 40 | |
| 41 | public function toPdf(): string |
| 42 | { |
| 43 | return $this->toDictionary()->toPdf(); |
| 44 | } |
| 45 | } |