X-Git-Url: https://git.m6w6.name/?a=blobdiff_plain;ds=sidebyside;f=mdref%2FFinder.php;h=e5cb7fb68c16816a618ddcb285ffddd8e8ea5f82;hb=9d7a4b3fe45e2e82918a8cdf2dde323b3008ff84;hp=9d1c64c68d774b2ef1950798923afb5e22ada72f;hpb=e49b8a277a69f2b1e1d90a0f7607b08bbf972da2;p=mdref%2Fmdref diff --git a/mdref/Finder.php b/mdref/Finder.php index 9d1c64c..e5cb7fb 100644 --- a/mdref/Finder.php +++ b/mdref/Finder.php @@ -2,6 +2,14 @@ namespace mdref; +/** + * Find markdown reference files in several REFPATH paths. + * + * The base URL is used to extract the relative identifier out of the request + * url in Finder::find(). + * + * Use the created Path of Finder::find() for Finder::glob() to find subrefs. + */ class Finder { /** @@ -29,21 +37,41 @@ class Finder } /** + * @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) { - $file = implode(DIRECTORY_SEPARATOR, - $this->baseUrl->params($requestUrl)); + 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()) { + 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);