181 lines
4.6 KiB

11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
  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-2014 Zend Technologies USA Inc. (http://www.zend.com)
  18. * @license http://framework.zend.com/license/new-bsd New BSD License
  19. * @version $Id$
  20. */
  21. /** Zend_Pdf_Element */
  22. // require_once 'Zend/Pdf/Element.php';
  23. /**
  24. * PDF file 'array' element implementation
  25. *
  26. * @category Zend
  27. * @package Zend_Pdf
  28. * @copyright Copyright (c) 2005-2014 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_Array extends Zend_Pdf_Element
  32. {
  33. /**
  34. * Array element items
  35. *
  36. * Array of Zend_Pdf_Element objects
  37. *
  38. * @var array
  39. */
  40. public $items;
  41. /**
  42. * Object constructor
  43. *
  44. * @param array $val - array of Zend_Pdf_Element objects
  45. * @throws Zend_Pdf_Exception
  46. */
  47. public function __construct($val = null)
  48. {
  49. $this->items = new ArrayObject();
  50. if ($val !== null && is_array($val)) {
  51. foreach ($val as $element) {
  52. if (!$element instanceof Zend_Pdf_Element) {
  53. // require_once 'Zend/Pdf/Exception.php';
  54. throw new Zend_Pdf_Exception('Array elements must be Zend_Pdf_Element objects');
  55. }
  56. $this->items[] = $element;
  57. }
  58. } else if ($val !== null){
  59. // require_once 'Zend/Pdf/Exception.php';
  60. throw new Zend_Pdf_Exception('Argument must be an array');
  61. }
  62. }
  63. /**
  64. * Getter
  65. *
  66. * @param string $property
  67. * @throws Zend_Pdf_Exception
  68. */
  69. public function __get($property) {
  70. // require_once 'Zend/Pdf/Exception.php';
  71. throw new Zend_Pdf_Exception('Undefined property: Zend_Pdf_Element_Array::$' . $property);
  72. }
  73. /**
  74. * Setter
  75. *
  76. * @param mixed $offset
  77. * @param mixed $value
  78. * @throws Zend_Pdf_Exception
  79. */
  80. public function __set($property, $value) {
  81. // require_once 'Zend/Pdf/Exception.php';
  82. throw new Zend_Pdf_Exception('Undefined property: Zend_Pdf_Element_Array::$' . $property);
  83. }
  84. /**
  85. * Return type of the element.
  86. *
  87. * @return integer
  88. */
  89. public function getType()
  90. {
  91. return Zend_Pdf_Element::TYPE_ARRAY;
  92. }
  93. /**
  94. * Return object as string
  95. *
  96. * @param Zend_Pdf_Factory $factory
  97. * @return string
  98. */
  99. public function toString($factory = null)
  100. {
  101. $outStr = '[';
  102. $lastNL = 0;
  103. foreach ($this->items as $element) {
  104. if (strlen($outStr) - $lastNL > 128) {
  105. $outStr .= "\n";
  106. $lastNL = strlen($outStr);
  107. }
  108. $outStr .= $element->toString($factory) . ' ';
  109. }
  110. $outStr .= ']';
  111. return $outStr;
  112. }
  113. /**
  114. * Detach PDF object from the factory (if applicable), clone it and attach to new factory.
  115. *
  116. * @param Zend_Pdf_ElementFactory $factory The factory to attach
  117. * @param array &$processed List of already processed indirect objects, used to avoid objects duplication
  118. * @param integer $mode Cloning mode (defines filter for objects cloning)
  119. * @returns Zend_Pdf_Element
  120. */
  121. public function makeClone(Zend_Pdf_ElementFactory $factory, array &$processed, $mode)
  122. {
  123. $newArray = new self();
  124. foreach ($this->items as $key => $value) {
  125. $newArray->items[$key] = $value->makeClone($factory, $processed, $mode);
  126. }
  127. return $newArray;
  128. }
  129. /**
  130. * Set top level parent indirect object.
  131. *
  132. * @param Zend_Pdf_Element_Object $parent
  133. */
  134. public function setParentObject(Zend_Pdf_Element_Object $parent)
  135. {
  136. parent::setParentObject($parent);
  137. foreach ($this->items as $item) {
  138. $item->setParentObject($parent);
  139. }
  140. }
  141. /**
  142. * Convert PDF element to PHP type.
  143. *
  144. * Dictionary is returned as an associative array
  145. *
  146. * @return mixed
  147. */
  148. public function toPhp()
  149. {
  150. $phpArray = array();
  151. foreach ($this->items as $item) {
  152. $phpArray[] = $item->toPhp();
  153. }
  154. return $phpArray;
  155. }
  156. }