*prechod na novsiu verziu ZF
[sport-group.git] / library / Zend / Pdf / Element / Reference.php
blob24be9784e9e98b6a1ae7e3ad30627b2632db110e
1 <?php
2 /**
3 * Zend Framework
5 * LICENSE
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.
15 * @category Zend
16 * @package Zend_Pdf
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';
36 /**
37 * PDF file 'reference' element implementation
39 * @category Zend
40 * @package Zend_Pdf
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
46 /**
47 * Object value
48 * The reference to the object
50 * @var mixed
52 private $_ref;
54 /**
55 * Object number within PDF file
57 * @var integer
59 private $_objNum;
61 /**
62 * Generation number
64 * @var integer
66 private $_genNum;
68 /**
69 * Reference context
71 * @var Zend_Pdf_Element_Reference_Context
73 private $_context;
76 /**
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
86 private $_factory;
88 /**
89 * Object constructor:
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;
108 $this->_ref = null;
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.
127 * @return integer
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
143 * @return string
145 public function toString($factory = null)
147 if ($factory === null) {
148 $shift = 0;
149 } else {
150 $shift = $factory->getEnumerationShift($this->_factory);
153 return $this->_objNum + $shift . ' ' . $this->_genNum . ' R';
158 * Dereference.
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
162 * $obj can be null
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'),
171 $this->_context
175 if ($obj === null ) {
176 $this->_ref = new Zend_Pdf_Element_Null();
177 return;
180 if ($obj->toString() != $this->_objNum . ' ' . $this->_genNum . ' R') {
181 throw new Zend_Pdf_Exception('Incorrect reference to the object');
184 $this->_ref = $obj;
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();
210 return $this->_ref;
214 * Get handler
216 * @param string $property
217 * @return mixed
219 public function __get($property)
221 if ($this->_ref === null) {
222 $this->_dereference();
225 return $this->_ref->$property;
229 * Set handler
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;
244 * Call handler
246 * @param string $method
247 * @param array $args
248 * @return mixed
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);
260 * Clean up resources
262 public function cleanUp()
264 $this->_ref = null;
268 * Convert PDF element to PHP type.
270 * @return mixed
272 public function toPhp()
274 if ($this->_ref === null) {
275 $this->_dereference();
278 return $this->_ref->toPhp();