]> git.immae.eu Git - github/shaarli/Shaarli.git/blobdiff - application/LinkFilter.php
Refactor filter in LinkDB
[github/shaarli/Shaarli.git] / application / LinkFilter.php
index 3fd803cb81f4d79c08538a8fc3a7079d8f0b9644..5e0d801594533174e7bd5aaef188d3eda81dfc4a 100644 (file)
@@ -44,7 +44,7 @@ class LinkFilter
      * Filter links according to parameters.
      *
      * @param string $type          Type of filter (eg. tags, permalink, etc.).
-     * @param string $request       Filter content.
+     * @param mixed  $request       Filter content.
      * @param bool   $casesensitive Optional: Perform case sensitive filter if true.
      * @param bool   $privateonly   Optional: Only returns private links if true.
      *
@@ -110,6 +110,8 @@ class LinkFilter
      * @param string $smallHash permalink hash.
      *
      * @return array $filtered array containing permalink data.
+     *
+     * @throws LinkNotFoundException if the smallhash doesn't match any link.
      */
     private function filterSmallHash($smallHash)
     {
@@ -121,6 +123,11 @@ class LinkFilter
                 return $filtered;
             }
         }
+
+        if (empty($filtered)) {
+            throw new LinkNotFoundException();
+        }
+
         return $filtered;
     }
 
@@ -318,3 +325,8 @@ class LinkFilter
         return array_filter(explode(' ', trim($tagsOut)), 'strlen');
     }
 }
+
+class LinkNotFoundException extends Exception
+{
+    protected $message = 'The link you are trying to reach does not exist or has been deleted.';
+}