Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
FileIterator.php
Go to the documentation of this file.
1 <?php
8 
11 
17 class FileIterator implements \Iterator, \Countable
18 {
24  protected $paths = [];
25 
31  protected $position;
32 
38  protected $fileReadFactory;
39 
46  public function __construct(ReadFactory $readFactory, array $paths)
47  {
48  $this->fileReadFactory = $readFactory;
49  $this->paths = $paths;
50  $this->position = 0;
51  }
52 
58  public function rewind()
59  {
60  reset($this->paths);
61  }
62 
68  public function current()
69  {
70  $fileRead = $this->fileReadFactory->create($this->key(), DriverPool::FILE);
71  return $fileRead->readAll();
72  }
73 
79  public function key()
80  {
81  return current($this->paths);
82  }
83 
89  public function next()
90  {
91  next($this->paths);
92  }
93 
99  public function valid()
100  {
101  return (bool) $this->key();
102  }
103 
109  public function toArray()
110  {
111  $result = [];
112  foreach ($this as $item) {
113  $result[$this->key()] = $item;
114  }
115  return $result;
116  }
117 
123  public function count()
124  {
125  return count($this->paths);
126  }
127 }
__construct(ReadFactory $readFactory, array $paths)