PageRenderTime 1120ms CodeModel.GetById 1102ms RepoModel.GetById 0ms app.codeStats 0ms

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

http://zoop.googlecode.com/
PHP | 148 lines | 56 code | 20 blank | 72 comment | 6 complexity | 0ee5f8ce02b6ceb728125cd39b28e293 MD5 | raw file
Possible License(s): BSD-3-Clause, LGPL-2.1
  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: Array.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 'array' 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_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. * Convert PDF element to PHP type.
  115. *
  116. * Dictionary is returned as an associative array
  117. *
  118. * @return mixed
  119. */
  120. public function toPhp()
  121. {
  122. $phpArray = array();
  123. foreach ($this->items as $item) {
  124. $phpArray[] = $item->toPhp();
  125. }
  126. return $phpArray;
  127. }
  128. }