Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
15 / 15 |
|
100.00% |
7 / 7 |
CRAP | |
100.00% |
1 / 1 |
| Form | |
100.00% |
15 / 15 |
|
100.00% |
7 / 7 |
8 | |
100.00% |
1 / 1 |
| __construct | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| setName | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 | |||
| getName | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| addFieldIndex | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 | |||
| getFieldIndices | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| getNumberOfFields | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| getStream | |
100.00% |
7 / 7 |
|
100.00% |
1 / 1 |
2 | |||
| 1 | <?php |
| 2 | declare(strict_types=1); |
| 3 | /** |
| 4 | * Pop PHP Framework (https://www.popphp.org/) |
| 5 | * |
| 6 | * @link https://github.com/popphp/popphp-framework |
| 7 | * @author Nick Sagona, III <nick@popphp.org> |
| 8 | * @copyright Copyright (c) 2009-2026 Nick Sagona, III |
| 9 | * @license https://www.popphp.org/license New BSD License |
| 10 | */ |
| 11 | |
| 12 | /** |
| 13 | * @namespace |
| 14 | */ |
| 15 | namespace Pop\Pdf\Document; |
| 16 | |
| 17 | /** |
| 18 | * Pdf form class |
| 19 | * |
| 20 | * @category Pop |
| 21 | * @package Pop\Pdf |
| 22 | * @author Nick Sagona, III <nick@popphp.org> |
| 23 | * @copyright Copyright (c) 2009-2026 Nick Sagona, III |
| 24 | * @license https://www.popphp.org/license New BSD License |
| 25 | * @version 6.0.0 |
| 26 | */ |
| 27 | class Form |
| 28 | { |
| 29 | |
| 30 | /** |
| 31 | * Form name |
| 32 | * @var ?string |
| 33 | */ |
| 34 | protected ?string $name = null; |
| 35 | |
| 36 | /** |
| 37 | * Form field indices |
| 38 | * @var array |
| 39 | */ |
| 40 | protected array $fields = []; |
| 41 | |
| 42 | /** |
| 43 | * Constructor |
| 44 | * |
| 45 | * Instantiate a PDF form object. |
| 46 | * |
| 47 | * @param string $name |
| 48 | */ |
| 49 | public function __construct(string $name) |
| 50 | { |
| 51 | $this->setName($name); |
| 52 | } |
| 53 | |
| 54 | /** |
| 55 | * Set form name |
| 56 | * |
| 57 | * @param string $name |
| 58 | * @return Form |
| 59 | */ |
| 60 | public function setName(string $name): Form |
| 61 | { |
| 62 | $this->name = $name; |
| 63 | return $this; |
| 64 | } |
| 65 | |
| 66 | /** |
| 67 | * Get the form name |
| 68 | * |
| 69 | * @return ?string |
| 70 | */ |
| 71 | public function getName(): ?string |
| 72 | { |
| 73 | return $this->name; |
| 74 | } |
| 75 | |
| 76 | /** |
| 77 | * Add field index |
| 78 | * |
| 79 | * @param int $i |
| 80 | * @return Form |
| 81 | */ |
| 82 | public function addFieldIndex(int $i): Form |
| 83 | { |
| 84 | $this->fields[] = $i; |
| 85 | return $this; |
| 86 | } |
| 87 | |
| 88 | /** |
| 89 | * Get field indices |
| 90 | * |
| 91 | * @return array |
| 92 | */ |
| 93 | public function getFieldIndices(): array |
| 94 | { |
| 95 | return $this->fields; |
| 96 | } |
| 97 | |
| 98 | /** |
| 99 | * Get number of fields |
| 100 | * |
| 101 | * @return int |
| 102 | */ |
| 103 | public function getNumberOfFields(): int |
| 104 | { |
| 105 | return count($this->fields); |
| 106 | } |
| 107 | |
| 108 | /** |
| 109 | * Get the form stream |
| 110 | * |
| 111 | * @param int $i |
| 112 | * @return string |
| 113 | */ |
| 114 | public function getStream(int $i): string |
| 115 | { |
| 116 | // Return the stream |
| 117 | $stream = "{$i} 0 obj\n<</Fields["; |
| 118 | |
| 119 | $fields = ''; |
| 120 | foreach ($this->fields as $value) { |
| 121 | $fields .= $value . ' 0 R '; |
| 122 | } |
| 123 | $fields = substr($fields, 0, -1); |
| 124 | |
| 125 | $stream .= $fields . "]>>\nendobj\n\n"; |
| 126 | |
| 127 | return $stream; |
| 128 | } |
| 129 | |
| 130 | } |