Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
NameTree.php
Go to the documentation of this file.
1 <?php
24 #require_once 'Zend/Pdf/Element.php';
25 
26 
36 class Zend_Pdf_NameTree implements ArrayAccess, Iterator, Countable
37 {
44  protected $_items = array();
45 
51  public function __construct(Zend_Pdf_Element $rootDictionary)
52  {
53  if ($rootDictionary->getType() != Zend_Pdf_Element::TYPE_DICTIONARY) {
54  #require_once 'Zend/Pdf/Exception.php';
55  throw new Zend_Pdf_Exception('Name tree root must be a dictionary.');
56  }
57 
58  $intermediateNodes = array();
59  $leafNodes = array();
60  if ($rootDictionary->Kids !== null) {
61  $intermediateNodes[] = $rootDictionary;
62  } else {
63  $leafNodes[] = $rootDictionary;
64  }
65 
66  while (count($intermediateNodes) != 0) {
67  $newIntermediateNodes = array();
68  foreach ($intermediateNodes as $node) {
69  foreach ($node->Kids->items as $childNode) {
70  if ($childNode->Kids !== null) {
71  $newIntermediateNodes[] = $childNode;
72  } else {
73  $leafNodes[] = $childNode;
74  }
75  }
76  }
77  $intermediateNodes = $newIntermediateNodes;
78  }
79 
80  foreach ($leafNodes as $leafNode) {
81  $destinationsCount = count($leafNode->Names->items)/2;
82  for ($count = 0; $count < $destinationsCount; $count++) {
83  $this->_items[$leafNode->Names->items[$count*2]->value] = $leafNode->Names->items[$count*2 + 1];
84  }
85  }
86  }
87 
88  public function current()
89  {
90  return current($this->_items);
91  }
92 
93 
94  public function next()
95  {
96  return next($this->_items);
97  }
98 
99 
100  public function key()
101  {
102  return key($this->_items);
103  }
104 
105 
106  public function valid() {
107  return current($this->_items)!==false;
108  }
109 
110 
111  public function rewind()
112  {
113  reset($this->_items);
114  }
115 
116 
117  public function offsetExists($offset)
118  {
119  return array_key_exists($offset, $this->_items);
120  }
121 
122 
123  public function offsetGet($offset)
124  {
125  return $this->_items[$offset];
126  }
127 
128 
129  public function offsetSet($offset, $value)
130  {
131  if ($offset === null) {
132  $this->_items[] = $value;
133  } else {
134  $this->_items[$offset] = $value;
135  }
136  }
137 
138 
139  public function offsetUnset($offset)
140  {
141  unset($this->_items[$offset]);
142  }
143 
144 
145  public function clear()
146  {
147  $this->_items = array();
148  }
149 
150  public function count()
151  {
152  return count($this->_items);
153  }
154 }
$count
Definition: recent.phtml:13
const TYPE_DICTIONARY
Definition: Element.php:37
__construct(Zend_Pdf_Element $rootDictionary)
Definition: NameTree.php:51
offsetUnset($offset)
Definition: NameTree.php:139
$value
Definition: gender.phtml:16
offsetSet($offset, $value)
Definition: NameTree.php:129
offsetExists($offset)
Definition: NameTree.php:117
offsetGet($offset)
Definition: NameTree.php:123