From 4a5516376bf4c8b0cdc1e81d24ce1cca68425785 Mon Sep 17 00:00:00 2001 From: Olivier Mehani Date: Fri, 10 May 2019 22:07:55 +1000 Subject: Add Wallabag\CoreBundle\Helper\UrlHasher Signed-off-by: Olivier Mehani --- .../CoreBundle/Repository/EntryRepository.php | 29 +++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) (limited to 'src/Wallabag/CoreBundle/Repository/EntryRepository.php') diff --git a/src/Wallabag/CoreBundle/Repository/EntryRepository.php b/src/Wallabag/CoreBundle/Repository/EntryRepository.php index 960b682d..37fc1000 100644 --- a/src/Wallabag/CoreBundle/Repository/EntryRepository.php +++ b/src/Wallabag/CoreBundle/Repository/EntryRepository.php @@ -9,6 +9,7 @@ use Pagerfanta\Adapter\DoctrineORMAdapter; use Pagerfanta\Pagerfanta; use Wallabag\CoreBundle\Entity\Entry; use Wallabag\CoreBundle\Entity\Tag; +use Wallabag\CoreBundle\Helper\UrlHasher; class EntryRepository extends EntityRepository { @@ -349,7 +350,7 @@ class EntryRepository extends EntityRepository public function findByUrlAndUserId($url, $userId) { return $this->findByHashedUrlAndUserId( - hash('sha1', $url), // XXX: the hash logic would better be in a separate util to avoid duplication with GenerateUrlHashesCommand::generateHashedUrls + UrlHasher::hashUrl($url), $userId); } @@ -506,6 +507,32 @@ class EntryRepository extends EntityRepository return $this->find($randomId); } + /** + * Inject a UrlHasher. + * + * @param UrlHasher $hasher + */ + public function setUrlHasher(UrlHasher $hasher) + { + $this->urlHasher = $hasher; + } + + /** + * Get the UrlHasher, or create a default one if not injected. + * + * XXX: the default uses the default hash algorithm + * + * @return UrlHasher + */ + protected function getUrlHasher() + { + if (!isset($this->urlHasher)) { + $this->setUrlHasher(new UrlHasher()); + } + + return $this->urlHasher; + } + /** * Return a query builder to be used by other getBuilderFor* method. * -- cgit v1.2.3