/framework/vendor/zend/Zend/Pdf/Element/Object.php

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