/tine20/library/Zend/Pdf/Element/Object.php

https://gitlab.com/rsilveira1987/Expresso · PHP · 250 lines · 88 code · 35 blank · 127 comment · 7 complexity · 45f87e7fc374e8532eec011759230577 MD5 · raw file

  1. <?php
  2. /**
  3. * Zend Framework
  4. *
  5. * LICENSE
  6. *
  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.
  14. *
  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: Object.php 10020 2009-08-18 14:34:09Z j.fischer@metaways.de $
  20. */
  21. /** Zend_Pdf_Element */
  22. require_once 'Zend/Pdf/Element.php';
  23. /** Zend_Pdf_ElementFactory */
  24. require_once 'Zend/Pdf/ElementFactory.php';
  25. /**
  26. * PDF file 'indirect object' element implementation
  27. *
  28. * @category Zend
  29. * @package Zend_Pdf
  30. * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
  31. * @license http://framework.zend.com/license/new-bsd New BSD License
  32. */
  33. class Zend_Pdf_Element_Object extends Zend_Pdf_Element
  34. {
  35. /**
  36. * Object value
  37. *
  38. * @var Zend_Pdf_Element
  39. */
  40. protected $_value;
  41. /**
  42. * Object number within PDF file
  43. *
  44. * @var integer
  45. */
  46. protected $_objNum;
  47. /**
  48. * Generation number
  49. *
  50. * @var integer
  51. */
  52. protected $_genNum;
  53. /**
  54. * Reference to the factory.
  55. *
  56. * @var Zend_Pdf_ElementFactory
  57. */
  58. protected $_factory;
  59. /**
  60. * Object constructor
  61. *
  62. * @param Zend_Pdf_Element $val
  63. * @param integer $objNum
  64. * @param integer $genNum
  65. * @param Zend_Pdf_ElementFactory $factory
  66. * @throws Zend_Pdf_Exception
  67. */
  68. public function __construct(Zend_Pdf_Element $val, $objNum, $genNum, Zend_Pdf_ElementFactory $factory)
  69. {
  70. if ($val instanceof self) {
  71. throw new Zend_Pdf_Exception('Object number must not be an instance of Zend_Pdf_Element_Object.');
  72. }
  73. if ( !(is_integer($objNum) && $objNum > 0) ) {
  74. throw new Zend_Pdf_Exception('Object number must be positive integer.');
  75. }
  76. if ( !(is_integer($genNum) && $genNum >= 0) ) {
  77. throw new Zend_Pdf_Exception('Generation number must be non-negative integer.');
  78. }
  79. $this->_value = $val;
  80. $this->_objNum = $objNum;
  81. $this->_genNum = $genNum;
  82. $this->_factory = $factory;
  83. $this->setParentObject($this);
  84. $factory->registerObject($this, $objNum . ' ' . $genNum);
  85. }
  86. /**
  87. * Check, that object is generated by specified factory
  88. *
  89. * @return Zend_Pdf_ElementFactory
  90. */
  91. public function getFactory()
  92. {
  93. return $this->_factory;
  94. }
  95. /**
  96. * Return type of the element.
  97. *
  98. * @return integer
  99. */
  100. public function getType()
  101. {
  102. return $this->_value->getType();
  103. }
  104. /**
  105. * Get object number
  106. *
  107. * @return integer
  108. */
  109. public function getObjNum()
  110. {
  111. return $this->_objNum;
  112. }
  113. /**
  114. * Get generation number
  115. *
  116. * @return integer
  117. */
  118. public function getGenNum()
  119. {
  120. return $this->_genNum;
  121. }
  122. /**
  123. * Return reference to the object
  124. *
  125. * @param Zend_Pdf_Factory $factory
  126. * @return string
  127. */
  128. public function toString($factory = null)
  129. {
  130. if ($factory === null) {
  131. $shift = 0;
  132. } else {
  133. $shift = $factory->getEnumerationShift($this->_factory);
  134. }
  135. return $this->_objNum + $shift . ' ' . $this->_genNum . ' R';
  136. }
  137. /**
  138. * Dump object to a string to save within PDF file.
  139. *
  140. * $factory parameter defines operation context.
  141. *
  142. * @param Zend_Pdf_ElementFactory $factory
  143. * @return string
  144. */
  145. public function dump(Zend_Pdf_ElementFactory $factory)
  146. {
  147. $shift = $factory->getEnumerationShift($this->_factory);
  148. return $this->_objNum + $shift . " " . $this->_genNum . " obj \n"
  149. . $this->_value->toString($factory) . "\n"
  150. . "endobj\n";
  151. }
  152. /**
  153. * Get handler
  154. *
  155. * @param string $property
  156. * @return mixed
  157. */
  158. public function __get($property)
  159. {
  160. return $this->_value->$property;
  161. }
  162. /**
  163. * Set handler
  164. *
  165. * @param string $property
  166. * @param mixed $value
  167. */
  168. public function __set($property, $value)
  169. {
  170. $this->_value->$property = $value;
  171. }
  172. /**
  173. * Call handler
  174. *
  175. * @param string $method
  176. * @param array $args
  177. * @return mixed
  178. */
  179. public function __call($method, $args)
  180. {
  181. return call_user_func_array(array($this->_value, $method), $args);
  182. }
  183. /**
  184. * Mark object as modified, to include it into new PDF file segment
  185. */
  186. public function touch()
  187. {
  188. $this->_factory->markAsModified($this);
  189. }
  190. /**
  191. * Return object, which can be used to identify object and its references identity
  192. *
  193. * @return Zend_Pdf_Element_Object
  194. */
  195. public function getObject()
  196. {
  197. return $this;
  198. }
  199. /**
  200. * Clean up resources, used by object
  201. */
  202. public function cleanUp()
  203. {
  204. $this->_value = null;
  205. }
  206. /**
  207. * Convert PDF element to PHP type.
  208. *
  209. * @return mixed
  210. */
  211. public function toPhp()
  212. {
  213. return $this->_value->toPhp();
  214. }
  215. }