Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
7 / 7 |
|
100.00% |
2 / 2 |
CRAP | |
100.00% |
1 / 1 |
| RequirementHandler | |
100.00% |
7 / 7 |
|
100.00% |
2 / 2 |
3 | |
100.00% |
1 / 1 |
| __construct | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| toPdf | |
100.00% |
6 / 6 |
|
100.00% |
1 / 1 |
2 | |||
| 1 | <?php |
| 2 | |
| 3 | declare(strict_types=1); |
| 4 | |
| 5 | namespace Phpdftk\Pdf\Core\Document; |
| 6 | |
| 7 | use Phpdftk\Pdf\Core\PdfDictionary; |
| 8 | use Phpdftk\Pdf\Core\PdfName; |
| 9 | use Phpdftk\Pdf\Core\PdfObject; |
| 10 | use Phpdftk\Pdf\Core\PdfString; |
| 11 | use Phpdftk\Pdf\Core\PdfVersion; |
| 12 | use Phpdftk\Pdf\Core\RequiresPdfVersion; |
| 13 | |
| 14 | /** |
| 15 | * Requirement handler dictionary (/Type /ReqHandler) — |
| 16 | * ISO 32000-2 §12.10, Table 254. |
| 17 | */ |
| 18 | #[RequiresPdfVersion(PdfVersion::V1_7)] |
| 19 | class RequirementHandler extends PdfObject |
| 20 | { |
| 21 | public const PDF_TYPE = 'ReqHandler'; |
| 22 | |
| 23 | public PdfName $s; // /S - handler type (JS, NoOp, …) |
| 24 | public ?PdfString $script = null; // /Script |
| 25 | |
| 26 | public function __construct(string $subtype) |
| 27 | { |
| 28 | $this->s = new PdfName($subtype); |
| 29 | } |
| 30 | |
| 31 | public function toPdf(): string |
| 32 | { |
| 33 | $dict = new PdfDictionary(); |
| 34 | $dict->set('Type', new PdfName(self::PDF_TYPE)); |
| 35 | $dict->set('S', $this->s); |
| 36 | if ($this->script !== null) { |
| 37 | $dict->set('Script', $this->script); |
| 38 | } |
| 39 | return $dict->toPdf(); |
| 40 | } |
| 41 | } |