Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
84.62% covered (warning)
84.62%
11 / 13
50.00% covered (danger)
50.00%
1 / 2
CRAP
0.00% covered (danger)
0.00%
0 / 1
DPart
84.62% covered (warning)
84.62%
11 / 13
50.00% covered (danger)
50.00%
1 / 2
6.13
0.00% covered (danger)
0.00%
0 / 1
 __construct
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 toPdf
83.33% covered (warning)
83.33%
10 / 12
0.00% covered (danger)
0.00%
0 / 1
5.12
1<?php
2
3declare(strict_types=1);
4
5namespace Phpdftk\Pdf\Core\Document;
6
7use Phpdftk\Pdf\Core\PdfArray;
8use Phpdftk\Pdf\Core\PdfDictionary;
9use Phpdftk\Pdf\Core\PdfName;
10use Phpdftk\Pdf\Core\PdfObject;
11use Phpdftk\Pdf\Core\PdfReference;
12use Phpdftk\Pdf\Core\PdfVersion;
13use Phpdftk\Pdf\Core\RequiresPdfVersion;
14
15/**
16 * Document part node (/Type /DPart) — ISO 32000-2 §14.12.
17 *
18 * A node in the document-part tree. Internal nodes carry a /DParts
19 * array of child node references; leaves carry a /Start page reference
20 * (and optionally /End) plus their record metadata.
21 */
22#[RequiresPdfVersion(PdfVersion::V2_0)]
23class DPart extends PdfObject
24{
25    public const PDF_TYPE = 'DPart';
26
27    public PdfReference $parent;                // /Parent - required
28    public ?PdfArray $dParts = null;             // /DParts - child nodes
29    public ?PdfReference $start = null;          // /Start
30    public ?PdfReference $end = null;            // /End
31    public ?PdfDictionary $dpm = null;           // /DPM - document-part metadata
32
33    public function __construct(PdfReference $parent)
34    {
35        $this->parent = $parent;
36    }
37
38    public function toPdf(): string
39    {
40        $dict = new PdfDictionary();
41        $dict->set('Type', new PdfName(self::PDF_TYPE));
42        $dict->set('Parent', $this->parent);
43        if ($this->dParts !== null) {
44            $dict->set('DParts', $this->dParts);
45        }
46        if ($this->start !== null) {
47            $dict->set('Start', $this->start);
48        }
49        if ($this->end !== null) {
50            $dict->set('End', $this->end);
51        }
52        if ($this->dpm !== null) {
53            $dict->set('DPM', $this->dpm);
54        }
55        return $dict->toPdf();
56    }
57}