6 * Find markdown reference files in several REFPATH paths.
8 * The base URL is used to extract the relative identifier out of the request
9 * url in Finder::find().
11 * Use the created Path of Finder::find() for Finder::glob() to find subrefs.
17 * @var \http\Controller\Url
25 protected $refs = array();
28 * @param \http\Controller\Url $baseUrl
29 * @param mixed $paths array or string of paths with markdown references
31 function __construct(\http\Controller\Url
$baseUrl, $paths = ".") {
32 if (!is_array($paths)) {
33 $paths = explode(PATH_SEPARATOR
, $paths);
36 $this->baseUrl
= $baseUrl;
39 function getBaseUrl() {
40 return $this->baseUrl
;
44 * Find a markdown reference file in one REFPATH. If nothing could be found
45 * an empty Path will be returned.
47 * @param \http\Url $requestUrl
50 function find(\http\Url
$requestUrl, $ext = ".md") {
51 $file = implode(DIRECTORY_SEPARATOR
, $this->baseUrl
->params($requestUrl));
53 foreach ($this->refs
as $base) {
54 $path = new Path($base, $file);
55 if ($path->isFile($ext)) {
64 * Glob either in a Path's base dir, or, if the path does not have a base
65 * dir set, in each REFPATH paths.
67 * @param \mdref\Path $path
68 * @param string $pattern glob pattern
69 * @param int $flags glob flags
70 * @return array glob result
72 function glob(Path
$path, $pattern, $flags = GLOB_BRACE
) {
73 if (strlen($path->getBaseDir())) {
74 return glob($path->getFullPath($pattern), $flags);
77 foreach ($this->refs
as $ref) {
78 $glob = array_merge($glob, array_map(function ($fn) use ($ref) {
79 return substr($fn, strlen($ref));
80 }, glob($ref . $pattern, $flags)));