From 1bee0eeb2965d930f92c7eae6debf7f6b83ff051 Mon Sep 17 00:00:00 2001 From: Yassine Guedidi Date: Sat, 27 Aug 2022 23:01:09 +0200 Subject: [PATCH] Make repositories use ServiceEntityRepository --- app/config/services.yml | 37 ++++++++----------- .../Repository/AnnotationRepository.php | 10 ++++- .../ApiBundle/Repository/ClientRepository.php | 11 +++++- .../Repository/ConfigRepository.php | 10 ++++- .../CoreBundle/Repository/EntryRepository.php | 10 ++++- .../IgnoreOriginInstanceRuleRepository.php | 10 ++++- .../IgnoreOriginUserRuleRepository.php | 10 ++++- .../Repository/SiteCredentialRepository.php | 9 ++++- .../CoreBundle/Repository/TagRepository.php | 10 ++++- .../Repository/TaggingRuleRepository.php | 10 ++++- .../UserBundle/Repository/UserRepository.php | 10 ++++- 11 files changed, 95 insertions(+), 42 deletions(-) diff --git a/app/config/services.yml b/app/config/services.yml index 4992f3d58..f578511a0 100644 --- a/app/config/services.yml +++ b/app/config/services.yml @@ -109,27 +109,23 @@ services: Wallabag\CoreBundle\Helper\RuleBasedIgnoreOriginProcessor: ~ # repository as a service - Wallabag\CoreBundle\Repository\EntryRepository: - factory: [ "@doctrine.orm.default_entity_manager", getRepository ] - arguments: - - 'Wallabag\CoreBundle\Entity\Entry' + Wallabag\AnnotationBundle\Repository\AnnotationRepository: ~ - Wallabag\CoreBundle\Repository\TagRepository: - factory: [ "@doctrine.orm.default_entity_manager", getRepository ] - arguments: - - 'Wallabag\CoreBundle\Entity\Tag' + Wallabag\ApiBundle\Repository\ClientRepository: ~ - Wallabag\CoreBundle\Repository\SiteCredentialRepository: - factory: [ "@doctrine.orm.default_entity_manager", getRepository ] - arguments: - - 'Wallabag\CoreBundle\Entity\SiteCredential' - calls: - - [ setCrypto, [ '@Wallabag\CoreBundle\Helper\CryptoProxy' ] ] + Wallabag\CoreBundle\Repository\ConfigRepository: ~ - Wallabag\CoreBundle\Repository\IgnoreOriginInstanceRuleRepository: - factory: [ "@doctrine.orm.default_entity_manager", getRepository ] - arguments: - - 'Wallabag\CoreBundle\Entity\IgnoreOriginInstanceRule' + Wallabag\CoreBundle\Repository\EntryRepository: ~ + + Wallabag\CoreBundle\Repository\TagRepository: ~ + + Wallabag\CoreBundle\Repository\TaggingRuleRepository: ~ + + Wallabag\CoreBundle\Repository\SiteCredentialRepository: ~ + + Wallabag\CoreBundle\Repository\IgnoreOriginInstanceRuleRepository: ~ + + Wallabag\CoreBundle\Repository\IgnoreOriginUserRuleRepository: ~ Wallabag\CoreBundle\Helper\EntriesExport: arguments: @@ -209,10 +205,7 @@ services: Wallabag\UserBundle\EventListener\PasswordResettingListener: ~ - Wallabag\UserBundle\Repository\UserRepository: - factory: [ "@doctrine.orm.default_entity_manager", getRepository ] - arguments: - - 'Wallabag\UserBundle\Entity\User' + Wallabag\UserBundle\Repository\UserRepository: ~ Wallabag\UserBundle\EventListener\CreateConfigListener: arguments: diff --git a/src/Wallabag/AnnotationBundle/Repository/AnnotationRepository.php b/src/Wallabag/AnnotationBundle/Repository/AnnotationRepository.php index 0de5c934e..59c17e447 100644 --- a/src/Wallabag/AnnotationBundle/Repository/AnnotationRepository.php +++ b/src/Wallabag/AnnotationBundle/Repository/AnnotationRepository.php @@ -2,15 +2,21 @@ namespace Wallabag\AnnotationBundle\Repository; -use Doctrine\ORM\EntityRepository; +use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository; use Doctrine\ORM\QueryBuilder; +use Doctrine\Persistence\ManagerRegistry; use Wallabag\AnnotationBundle\Entity\Annotation; /** * AnnotationRepository. */ -class AnnotationRepository extends EntityRepository +class AnnotationRepository extends ServiceEntityRepository { + public function __construct(ManagerRegistry $registry) + { + parent::__construct($registry, Annotation::class); + } + /** * Retrieves all annotations for a user. * diff --git a/src/Wallabag/ApiBundle/Repository/ClientRepository.php b/src/Wallabag/ApiBundle/Repository/ClientRepository.php index fc14262e2..1c00e1645 100644 --- a/src/Wallabag/ApiBundle/Repository/ClientRepository.php +++ b/src/Wallabag/ApiBundle/Repository/ClientRepository.php @@ -2,10 +2,17 @@ namespace Wallabag\ApiBundle\Repository; -use Doctrine\ORM\EntityRepository; +use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository; +use Doctrine\Persistence\ManagerRegistry; +use Wallabag\ApiBundle\Entity\Client; -class ClientRepository extends EntityRepository +class ClientRepository extends ServiceEntityRepository { + public function __construct(ManagerRegistry $registry) + { + parent::__construct($registry, Client::class); + } + public function findOneBy(array $criteria, array $orderBy = null) { if (!empty($criteria['id'])) { diff --git a/src/Wallabag/CoreBundle/Repository/ConfigRepository.php b/src/Wallabag/CoreBundle/Repository/ConfigRepository.php index b2b1f627a..c09aabd19 100644 --- a/src/Wallabag/CoreBundle/Repository/ConfigRepository.php +++ b/src/Wallabag/CoreBundle/Repository/ConfigRepository.php @@ -2,8 +2,14 @@ namespace Wallabag\CoreBundle\Repository; -use Doctrine\ORM\EntityRepository; +use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository; +use Doctrine\Persistence\ManagerRegistry; +use Wallabag\CoreBundle\Entity\Config; -class ConfigRepository extends EntityRepository +class ConfigRepository extends ServiceEntityRepository { + public function __construct(ManagerRegistry $registry) + { + parent::__construct($registry, Config::class); + } } diff --git a/src/Wallabag/CoreBundle/Repository/EntryRepository.php b/src/Wallabag/CoreBundle/Repository/EntryRepository.php index 7d400b7dc..4874f2790 100644 --- a/src/Wallabag/CoreBundle/Repository/EntryRepository.php +++ b/src/Wallabag/CoreBundle/Repository/EntryRepository.php @@ -2,17 +2,23 @@ namespace Wallabag\CoreBundle\Repository; -use Doctrine\ORM\EntityRepository; +use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository; use Doctrine\ORM\NoResultException; use Doctrine\ORM\QueryBuilder; +use Doctrine\Persistence\ManagerRegistry; use Pagerfanta\Doctrine\ORM\QueryAdapter as DoctrineORMAdapter; use Pagerfanta\Pagerfanta; use Wallabag\CoreBundle\Entity\Entry; use Wallabag\CoreBundle\Entity\Tag; use Wallabag\CoreBundle\Helper\UrlHasher; -class EntryRepository extends EntityRepository +class EntryRepository extends ServiceEntityRepository { + public function __construct(ManagerRegistry $registry) + { + parent::__construct($registry, Entry::class); + } + /** * Retrieves all entries for a user. * diff --git a/src/Wallabag/CoreBundle/Repository/IgnoreOriginInstanceRuleRepository.php b/src/Wallabag/CoreBundle/Repository/IgnoreOriginInstanceRuleRepository.php index 708a0edee..ccf321174 100644 --- a/src/Wallabag/CoreBundle/Repository/IgnoreOriginInstanceRuleRepository.php +++ b/src/Wallabag/CoreBundle/Repository/IgnoreOriginInstanceRuleRepository.php @@ -2,8 +2,14 @@ namespace Wallabag\CoreBundle\Repository; -use Doctrine\ORM\EntityRepository; +use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository; +use Doctrine\Persistence\ManagerRegistry; +use Wallabag\CoreBundle\Entity\IgnoreOriginInstanceRule; -class IgnoreOriginInstanceRuleRepository extends EntityRepository +class IgnoreOriginInstanceRuleRepository extends ServiceEntityRepository { + public function __construct(ManagerRegistry $registry) + { + parent::__construct($registry, IgnoreOriginInstanceRule::class); + } } diff --git a/src/Wallabag/CoreBundle/Repository/IgnoreOriginUserRuleRepository.php b/src/Wallabag/CoreBundle/Repository/IgnoreOriginUserRuleRepository.php index 8aa4c2652..f41c5b7b4 100644 --- a/src/Wallabag/CoreBundle/Repository/IgnoreOriginUserRuleRepository.php +++ b/src/Wallabag/CoreBundle/Repository/IgnoreOriginUserRuleRepository.php @@ -2,8 +2,14 @@ namespace Wallabag\CoreBundle\Repository; -use Doctrine\ORM\EntityRepository; +use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository; +use Doctrine\Persistence\ManagerRegistry; +use Wallabag\CoreBundle\Entity\IgnoreOriginUserRule; -class IgnoreOriginUserRuleRepository extends EntityRepository +class IgnoreOriginUserRuleRepository extends ServiceEntityRepository { + public function __construct(ManagerRegistry $registry) + { + parent::__construct($registry, IgnoreOriginUserRule::class); + } } diff --git a/src/Wallabag/CoreBundle/Repository/SiteCredentialRepository.php b/src/Wallabag/CoreBundle/Repository/SiteCredentialRepository.php index aeadd7704..0c2ad6fb5 100644 --- a/src/Wallabag/CoreBundle/Repository/SiteCredentialRepository.php +++ b/src/Wallabag/CoreBundle/Repository/SiteCredentialRepository.php @@ -2,17 +2,22 @@ namespace Wallabag\CoreBundle\Repository; +use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository; +use Doctrine\Persistence\ManagerRegistry; +use Wallabag\CoreBundle\Entity\SiteCredential; use Wallabag\CoreBundle\Helper\CryptoProxy; /** * SiteCredentialRepository. */ -class SiteCredentialRepository extends \Doctrine\ORM\EntityRepository +class SiteCredentialRepository extends ServiceEntityRepository { private $cryptoProxy; - public function setCrypto(CryptoProxy $cryptoProxy) + public function __construct(ManagerRegistry $registry, CryptoProxy $cryptoProxy) { + parent::__construct($registry, SiteCredential::class); + $this->cryptoProxy = $cryptoProxy; } diff --git a/src/Wallabag/CoreBundle/Repository/TagRepository.php b/src/Wallabag/CoreBundle/Repository/TagRepository.php index 3e64f8b26..ffa2c0b36 100644 --- a/src/Wallabag/CoreBundle/Repository/TagRepository.php +++ b/src/Wallabag/CoreBundle/Repository/TagRepository.php @@ -2,12 +2,18 @@ namespace Wallabag\CoreBundle\Repository; -use Doctrine\ORM\EntityRepository; +use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository; use Doctrine\ORM\QueryBuilder; +use Doctrine\Persistence\ManagerRegistry; use Wallabag\CoreBundle\Entity\Tag; -class TagRepository extends EntityRepository +class TagRepository extends ServiceEntityRepository { + public function __construct(ManagerRegistry $registry) + { + parent::__construct($registry, Tag::class); + } + /** * Count all tags per user. * diff --git a/src/Wallabag/CoreBundle/Repository/TaggingRuleRepository.php b/src/Wallabag/CoreBundle/Repository/TaggingRuleRepository.php index de3807388..3f38dc85d 100644 --- a/src/Wallabag/CoreBundle/Repository/TaggingRuleRepository.php +++ b/src/Wallabag/CoreBundle/Repository/TaggingRuleRepository.php @@ -2,8 +2,14 @@ namespace Wallabag\CoreBundle\Repository; -use Doctrine\ORM\EntityRepository; +use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository; +use Doctrine\Persistence\ManagerRegistry; +use Wallabag\CoreBundle\Entity\TaggingRule; -class TaggingRuleRepository extends EntityRepository +class TaggingRuleRepository extends ServiceEntityRepository { + public function __construct(ManagerRegistry $registry) + { + parent::__construct($registry, TaggingRule::class); + } } diff --git a/src/Wallabag/UserBundle/Repository/UserRepository.php b/src/Wallabag/UserBundle/Repository/UserRepository.php index 4abd55f15..b4333b993 100644 --- a/src/Wallabag/UserBundle/Repository/UserRepository.php +++ b/src/Wallabag/UserBundle/Repository/UserRepository.php @@ -2,12 +2,18 @@ namespace Wallabag\UserBundle\Repository; -use Doctrine\ORM\EntityRepository; +use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository; use Doctrine\ORM\QueryBuilder; +use Doctrine\Persistence\ManagerRegistry; use Wallabag\UserBundle\Entity\User; -class UserRepository extends EntityRepository +class UserRepository extends ServiceEntityRepository { + public function __construct(ManagerRegistry $registry) + { + parent::__construct($registry, User::class); + } + /** * Find a user by its username and Feed token. *