]> git.immae.eu Git - github/wallabag/wallabag.git/blobdiff - src/Wallabag/CoreBundle/Helper/UrlHasher.php
Merge pull request #3944 from shtrom/always-hash-exists-url
[github/wallabag/wallabag.git] / src / Wallabag / CoreBundle / Helper / UrlHasher.php
diff --git a/src/Wallabag/CoreBundle/Helper/UrlHasher.php b/src/Wallabag/CoreBundle/Helper/UrlHasher.php
new file mode 100644 (file)
index 0000000..d123eab
--- /dev/null
@@ -0,0 +1,23 @@
+<?php
+
+namespace Wallabag\CoreBundle\Helper;
+
+/**
+ * Hash URLs for privacy and performance.
+ */
+class UrlHasher
+{
+    /**
+     * Hash the given url using the given algorithm.
+     * Hashed url are faster to be retrieved in the database than the real url.
+     *
+     * @param string $url
+     * @param string $algorithm
+     *
+     * @return string
+     */
+    public static function hashUrl(string $url, $algorithm = 'sha1')
+    {
+        return hash($algorithm, urldecode($url));
+    }
+}