7 * This source file is subject to the new BSD license that is bundled
8 * with this package in the file LICENSE.txt.
9 * It is also available through the world-wide-web at this URL:
10 * http://framework.zend.com/license/new-bsd
11 * If you did not receive a copy of the license and are unable to
12 * obtain it through the world-wide-web, please send an email
13 * to license@zend.com so we can send you a copy immediately.
17 * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
18 * @license http://framework.zend.com/license/new-bsd New BSD License
19 * @version $Id: Reference.php 17533 2009-08-10 19:06:27Z alexander $
23 /** Zend_Pdf_Element */
24 require_once 'Zend/Pdf/Element.php';
26 /** Zend_Pdf_Element_Reference_Context */
27 require_once 'Zend/Pdf/Element/Reference/Context.php';
29 /** Zend_Pdf_Element_Reference_Table */
30 require_once 'Zend/Pdf/Element/Reference/Table.php';
32 /** Zend_Pdf_ElementFactory */
33 require_once 'Zend/Pdf/ElementFactory.php';
37 * PDF file 'reference' element implementation
41 * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
42 * @license http://framework.zend.com/license/new-bsd New BSD License
44 class Zend_Pdf_Element_Reference
extends Zend_Pdf_Element
48 * The reference to the object
55 * Object number within PDF file
71 * @var Zend_Pdf_Element_Reference_Context
77 * Reference to the factory.
79 * It's the same as referenced object factory, but we save it here to avoid
80 * unnecessary dereferencing, whech can produce cascade dereferencing and parsing.
81 * The same for duplication of getFactory() function. It can be processed by __call()
82 * method, but we catch it here.
84 * @var Zend_Pdf_ElementFactory
91 * @param integer $objNum
92 * @param integer $genNum
93 * @param Zend_Pdf_Element_Reference_Context $context
94 * @param Zend_Pdf_ElementFactory $factory
95 * @throws Zend_Pdf_Exception
97 public function __construct($objNum, $genNum = 0, Zend_Pdf_Element_Reference_Context
$context, Zend_Pdf_ElementFactory
$factory)
99 if ( !(is_integer($objNum) && $objNum > 0) ) {
100 throw new Zend_Pdf_Exception('Object number must be positive integer');
102 if ( !(is_integer($genNum) && $genNum >= 0) ) {
103 throw new Zend_Pdf_Exception('Generation number must be non-negative integer');
106 $this->_objNum
= $objNum;
107 $this->_genNum
= $genNum;
109 $this->_context
= $context;
110 $this->_factory
= $factory;
114 * Check, that object is generated by specified factory
116 * @return Zend_Pdf_ElementFactory
118 public function getFactory()
120 return $this->_factory
;
125 * Return type of the element.
129 public function getType()
131 if ($this->_ref
=== null) {
132 $this->_dereference();
135 return $this->_ref
->getType();
140 * Return reference to the object
142 * @param Zend_Pdf_Factory $factory
145 public function toString($factory = null)
147 if ($factory === null) {
150 $shift = $factory->getEnumerationShift($this->_factory
);
153 return $this->_objNum +
$shift . ' ' . $this->_genNum
. ' R';
159 * Take inderect object, take $value member of this object (must be Zend_Pdf_Element),
160 * take reference to the $value member of this object and assign it to
161 * $value member of current PDF Reference object
164 * @throws Zend_Pdf_Exception
166 private function _dereference()
168 if (($obj = $this->_factory
->fetchObject($this->_objNum
. ' ' . $this->_genNum
)) === null) {
169 $obj = $this->_context
->getParser()->getObject(
170 $this->_context
->getRefTable()->getOffset($this->_objNum
. ' ' . $this->_genNum
. ' R'),
175 if ($obj === null ) {
176 $this->_ref
= new Zend_Pdf_Element_Null();
180 if ($obj->toString() != $this->_objNum
. ' ' . $this->_genNum
. ' R') {
181 throw new Zend_Pdf_Exception('Incorrect reference to the object');
188 * Mark object as modified, to include it into new PDF file segment.
190 public function touch()
192 if ($this->_ref
=== null) {
193 $this->_dereference();
196 $this->_ref
->touch();
200 * Return object, which can be used to identify object and its references identity
202 * @return Zend_Pdf_Element_Object
204 public function getObject()
206 if ($this->_ref
=== null) {
207 $this->_dereference();
216 * @param string $property
219 public function __get($property)
221 if ($this->_ref
=== null) {
222 $this->_dereference();
225 return $this->_ref
->$property;
231 * @param string $property
232 * @param mixed $value
234 public function __set($property, $value)
236 if ($this->_ref
=== null) {
237 $this->_dereference();
240 $this->_ref
->$property = $value;
246 * @param string $method
250 public function __call($method, $args)
252 if ($this->_ref
=== null) {
253 $this->_dereference();
256 return call_user_func_array(array($this->_ref
, $method), $args);
262 public function cleanUp()
268 * Convert PDF element to PHP type.
272 public function toPhp()
274 if ($this->_ref
=== null) {
275 $this->_dereference();
278 return $this->_ref
->toPhp();