5 class RefListing
implements \Countable
, \Iterator
18 * @param \mdref\Path $path
20 function __construct(Path
$path, array $files) {
22 $this->entries
= array_map(function($fn) {
23 return substr(trim($fn, DIRECTORY_SEPARATOR
), 0, -3);
29 * @param mixed $filter callable array filter or fnmatch pattern
30 * @return \mdref\RefListing
32 function __invoke($filter) {
35 $that->entries
= array_filter($that->entries
, is_callable($filter)
37 : function($fn) use ($filter) {
38 return fnmatch($filter, $fn);
44 function __toString() {
46 return $this->format(substr($this->path
, strlen($this->path
->getBaseDir())));
50 return count($this->entries
);
54 reset($this->entries
);
58 return null !== key($this->entries
);
62 return $this->path
->getSubPath(current($this->entries
));
70 return new RefEntry($this->path
, $this->key());//$this->format($this->key());
73 function getParent() {
74 switch ($parent = dirname($this->path
->getPathName())) {
79 return new RefEntry($this->path
, $parent);
84 return new RefEntry($this->path
);
87 function format($entry) {
90 if (strlen($entry = trim($entry, DIRECTORY_SEPARATOR
))) {
91 $upper = ctype_upper($entry[0]);
92 $parts = explode(DIRECTORY_SEPARATOR
, $entry);
94 for ($i = 0; $i < count($parts); ++
$i) {
95 if (!strlen($parts[$i]) ||
$parts[$i] === ".") {
99 if ($upper && !ctype_upper($parts[$i][0])) {
106 $upper = ctype_upper($parts[$i][0]);