5 class Tree
implements \RecursiveIterator
{
13 * List of first level entries
16 private $list = array();
26 * @param \mdref\Repo $repo
28 public function __construct($path, Repo
$repo) {
29 if (realpath($path)."/" === $repo->getPath()) {
30 $list = [$path ."/". $repo->getName() .".md"];
31 } elseif (!($list = glob("$path/*.md"))) {
32 $list = glob("$path/*/*.md");
35 $this->list = array_filter($list, $this->generateFilter($list));
36 sort($this->list, SORT_STRING
);
45 private function generateFilter(array $list) {
46 return function($v) use($list) {
50 if (false !== array_search("$v.md", $list, true)) {
55 if (isset($pi["extension"]) && "md" !== $pi["extension"]) {
64 * Implements \Iterator
65 * @return \mdref\Entry
67 public function current() {
68 return $this->repo
->getEntry($this->repo
->hasFile(current($this->iter
)));
72 * Implements \Iterator
74 public function next() {
79 * Implements \Iterator
82 public function key() {
83 return key($this->iter
);
87 * Implements \Iterator
89 public function rewind() {
90 $this->iter
= $this->list;
95 * Implements \Iterator
98 public function valid() {
99 return null !== key($this->iter
);
103 * Implements \RecursiveIterator
106 public function hasChildren() {
107 return $this->current()->hasIterator();
111 * Implements \RecursiveIterator
112 * @return \mdref\Tree
114 public function getChildren() {
115 return $this->current()->getIterator();