File indexing completed on 2025-01-19 05:21:21
0001 <?php 0002 /** 0003 * Zend Framework 0004 * 0005 * LICENSE 0006 * 0007 * This source file is subject to the new BSD license that is bundled 0008 * with this package in the file LICENSE.txt. 0009 * It is also available through the world-wide-web at this URL: 0010 * http://framework.zend.com/license/new-bsd 0011 * If you did not receive a copy of the license and are unable to 0012 * obtain it through the world-wide-web, please send an email 0013 * to license@zend.com so we can send you a copy immediately. 0014 * 0015 * @category Zend 0016 * @package Zend_Pdf 0017 * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com) 0018 * @license http://framework.zend.com/license/new-bsd New BSD License 0019 * @version $Id$ 0020 */ 0021 0022 0023 /** Zend_Pdf_Element */ 0024 // require_once 'Zend/Pdf/Element.php'; 0025 0026 0027 /** 0028 * PDF file 'indirect object' element implementation 0029 * 0030 * @category Zend 0031 * @package Zend_Pdf 0032 * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com) 0033 * @license http://framework.zend.com/license/new-bsd New BSD License 0034 */ 0035 class Zend_Pdf_Element_Object extends Zend_Pdf_Element 0036 { 0037 /** 0038 * Object value 0039 * 0040 * @var Zend_Pdf_Element 0041 */ 0042 protected $_value; 0043 0044 /** 0045 * Object number within PDF file 0046 * 0047 * @var integer 0048 */ 0049 protected $_objNum; 0050 0051 /** 0052 * Generation number 0053 * 0054 * @var integer 0055 */ 0056 protected $_genNum; 0057 0058 /** 0059 * Reference to the factory. 0060 * 0061 * @var Zend_Pdf_ElementFactory 0062 */ 0063 protected $_factory; 0064 0065 /** 0066 * Object constructor 0067 * 0068 * @param Zend_Pdf_Element $val 0069 * @param integer $objNum 0070 * @param integer $genNum 0071 * @param Zend_Pdf_ElementFactory $factory 0072 * @throws Zend_Pdf_Exception 0073 */ 0074 public function __construct(Zend_Pdf_Element $val, $objNum, $genNum, Zend_Pdf_ElementFactory $factory) 0075 { 0076 if ($val instanceof self) { 0077 // require_once 'Zend/Pdf/Exception.php'; 0078 throw new Zend_Pdf_Exception('Object number must not be an instance of Zend_Pdf_Element_Object.'); 0079 } 0080 0081 if ( !(is_integer($objNum) && $objNum > 0) ) { 0082 // require_once 'Zend/Pdf/Exception.php'; 0083 throw new Zend_Pdf_Exception('Object number must be positive integer.'); 0084 } 0085 0086 if ( !(is_integer($genNum) && $genNum >= 0) ) { 0087 // require_once 'Zend/Pdf/Exception.php'; 0088 throw new Zend_Pdf_Exception('Generation number must be non-negative integer.'); 0089 } 0090 0091 $this->_value = $val; 0092 $this->_objNum = $objNum; 0093 $this->_genNum = $genNum; 0094 $this->_factory = $factory; 0095 0096 $this->setParentObject($this); 0097 0098 $factory->registerObject($this, $objNum . ' ' . $genNum); 0099 } 0100 0101 0102 /** 0103 * Check, that object is generated by specified factory 0104 * 0105 * @return Zend_Pdf_ElementFactory 0106 */ 0107 public function getFactory() 0108 { 0109 return $this->_factory; 0110 } 0111 0112 /** 0113 * Return type of the element. 0114 * 0115 * @return integer 0116 */ 0117 public function getType() 0118 { 0119 return $this->_value->getType(); 0120 } 0121 0122 0123 /** 0124 * Get object number 0125 * 0126 * @return integer 0127 */ 0128 public function getObjNum() 0129 { 0130 return $this->_objNum; 0131 } 0132 0133 0134 /** 0135 * Get generation number 0136 * 0137 * @return integer 0138 */ 0139 public function getGenNum() 0140 { 0141 return $this->_genNum; 0142 } 0143 0144 0145 /** 0146 * Return reference to the object 0147 * 0148 * @param Zend_Pdf_Factory $factory 0149 * @return string 0150 */ 0151 public function toString($factory = null) 0152 { 0153 if ($factory === null) { 0154 $shift = 0; 0155 } else { 0156 $shift = $factory->getEnumerationShift($this->_factory); 0157 } 0158 0159 return $this->_objNum + $shift . ' ' . $this->_genNum . ' R'; 0160 } 0161 0162 0163 /** 0164 * Dump object to a string to save within PDF file. 0165 * 0166 * $factory parameter defines operation context. 0167 * 0168 * @param Zend_Pdf_ElementFactory $factory 0169 * @return string 0170 */ 0171 public function dump(Zend_Pdf_ElementFactory $factory) 0172 { 0173 $shift = $factory->getEnumerationShift($this->_factory); 0174 0175 return $this->_objNum + $shift . " " . $this->_genNum . " obj \n" 0176 . $this->_value->toString($factory) . "\n" 0177 . "endobj\n"; 0178 } 0179 0180 /** 0181 * Get handler 0182 * 0183 * @param string $property 0184 * @return mixed 0185 */ 0186 public function __get($property) 0187 { 0188 return $this->_value->$property; 0189 } 0190 0191 /** 0192 * Set handler 0193 * 0194 * @param string $property 0195 * @param mixed $value 0196 */ 0197 public function __set($property, $value) 0198 { 0199 $this->_value->$property = $value; 0200 } 0201 0202 /** 0203 * Call handler 0204 * 0205 * @param string $method 0206 * @param array $args 0207 * @return mixed 0208 */ 0209 public function __call($method, $args) 0210 { 0211 return call_user_func_array(array($this->_value, $method), $args); 0212 } 0213 0214 /** 0215 * Detach PDF object from the factory (if applicable), clone it and attach to new factory. 0216 * 0217 * @param Zend_Pdf_ElementFactory $factory The factory to attach 0218 * @param array &$processed List of already processed indirect objects, used to avoid objects duplication 0219 * @param integer $mode Cloning mode (defines filter for objects cloning) 0220 * @returns Zend_Pdf_Element 0221 */ 0222 public function makeClone(Zend_Pdf_ElementFactory $factory, array &$processed, $mode) 0223 { 0224 $id = spl_object_hash($this); 0225 if (isset($processed[$id])) { 0226 // Do nothing if object is already processed 0227 // return it 0228 return $processed[$id]; 0229 } 0230 0231 // Create obect with null value and register it in $processed container 0232 $processed[$id] = $clonedObject = $factory->newObject(new Zend_Pdf_Element_Null()); 0233 0234 // Pecursively process actual data 0235 $clonedObject->_value = $this->_value->makeClone($factory, $processed, $mode); 0236 0237 if ($clonedObject->_value instanceof Zend_Pdf_Element_Null) { 0238 // Do not store null objects within $processed container since it may be filtered 0239 // by $mode parameter but used in some future pass 0240 unset($processed[$id]); 0241 0242 // Return direct null object 0243 return $clonedObject->_value; 0244 } 0245 0246 return $clonedObject; 0247 } 0248 0249 /** 0250 * Mark object as modified, to include it into new PDF file segment 0251 */ 0252 public function touch() 0253 { 0254 $this->_factory->markAsModified($this); 0255 } 0256 0257 /** 0258 * Return object, which can be used to identify object and its references identity 0259 * 0260 * @return Zend_Pdf_Element_Object 0261 */ 0262 public function getObject() 0263 { 0264 return $this; 0265 } 0266 0267 /** 0268 * Clean up resources, used by object 0269 */ 0270 public function cleanUp() 0271 { 0272 $this->_value = null; 0273 } 0274 0275 /** 0276 * Convert PDF element to PHP type. 0277 * 0278 * @return mixed 0279 */ 0280 public function toPhp() 0281 { 0282 return $this->_value->toPhp(); 0283 } 0284 }