d9e2b0db2149221b82e99d65fb43c4bddce90adb
5 class Tree
implements \RecursiveIterator
{
13 * List of first level entries
26 * @param \mdref\Repo $repo
28 public function __construct($path, Repo
$repo) {
29 if (!($list = glob("$path/*.md"))) {
30 $list = glob("$path/*/*.md");
32 $this->list = array_filter($list, $this->generateFilter($list));
33 sort($this->list, SORT_STRING
);
41 private function generateFilter(array $list) {
42 return function($v) use($list) {
46 if (false !== array_search("$v.md", $list, true)) {
51 if (isset($pi["extension"]) && "md" !== $pi["extension"]) {
60 * Implements \Iterator
61 * @return \mdref\Entry
63 public function current() {
64 return $this->repo
->getEntry($this->repo
->hasFile(current($this->iter
)));
68 * Implements \Iterator
70 public function next() {
75 * Implements \Iterator
78 public function key() {
79 return key($this->iter
);
83 * Implements \Iterator
85 public function rewind() {
86 $this->iter
= $this->list;
91 * Implements \Iterator
94 public function valid() {
95 return null !== key($this->iter
);
99 * Implements \RecursiveIterator
102 public function hasChildren() {
103 return $this->current()->hasIterator();
107 * Implements \RecursiveIterator
108 * @return \mdref\Tree
110 public function getChildren() {
111 return $this->current()->getIterator();