Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
10 / 10 |
|
100.00% |
3 / 3 |
CRAP | |
100.00% |
1 / 1 |
| SignatureField | |
100.00% |
10 / 10 |
|
100.00% |
3 / 3 |
6 | |
100.00% |
1 / 1 |
| __construct | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| setSignatureValue | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| toPdf | |
100.00% |
8 / 8 |
|
100.00% |
1 / 1 |
4 | |||
| 1 | <?php |
| 2 | |
| 3 | declare(strict_types=1); |
| 4 | |
| 5 | namespace Phpdftk\Pdf\Core\Interactive\Form; |
| 6 | |
| 7 | use Phpdftk\Pdf\Core\Interactive\Signature\SignatureValue; |
| 8 | use Phpdftk\Pdf\Core\PdfDictionary; |
| 9 | use Phpdftk\Pdf\Core\PdfName; |
| 10 | use Phpdftk\Pdf\Core\PdfNumber; |
| 11 | use Phpdftk\Pdf\Core\PdfReference; |
| 12 | use Phpdftk\Pdf\Core\PdfVersion; |
| 13 | use Phpdftk\Pdf\Core\RequiresPdfVersion; |
| 14 | |
| 15 | /** |
| 16 | * Signature field (/FT /Sig) — ISO 32000-2 §12.7.5.5. |
| 17 | * |
| 18 | * The field's /V may be a typed {@see SignatureValue}, an inline |
| 19 | * PdfDictionary, or a reference to a SignatureValue indirect object. |
| 20 | * /Lock and /SV provide an optional lock dict and seed-value dict. |
| 21 | */ |
| 22 | #[RequiresPdfVersion(PdfVersion::V1_3)] |
| 23 | class SignatureField extends Field |
| 24 | { |
| 25 | public ?int $sigFlags = null; // /SigFlags (carried on AcroForm) |
| 26 | public SigFieldLock|PdfDictionary|PdfReference|null $lock = null; // /Lock |
| 27 | public SeedValueDictionary|PdfDictionary|PdfReference|null $sv = null; // /SV seed-value |
| 28 | |
| 29 | public function __construct() |
| 30 | { |
| 31 | $this->ft = new PdfName('Sig'); |
| 32 | } |
| 33 | |
| 34 | /** |
| 35 | * Attach a SignatureValue directly as the field value. |
| 36 | */ |
| 37 | public function setSignatureValue(SignatureValue|PdfReference $value): void |
| 38 | { |
| 39 | $this->v = $value; |
| 40 | } |
| 41 | |
| 42 | public function toPdf(): string |
| 43 | { |
| 44 | $dict = $this->buildFieldDictionary(); |
| 45 | |
| 46 | if ($this->sigFlags !== null) { |
| 47 | $dict->set('SigFlags', new PdfNumber($this->sigFlags)); |
| 48 | } |
| 49 | if ($this->lock !== null) { |
| 50 | $dict->set('Lock', $this->lock); |
| 51 | } |
| 52 | if ($this->sv !== null) { |
| 53 | $dict->set('SV', $this->sv); |
| 54 | } |
| 55 | |
| 56 | return $dict->toPdf(); |
| 57 | } |
| 58 | } |