refs = $paths; $this->baseUrl = $baseUrl; } /** * @return \http\Controller\Url */ function getBaseUrl() { return $this->baseUrl; } /** * Find a markdown reference file in one REFPATH. If nothing could be found * an empty Path will be returned. * * @param \http\Url $requestUrl * @return Path */ function find(\http\Url $requestUrl, $ext = ".md") { $file = implode(DIRECTORY_SEPARATOR, $this->baseUrl->params($requestUrl)); foreach ($this->refs as $base) { $path = new Path($base, $file); if ($path->isFile($ext)) { return $path; } } return new Path; } /** * Glob either in a Path's base dir, or, if the path does not have a base * dir set, in each REFPATH paths. * * @param \mdref\Path $path * @param string $pattern glob pattern * @param int $flags glob flags * @return array glob result */ function glob(Path $path, $pattern, $flags = GLOB_BRACE) { if (strlen($path->getBaseDir())) { return glob($path->getFullPath($pattern), $flags); } $glob = array(); foreach ($this->refs as $ref) { $glob = array_merge($glob, array_map(function ($fn) use ($ref) { return substr($fn, strlen($ref)); }, glob($ref . $pattern, $flags))); } return $glob; } }