in-depth overview on the start page
[mdref/mdref] / mdref / RefListing.php
1 <?php
2
3 namespace mdref;
4
5 class RefListing implements \Countable, \Iterator
6 {
7 /**
8 * @var \mdref\Path
9 */
10 protected $path;
11
12 /**
13 * @var array
14 */
15 protected $entries;
16
17 /**
18 * @param \mdref\Path $path
19 * @param array $files
20 */
21 function __construct(Path $path, array $files) {
22 $this->path = $path;
23 $this->entries = array_map(function($fn) {
24 return substr(trim($fn, DIRECTORY_SEPARATOR), 0, -3);
25 }, $files);
26 }
27
28 function count() {
29 return count($this->entries);
30 }
31
32 function rewind() {
33 reset($this->entries);
34 }
35
36 function valid() {
37 return null !== key($this->entries);
38 }
39
40 function key() {
41 return $this->path->getSubPath(current($this->entries));
42 }
43
44 function next() {
45 next($this->entries);
46 }
47
48 function current() {
49 return new RefEntry($this->path, $this->key());//$this->format($this->key());
50 }
51
52 function getParent() {
53 switch ($parent = dirname($this->path->getPathName())) {
54 case ".":
55 case "":
56 return null;
57 default:
58 return new RefEntry($this->path, $parent);
59 }
60 }
61
62 function getSelf() {
63 return new RefEntry($this->path);
64 }
65 }