2019-05-10 12:07:55 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Wallabag\CoreBundle\Helper;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Hash URLs for privacy and performance.
|
|
|
|
*/
|
|
|
|
class UrlHasher
|
|
|
|
{
|
|
|
|
/**
|
2019-05-24 13:15:12 +00:00
|
|
|
* Hash the given url using the given algorithm.
|
|
|
|
* Hashed url are faster to be retrieved in the database than the real url.
|
|
|
|
*
|
|
|
|
* @param string $algorithm
|
2019-05-10 12:07:55 +00:00
|
|
|
*
|
2019-05-24 13:15:12 +00:00
|
|
|
* @return string
|
2019-05-10 12:07:55 +00:00
|
|
|
*/
|
2019-05-24 13:15:12 +00:00
|
|
|
public static function hashUrl(string $url, $algorithm = 'sha1')
|
2019-05-10 12:07:55 +00:00
|
|
|
{
|
2019-05-24 13:15:12 +00:00
|
|
|
return hash($algorithm, urldecode($url));
|
2019-05-10 12:07:55 +00:00
|
|
|
}
|
|
|
|
}
|