namespace mdref;
+/**
+ * A list of markdown reference files
+ */
class RefListing implements \Countable, \Iterator
{
/**
/**
* @param \mdref\Path $path
+ * @param array $files
*/
function __construct(Path $path, array $files) {
$this->path = $path;
}
/**
- * Copy constructor
- * @param mixed $filter callable array filter or fnmatch pattern
- * @return \mdref\RefListing
+ * Implements \Countable
+ * @return int
*/
- function __invoke($filter) {
- die(__METHOD__);
- $that = clone $this;
- $that->entries = array_filter($that->entries, is_callable($filter)
- ? $filter
- : function($fn) use ($filter) {
- return fnmatch($filter, $fn);
- }
- );
- return $that;
- }
-
- function __toString() {
- return __METHOD__;
- return $this->format(substr($this->path, strlen($this->path->getBaseDir())));
- }
-
function count() {
return count($this->entries);
}
+ /**
+ * Implements \Iterator
+ */
function rewind() {
reset($this->entries);
}
+ /**
+ * Implements \Iterator
+ * @return bool
+ */
function valid() {
return null !== key($this->entries);
}
+ /**
+ * Implements \Iterator
+ * @return string
+ */
function key() {
return $this->path->getSubPath(current($this->entries));
}
+ /**
+ * Implements \Iterator
+ */
function next() {
next($this->entries);
}
-
+
+ /**
+ * Implements \Iterator
+ * @return \mdref\RefEntry
+ */
function current() {
return new RefEntry($this->path, $this->key());//$this->format($this->key());
}
+ /**
+ * Get the parent reference entry
+ * @return null|\mdref\RefEntry
+ */
function getParent() {
switch ($parent = dirname($this->path->getPathName())) {
case ".":
}
}
+ /**
+ * Get the reference entry this reflist is based of
+ * @return \mdref\RefEntry
+ */
function getSelf() {
return new RefEntry($this->path);
}
-
- function format($entry) {
- return __METHOD__;
- $ns = "";
- if (strlen($entry = trim($entry, DIRECTORY_SEPARATOR))) {
- $upper = ctype_upper($entry[0]);
- $parts = explode(DIRECTORY_SEPARATOR, $entry);
-
- for ($i = 0; $i < count($parts); ++$i) {
- if (!strlen($parts[$i]) || $parts[$i] === ".") {
- continue;
- }
- if (strlen($ns)) {
- if ($upper && !ctype_upper($parts[$i][0])) {
- $ns .= "::";
- } else {
- $ns .= "\\";
- }
- }
- $ns .= $parts[$i];
- $upper = ctype_upper($parts[$i][0]);
- }
- }
- return $ns;
- }
-}
\ No newline at end of file
+}