Container.php 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  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. * @subpackage Actions
  18. * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
  19. * @license http://framework.zend.com/license/new-bsd New BSD License
  20. * @version $Id$
  21. */
  22. /**
  23. * Iteratable outlines container
  24. *
  25. * @todo Implement an ability to associate an outline item with a structure element (PDF 1.3 feature)
  26. *
  27. * @package Zend_Pdf
  28. * @subpackage Outlines
  29. * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
  30. * @license http://framework.zend.com/license/new-bsd New BSD License
  31. */
  32. class Zend_Pdf_Outline_Container implements RecursiveIterator, Countable
  33. {
  34. /**
  35. * Array of outlines (array of Zend_Pdf_Outline objects)
  36. *
  37. * @var array
  38. */
  39. protected $_outlines = array();
  40. /**
  41. * Object constructor
  42. *
  43. * @param array $outlines
  44. */
  45. public function __construct(array $outlines)
  46. {
  47. $this->_outlines = $outlines;
  48. }
  49. ////////////////////////////////////////////////////////////////////////
  50. // RecursiveIterator interface methods
  51. //////////////
  52. /**
  53. * Returns the child outline.
  54. *
  55. * @return Zend_Pdf_Outline|null
  56. */
  57. public function current()
  58. {
  59. return current($this->_outlines);
  60. }
  61. /**
  62. * Returns current iterator key
  63. *
  64. * @return integer
  65. */
  66. public function key()
  67. {
  68. return key($this->_outlines);
  69. }
  70. /**
  71. * Go to next child
  72. */
  73. public function next()
  74. {
  75. return next($this->_outlines);
  76. }
  77. /**
  78. * Rewind children
  79. */
  80. public function rewind()
  81. {
  82. return reset($this->_outlines);
  83. }
  84. /**
  85. * Check if current position is valid
  86. *
  87. * @return boolean
  88. */
  89. public function valid()
  90. {
  91. return current($this->_outlines) !== false;
  92. }
  93. /**
  94. * Returns the child outline.
  95. *
  96. * @return Zend_Pdf_Outline|null
  97. */
  98. public function getChildren()
  99. {
  100. return current($this->_outlines);
  101. }
  102. /**
  103. * Implements RecursiveIterator interface.
  104. *
  105. * @return bool whether container has any pages
  106. */
  107. public function hasChildren()
  108. {
  109. return count($this->_outlines) > 0;
  110. }
  111. ////////////////////////////////////////////////////////////////////////
  112. // Countable interface methods
  113. //////////////
  114. /**
  115. * count()
  116. *
  117. * @return int
  118. */
  119. public function count()
  120. {
  121. return count($this->_outlines);
  122. }
  123. }