Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
9 / 9 |
|
100.00% |
2 / 2 |
CRAP | |
100.00% |
1 / 1 |
| EmbeddedFile | |
100.00% |
9 / 9 |
|
100.00% |
2 / 2 |
5 | |
100.00% |
1 / 1 |
| __construct | |
100.00% |
3 / 3 |
|
100.00% |
1 / 1 |
2 | |||
| toPdf | |
100.00% |
6 / 6 |
|
100.00% |
1 / 1 |
3 | |||
| 1 | <?php |
| 2 | |
| 3 | declare(strict_types=1); |
| 4 | |
| 5 | namespace Phpdftk\Pdf\Core\FileSpec; |
| 6 | |
| 7 | use Phpdftk\Pdf\Core\PdfDictionary; |
| 8 | use Phpdftk\Pdf\Core\PdfName; |
| 9 | use Phpdftk\Pdf\Core\PdfStream; |
| 10 | use Phpdftk\Pdf\Core\PdfVersion; |
| 11 | use Phpdftk\Pdf\Core\RequiresPdfVersion; |
| 12 | |
| 13 | /** |
| 14 | * Embedded file stream (/Type /EmbeddedFile) — ISO 32000-2 §7.11.4. |
| 15 | * |
| 16 | * Carries the bytes of a file embedded in the PDF. The /Subtype holds the |
| 17 | * MIME type (e.g. `application/xml`) with solidus characters escaped as |
| 18 | * `#2F` per the /Name escaping rules. |
| 19 | */ |
| 20 | #[RequiresPdfVersion(PdfVersion::V1_3)] |
| 21 | class EmbeddedFile extends PdfStream |
| 22 | { |
| 23 | public const PDF_TYPE = 'EmbeddedFile'; |
| 24 | |
| 25 | public ?PdfName $subtype = null; // /Subtype (MIME) |
| 26 | public ?EmbeddedFileParams $params = null; // /Params |
| 27 | |
| 28 | public function __construct(string $data = '', ?string $mimeType = null) |
| 29 | { |
| 30 | parent::__construct(new PdfDictionary(), $data); |
| 31 | if ($mimeType !== null) { |
| 32 | $this->subtype = new PdfName($mimeType); |
| 33 | } |
| 34 | } |
| 35 | |
| 36 | public function toPdf(): string |
| 37 | { |
| 38 | $this->dictionary->set('Type', new PdfName(self::PDF_TYPE)); |
| 39 | if ($this->subtype !== null) { |
| 40 | $this->dictionary->set('Subtype', $this->subtype); |
| 41 | } |
| 42 | if ($this->params !== null) { |
| 43 | $this->dictionary->set('Params', $this->params); |
| 44 | } |
| 45 | |
| 46 | return parent::toPdf(); |
| 47 | } |
| 48 | } |