aboutsummaryrefslogtreecommitdiffhomepage
path: root/application/LinkFilter.php
diff options
context:
space:
mode:
authorArthurHoaro <arthur@hoa.ro>2016-03-21 21:40:49 +0100
committerArthurHoaro <arthur@hoa.ro>2016-03-25 19:17:59 +0100
commit528a6f8a232c060faf024008e4f8a09b4aa8dabc (patch)
tree86cac78b7f4d3998bedd923da83145c37ec88ff4 /application/LinkFilter.php
parentee88a4bcc29da721cf43b750663aebeac4969517 (diff)
downloadShaarli-528a6f8a232c060faf024008e4f8a09b4aa8dabc.tar.gz
Shaarli-528a6f8a232c060faf024008e4f8a09b4aa8dabc.tar.zst
Shaarli-528a6f8a232c060faf024008e4f8a09b4aa8dabc.zip
Refactor filter in LinkDB
* search type now carried by LinkDB in order to factorize code between different search sources. * LinkDB->filter split in 3 method: filterSearch, filterHash, filterDay (we know what type of filter is needed). * filterHash now throw a LinkNotFoundException if it doesn't exist: internal implementation choice, still displays a 404. * Smallhash regex has been rewritten. * Unit tests update
Diffstat (limited to 'application/LinkFilter.php')
-rw-r--r--application/LinkFilter.php14
1 files changed, 13 insertions, 1 deletions
diff --git a/application/LinkFilter.php b/application/LinkFilter.php
index 3fd803cb..5e0d8015 100644
--- a/application/LinkFilter.php
+++ b/application/LinkFilter.php
@@ -44,7 +44,7 @@ class LinkFilter
44 * Filter links according to parameters. 44 * Filter links according to parameters.
45 * 45 *
46 * @param string $type Type of filter (eg. tags, permalink, etc.). 46 * @param string $type Type of filter (eg. tags, permalink, etc.).
47 * @param string $request Filter content. 47 * @param mixed $request Filter content.
48 * @param bool $casesensitive Optional: Perform case sensitive filter if true. 48 * @param bool $casesensitive Optional: Perform case sensitive filter if true.
49 * @param bool $privateonly Optional: Only returns private links if true. 49 * @param bool $privateonly Optional: Only returns private links if true.
50 * 50 *
@@ -110,6 +110,8 @@ class LinkFilter
110 * @param string $smallHash permalink hash. 110 * @param string $smallHash permalink hash.
111 * 111 *
112 * @return array $filtered array containing permalink data. 112 * @return array $filtered array containing permalink data.
113 *
114 * @throws LinkNotFoundException if the smallhash doesn't match any link.
113 */ 115 */
114 private function filterSmallHash($smallHash) 116 private function filterSmallHash($smallHash)
115 { 117 {
@@ -121,6 +123,11 @@ class LinkFilter
121 return $filtered; 123 return $filtered;
122 } 124 }
123 } 125 }
126
127 if (empty($filtered)) {
128 throw new LinkNotFoundException();
129 }
130
124 return $filtered; 131 return $filtered;
125 } 132 }
126 133
@@ -318,3 +325,8 @@ class LinkFilter
318 return array_filter(explode(' ', trim($tagsOut)), 'strlen'); 325 return array_filter(explode(' ', trim($tagsOut)), 'strlen');
319 } 326 }
320} 327}
328
329class LinkNotFoundException extends Exception
330{
331 protected $message = 'The link you are trying to reach does not exist or has been deleted.';
332}