Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
88.89% |
16 / 18 |
|
71.43% |
5 / 7 |
CRAP | |
0.00% |
0 / 1 |
| AbstractObject | |
88.89% |
16 / 18 |
|
71.43% |
5 / 7 |
9.11 | |
0.00% |
0 / 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 | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| isImported | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| getDictionaryReferences | |
88.89% |
8 / 9 |
|
0.00% |
0 / 1 |
3.01 | |||
| __toString | n/a |
0 / 0 |
n/a |
0 / 0 |
0 | |||||
| 1 | <?php |
| 2 | /** |
| 3 | * Pop PHP Framework (https://www.popphp.org/) |
| 4 | * |
| 5 | * @link https://github.com/popphp/popphp-framework |
| 6 | * @author Nick Sagona, III <dev@noladev.com> |
| 7 | * @copyright Copyright (c) 2009-2025 NOLA Interactive, LLC. |
| 8 | * @license https://www.popphp.org/license New BSD License |
| 9 | */ |
| 10 | |
| 11 | /** |
| 12 | * @namespace |
| 13 | */ |
| 14 | namespace Pop\Pdf\Build\PdfObject; |
| 15 | |
| 16 | /** |
| 17 | * Pdf abstract object class |
| 18 | * |
| 19 | * @category Pop |
| 20 | * @package Pop\Pdf |
| 21 | * @author Nick Sagona, III <dev@noladev.com> |
| 22 | * @copyright Copyright (c) 2009-2025 NOLA Interactive, LLC. |
| 23 | * @license https://www.popphp.org/license New BSD License |
| 24 | * @version 5.2.2 |
| 25 | */ |
| 26 | abstract class AbstractObject implements ObjectInterface |
| 27 | { |
| 28 | |
| 29 | /** |
| 30 | * PDF object index |
| 31 | * @var ?int |
| 32 | */ |
| 33 | protected ?int $index = null; |
| 34 | |
| 35 | /** |
| 36 | * PDF object data |
| 37 | * @var ?string |
| 38 | */ |
| 39 | protected ?string $data = null; |
| 40 | |
| 41 | /** |
| 42 | * Imported flag |
| 43 | * @var bool |
| 44 | */ |
| 45 | protected bool $isImported = false; |
| 46 | |
| 47 | /** |
| 48 | * Set the object index |
| 49 | * |
| 50 | * @param int $i |
| 51 | * @return AbstractObject |
| 52 | */ |
| 53 | public function setIndex(int $i): AbstractObject |
| 54 | { |
| 55 | $this->index = $i; |
| 56 | return $this; |
| 57 | } |
| 58 | |
| 59 | /** |
| 60 | * Set the object data |
| 61 | * |
| 62 | * @param string $data |
| 63 | * @return AbstractObject |
| 64 | */ |
| 65 | public function setData(string $data): AbstractObject |
| 66 | { |
| 67 | $this->data = $data; |
| 68 | return $this; |
| 69 | } |
| 70 | |
| 71 | /** |
| 72 | * Set whether the object is imported |
| 73 | * |
| 74 | * @param bool $imported |
| 75 | * @return AbstractObject |
| 76 | */ |
| 77 | public function setImported(bool $imported) |
| 78 | { |
| 79 | $this->isImported = $imported; |
| 80 | return $this; |
| 81 | } |
| 82 | |
| 83 | /** |
| 84 | * Get the object index |
| 85 | * |
| 86 | * @return ?int |
| 87 | */ |
| 88 | public function getIndex(): ?int |
| 89 | { |
| 90 | return $this->index; |
| 91 | } |
| 92 | |
| 93 | /** |
| 94 | * Get the object stream |
| 95 | * |
| 96 | * @return ?string |
| 97 | */ |
| 98 | public function getData(): ?string |
| 99 | { |
| 100 | return $this->data; |
| 101 | } |
| 102 | |
| 103 | /** |
| 104 | * Determine if the object is imported |
| 105 | * |
| 106 | * @return bool |
| 107 | */ |
| 108 | public function isImported(): bool |
| 109 | { |
| 110 | return $this->isImported; |
| 111 | } |
| 112 | |
| 113 | /** |
| 114 | * Get the integer references within a dictionary stream |
| 115 | * |
| 116 | * @param string $dictionary |
| 117 | * @return array |
| 118 | */ |
| 119 | public function getDictionaryReferences(string $dictionary): array |
| 120 | { |
| 121 | $dictionary = trim($dictionary); |
| 122 | |
| 123 | if (str_starts_with($dictionary, '[')) { |
| 124 | $dictionary = substr($dictionary, 0, strpos($dictionary, ']')); |
| 125 | $dictionary = trim(str_replace(['[', '0 R', '1 R', ' '], ['', '|', '|', ''], $dictionary)); |
| 126 | if (str_ends_with($dictionary, '|')) { |
| 127 | $dictionary = substr($dictionary, 0, -1); |
| 128 | } |
| 129 | $references = explode('|', $dictionary); |
| 130 | } else { |
| 131 | $references = [substr($dictionary, 0, strpos($dictionary, ' '))]; |
| 132 | } |
| 133 | |
| 134 | return $references; |
| 135 | } |
| 136 | |
| 137 | /** |
| 138 | * Method to print the object |
| 139 | * |
| 140 | * @return string |
| 141 | */ |
| 142 | abstract public function __toString(): string; |
| 143 | |
| 144 | } |