openshift makefile
[mdref/mdref] / mdref / Finder.php
index 9d1c64c68d774b2ef1950798923afb5e22ada72f..e5cb7fb68c16816a618ddcb285ffddd8e8ea5f82 100644 (file)
@@ -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);