1<?php 2 3/** 4 * Hoa 5 * 6 * 7 * @license 8 * 9 * New BSD License 10 * 11 * Copyright © 2007-2017, Hoa community. All rights reserved. 12 * 13 * Redistribution and use in source and binary forms, with or without 14 * modification, are permitted provided that the following conditions are met: 15 * * Redistributions of source code must retain the above copyright 16 * notice, this list of conditions and the following disclaimer. 17 * * Redistributions in binary form must reproduce the above copyright 18 * notice, this list of conditions and the following disclaimer in the 19 * documentation and/or other materials provided with the distribution. 20 * * Neither the name of the Hoa nor the names of its contributors may be 21 * used to endorse or promote products derived from this software without 22 * specific prior written permission. 23 * 24 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 25 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 26 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 27 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS AND CONTRIBUTORS BE 28 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 29 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 30 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 31 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 32 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 33 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 34 * POSSIBILITY OF SUCH DAMAGE. 35 */ 36 37namespace Hoa\Iterator\Recursive; 38 39/** 40 * Class \Hoa\Iterator\Recursive\Mock. 41 * 42 * Mock a recursive iterator with no children. 43 * It allows to use regular iterators with a recursive iterator iterator. 44 * 45 * @copyright Copyright © 2007-2017 Hoa community 46 * @license New BSD License 47 */ 48class Mock implements Recursive 49{ 50 /** 51 * Current iterator. 52 * 53 * @var \Traversable 54 */ 55 protected $_iterator = null; 56 57 58 59 /** 60 * Constructor. 61 * 62 * @param \Traversable $iterator Iterator. 63 */ 64 public function __construct(\Traversable $iterator) 65 { 66 if ($iterator instanceof \IteratorAggregate) { 67 $iterator = $iterator->getIterator(); 68 } 69 70 $this->_iterator = $iterator; 71 72 return; 73 } 74 75 /** 76 * Return the current element. 77 * 78 * @return mixed 79 */ 80 public function current() 81 { 82 return $this->_iterator->current(); 83 } 84 85 /** 86 * Return the key of the current element. 87 * 88 * @return mixed 89 */ 90 public function key() 91 { 92 return $this->_iterator->key(); 93 } 94 95 /** 96 * Move forward to next element. 97 * 98 * @return void 99 */ 100 public function next() 101 { 102 return $this->_iterator->next(); 103 } 104 105 /** 106 * Rewind the iterator to the first element. 107 * 108 * @return void 109 */ 110 public function rewind() 111 { 112 return $this->_iterator->rewind(); 113 } 114 115 /** 116 * Check if current position is valid. 117 * 118 * @return bool 119 */ 120 public function valid() 121 { 122 return $this->_iterator->valid(); 123 } 124 125 /** 126 * Return an iterator for the current entry. 127 * It's a fake, we return null. 128 * 129 * @return void 130 */ 131 public function getChildren() 132 { 133 return null; 134 } 135 136 /** 137 * Return if an iterator can be created for the current entry. 138 * It's a fake, we return false. 139 * 140 * @return bool 141 */ 142 public function hasChildren() 143 { 144 return false; 145 } 146} 147