Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
88.89% covered (success)
88.89%
16 / 18
71.43% covered (success)
71.43%
5 / 7
CRAP
0.00% covered (danger)
0.00%
0 / 1
AbstractObject
88.89% covered (success)
88.89%
16 / 18
71.43% covered (success)
71.43%
5 / 7
9.11
0.00% covered (danger)
0.00%
0 / 1
 setIndex
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
1
 setData
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
1
 setImported
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
1
 getIndex
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getData
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 isImported
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getDictionaryReferences
88.89% covered (success)
88.89%
8 / 9
0.00% covered (danger)
0.00%
0 / 1
3.01
 __toString
n/a
0 / 0
n/a
0 / 0
0
1<?php
2/**
3 * Pop PHP Framework (http://www.popphp.org/)
4 *
5 * @link       https://github.com/popphp/popphp-framework
6 * @author     Nick Sagona, III <dev@nolainteractive.com>
7 * @copyright  Copyright (c) 2009-2023 NOLA Interactive, LLC. (http://www.nolainteractive.com)
8 * @license    http://www.popphp.org/license     New BSD License
9 */
10
11/**
12 * @namespace
13 */
14namespace 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@nolainteractive.com>
22 * @copyright  Copyright (c) 2009-2023 NOLA Interactive, LLC. (http://www.nolainteractive.com)
23 * @license    http://www.popphp.org/license     New BSD License
24 * @version    4.2.0
25 */
26abstract class AbstractObject implements ObjectInterface
27{
28
29    /**
30     * PDF object index
31     * @var int
32     */
33    protected $index = null;
34
35    /**
36     * PDF object data
37     * @var string
38     */
39    protected $data = null;
40
41    /**
42     * Imported flag
43     * @var string
44     */
45    protected $isImported = false;
46
47    /**
48     * Set the object index
49     *
50     * @param  int $i
51     * @return AbstractObject
52     */
53    public function setIndex($i)
54    {
55        $this->index = (int)$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($data)
66    {
67        $this->data = $data;
68        return $this;
69    }
70
71    /**
72     * Set whether the object is imported
73     *
74     * @param  boolean $imported
75     * @return AbstractObject
76     */
77    public function setImported($imported)
78    {
79        $this->isImported = (bool)$imported;
80        return $this;
81    }
82
83    /**
84     * Get the object index
85     *
86     * @return int
87     */
88    public function getIndex()
89    {
90        return $this->index;
91    }
92
93    /**
94     * Get the object stream
95     *
96     * @return string
97     */
98    public function getData()
99    {
100        return $this->data;
101    }
102
103    /**
104     * Determine if the object is imported
105     *
106     * @return boolean
107     */
108    public function isImported()
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($dictionary)
120    {
121        $dictionary = trim($dictionary);
122
123        if (substr($dictionary, 0, 1) == '[') {
124            $dictionary = substr($dictionary, 0, strpos($dictionary, ']'));
125            $dictionary = trim(str_replace(['[', '0 R', '1 R', ' '], ['', '|', '|', ''], $dictionary));
126            if (substr($dictionary, -1) == '|') {
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();
143
144}