2
0

Array.php 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  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$
  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-2009 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. throw new Zend_Pdf_Exception('Array elements must be Zend_Pdf_Element objects');
  54. }
  55. $this->items[] = $element;
  56. }
  57. } else if ($val !== null){
  58. throw new Zend_Pdf_Exception('Argument must be an array');
  59. }
  60. }
  61. /**
  62. * Getter
  63. *
  64. * @param string $property
  65. * @throws Zend_Pdf_Exception
  66. */
  67. public function __get($property) {
  68. require_once 'Zend/Pdf/Exception.php';
  69. throw new Zend_Pdf_Exception('Undefined property: Zend_Pdf_Element_Array::$' . $property);
  70. }
  71. /**
  72. * Setter
  73. *
  74. * @param mixed $offset
  75. * @param mixed $value
  76. * @throws Zend_Pdf_Exception
  77. */
  78. public function __set($property, $value) {
  79. require_once 'Zend/Pdf/Exception.php';
  80. throw new Zend_Pdf_Exception('Undefined property: Zend_Pdf_Element_Array::$' . $property);
  81. }
  82. /**
  83. * Return type of the element.
  84. *
  85. * @return integer
  86. */
  87. public function getType()
  88. {
  89. return Zend_Pdf_Element::TYPE_ARRAY;
  90. }
  91. /**
  92. * Return object as string
  93. *
  94. * @param Zend_Pdf_Factory $factory
  95. * @return string
  96. */
  97. public function toString($factory = null)
  98. {
  99. $outStr = '[';
  100. $lastNL = 0;
  101. foreach ($this->items as $element) {
  102. if (strlen($outStr) - $lastNL > 128) {
  103. $outStr .= "\n";
  104. $lastNL = strlen($outStr);
  105. }
  106. $outStr .= $element->toString($factory) . ' ';
  107. }
  108. $outStr .= ']';
  109. return $outStr;
  110. }
  111. /**
  112. * Convert PDF element to PHP type.
  113. *
  114. * Dictionary is returned as an associative array
  115. *
  116. * @return mixed
  117. */
  118. public function toPhp()
  119. {
  120. $phpArray = array();
  121. foreach ($this->items as $item) {
  122. $phpArray[] = $item->toPhp();
  123. }
  124. return $phpArray;
  125. }
  126. }