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 (!($list = glob("$path/*.md"))) {
30 $list = glob("$path/*/*.md");
33 $this->list = array_filter($list, $this->generateFilter($list));
34 sort($this->list, SORT_STRING
);
43 private function generateFilter(array $list) {
44 return function($v) use($list) {
48 if (false !== array_search("$v.md", $list, true)) {
53 if (isset($pi["extension"]) && "md" !== $pi["extension"]) {
62 * Implements \Iterator
63 * @return \mdref\Entry
65 public function current() {
66 return $this->repo
->getEntry($this->repo
->hasFile(current($this->iter
)));
70 * Implements \Iterator
72 public function next() {
77 * Implements \Iterator
80 public function key() {
81 return key($this->iter
);
85 * Implements \Iterator
87 public function rewind() {
88 $this->iter
= $this->list;
93 * Implements \Iterator
96 public function valid() {
97 return null !== key($this->iter
);
101 * Implements \RecursiveIterator
104 public function hasChildren() {
105 return $this->current()->hasIterator();
109 * Implements \RecursiveIterator
110 * @return \mdref\Tree
112 public function getChildren() {
113 return $this->current()->getIterator();