X-Git-Url: https://git.m6w6.name/?a=blobdiff_plain;f=mdref%2FRefListing.php;h=d7180906479721f4066d54a6083b769bbf47ee8a;hb=e49b8a277a69f2b1e1d90a0f7607b08bbf972da2;hp=542a3ffe07bffa25c12bc245e271390455fbac9c;hpb=d7b9f83d24b7af987618921f555c9e5e2c2f4b95;p=mdref%2Fmdref diff --git a/mdref/RefListing.php b/mdref/RefListing.php index 542a3ff..d718090 100644 --- a/mdref/RefListing.php +++ b/mdref/RefListing.php @@ -1,8 +1,111 @@ path = $path; + $this->entries = array_map(function($fn) { + return substr(trim($fn, DIRECTORY_SEPARATOR), 0, -3); + }, $files); + } + + /** + * Copy constructor + * @param mixed $filter callable array filter or fnmatch pattern + * @return \mdref\RefListing + */ + 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); + } + + function rewind() { + reset($this->entries); + } + + function valid() { + return null !== key($this->entries); + } + + function key() { + return $this->path->getSubPath(current($this->entries)); + } + + function next() { + next($this->entries); + } + + function current() { + return new RefEntry($this->path, $this->key());//$this->format($this->key()); + } + + function getParent() { + switch ($parent = dirname($this->path->getPathName())) { + case ".": + case "": + return null; + default: + return new RefEntry($this->path, $parent); + } + } + + 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