Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
18 / 18 |
|
100.00% |
7 / 7 |
CRAP | |
100.00% |
1 / 1 |
| AbstractObject | |
100.00% |
18 / 18 |
|
100.00% |
7 / 7 |
9 | |
100.00% |
1 / 1 |
| setIndex | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 | |||
| setData | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 | |||
| setImported | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 | |||
| getIndex | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| getData | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| isImported | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| getDictionaryReferences | |
100.00% |
9 / 9 |
|
100.00% |
1 / 1 |
3 | |||
| __toString | n/a |
0 / 0 |
n/a |
0 / 0 |
0 | |||||
| 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\Build\PdfObject; |
| 16 | |
| 17 | /** |
| 18 | * Pdf abstract object 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 | abstract class AbstractObject implements ObjectInterface |
| 28 | { |
| 29 | |
| 30 | /** |
| 31 | * PDF object index |
| 32 | * @var ?int |
| 33 | */ |
| 34 | protected ?int $index = null; |
| 35 | |
| 36 | /** |
| 37 | * PDF object data |
| 38 | * @var ?string |
| 39 | */ |
| 40 | protected ?string $data = null; |
| 41 | |
| 42 | /** |
| 43 | * Imported flag |
| 44 | * @var bool |
| 45 | */ |
| 46 | protected bool $isImported = false; |
| 47 | |
| 48 | /** |
| 49 | * Set the object index |
| 50 | * |
| 51 | * @param int $i |
| 52 | * @return AbstractObject |
| 53 | */ |
| 54 | public function setIndex(int $i): AbstractObject |
| 55 | { |
| 56 | $this->index = $i; |
| 57 | return $this; |
| 58 | } |
| 59 | |
| 60 | /** |
| 61 | * Set the object data |
| 62 | * |
| 63 | * @param string $data |
| 64 | * @return AbstractObject |
| 65 | */ |
| 66 | public function setData(string $data): AbstractObject |
| 67 | { |
| 68 | $this->data = $data; |
| 69 | return $this; |
| 70 | } |
| 71 | |
| 72 | /** |
| 73 | * Set whether the object is imported |
| 74 | * |
| 75 | * @param bool $imported |
| 76 | * @return AbstractObject |
| 77 | */ |
| 78 | public function setImported(bool $imported) |
| 79 | { |
| 80 | $this->isImported = $imported; |
| 81 | return $this; |
| 82 | } |
| 83 | |
| 84 | /** |
| 85 | * Get the object index |
| 86 | * |
| 87 | * @return ?int |
| 88 | */ |
| 89 | public function getIndex(): ?int |
| 90 | { |
| 91 | return $this->index; |
| 92 | } |
| 93 | |
| 94 | /** |
| 95 | * Get the object stream |
| 96 | * |
| 97 | * @return ?string |
| 98 | */ |
| 99 | public function getData(): ?string |
| 100 | { |
| 101 | return $this->data; |
| 102 | } |
| 103 | |
| 104 | /** |
| 105 | * Determine if the object is imported |
| 106 | * |
| 107 | * @return bool |
| 108 | */ |
| 109 | public function isImported(): bool |
| 110 | { |
| 111 | return $this->isImported; |
| 112 | } |
| 113 | |
| 114 | /** |
| 115 | * Get the integer references within a dictionary stream |
| 116 | * |
| 117 | * @param string $dictionary |
| 118 | * @return array |
| 119 | */ |
| 120 | public function getDictionaryReferences(string $dictionary): array |
| 121 | { |
| 122 | $dictionary = trim($dictionary); |
| 123 | |
| 124 | if (str_starts_with($dictionary, '[')) { |
| 125 | $dictionary = substr($dictionary, 0, strpos($dictionary, ']')); |
| 126 | $dictionary = trim(str_replace(['[', '0 R', '1 R', ' '], ['', '|', '|', ''], $dictionary)); |
| 127 | if (str_ends_with($dictionary, '|')) { |
| 128 | $dictionary = substr($dictionary, 0, -1); |
| 129 | } |
| 130 | $references = explode('|', $dictionary); |
| 131 | } else { |
| 132 | $references = [substr($dictionary, 0, strpos($dictionary, ' '))]; |
| 133 | } |
| 134 | |
| 135 | return $references; |
| 136 | } |
| 137 | |
| 138 | /** |
| 139 | * Method to print the object |
| 140 | * |
| 141 | * @return string |
| 142 | */ |
| 143 | abstract public function __toString(): string; |
| 144 | |
| 145 | } |