Use FQCN as service name for repositories

This commit is contained in:
Yassine Guedidi 2022-04-24 17:58:57 +02:00
parent 844e8e9d22
commit 0f9c359476
17 changed files with 68 additions and 50 deletions

View file

@ -11,8 +11,8 @@ services:
class: Wallabag\CoreBundle\Twig\WallabagExtension
public: false
arguments:
- "@wallabag_core.entry_repository"
- "@wallabag_core.tag_repository"
- '@Wallabag\CoreBundle\Repository\EntryRepository'
- '@Wallabag\CoreBundle\Repository\TagRepository'
- "@security.token_storage"
- "%wallabag_core.cache_lifetime%"
- "@translator"

View file

@ -9,7 +9,7 @@ services:
public: true
wallabag_core.entry_repository.test:
alias: wallabag_core.entry_repository
alias: Wallabag\CoreBundle\Repository\EntryRepository
public: true
wallabag_user.user_repository.test:

View file

@ -18,6 +18,7 @@ use Wallabag\CoreBundle\Helper\ContentProxy;
use Wallabag\CoreBundle\Helper\EntriesExport;
use Wallabag\CoreBundle\Helper\TagsAssigner;
use Wallabag\CoreBundle\Helper\UrlHasher;
use Wallabag\CoreBundle\Repository\EntryRepository;
class EntryRestController extends WallabagRestController
{
@ -138,7 +139,7 @@ class EntryRestController extends WallabagRestController
try {
/** @var \Pagerfanta\Pagerfanta $pager */
$pager = $this->get('wallabag_core.entry_repository')->findEntries(
$pager = $this->get(EntryRepository::class)->findEntries(
$this->getUser()->getId(),
$isArchived,
$isStarred,
@ -247,7 +248,7 @@ class EntryRestController extends WallabagRestController
// handle multiple urls
foreach ($urls as $key => $url) {
$entry = $this->get('wallabag_core.entry_repository')->findByUrlAndUserId(
$entry = $this->get(EntryRepository::class)->findByUrlAndUserId(
$url,
$this->getUser()->getId()
);
@ -301,7 +302,7 @@ class EntryRestController extends WallabagRestController
// handle multiple urls
foreach ($urls as $key => $url) {
$entry = $this->get('wallabag_core.entry_repository')->findByUrlAndUserId(
$entry = $this->get(EntryRepository::class)->findByUrlAndUserId(
$url,
$this->getUser()->getId()
);
@ -358,7 +359,7 @@ class EntryRestController extends WallabagRestController
$url = $request->request->get('url');
$entry = $this->get('wallabag_core.entry_repository')->findByUrlAndUserId(
$entry = $this->get(EntryRepository::class)->findByUrlAndUserId(
$url,
$this->getUser()->getId()
);
@ -736,7 +737,7 @@ class EntryRestController extends WallabagRestController
$results = [];
foreach ($list as $key => $element) {
$entry = $this->get('wallabag_core.entry_repository')->findByUrlAndUserId(
$entry = $this->get(EntryRepository::class)->findByUrlAndUserId(
$element->url,
$this->getUser()->getId()
);
@ -794,7 +795,7 @@ class EntryRestController extends WallabagRestController
// handle multiple urls
foreach ($list as $key => $element) {
$entry = $this->get('wallabag_core.entry_repository')->findByUrlAndUserId(
$entry = $this->get(EntryRepository::class)->findByUrlAndUserId(
$element->url,
$this->getUser()->getId()
);

View file

@ -9,6 +9,7 @@ use Pagerfanta\Doctrine\ORM\QueryAdapter as DoctrineORMAdapter;
use Pagerfanta\Pagerfanta;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Request;
use Wallabag\CoreBundle\Repository\EntryRepository;
class SearchRestController extends WallabagRestController
{
@ -33,7 +34,7 @@ class SearchRestController extends WallabagRestController
$page = (int) $request->query->get('page', 1);
$perPage = (int) $request->query->get('perPage', 30);
$qb = $this->get('wallabag_core.entry_repository')
$qb = $this->get(EntryRepository::class)
->getBuilderForSearchByUser(
$this->getUser()->getId(),
$term,

View file

@ -9,6 +9,7 @@ use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Style\SymfonyStyle;
use Symfony\Component\Finder\Finder;
use Wallabag\CoreBundle\Helper\DownloadImages;
use Wallabag\CoreBundle\Repository\EntryRepository;
class CleanDownloadedImagesCommand extends ContainerAwareCommand
{
@ -57,7 +58,7 @@ class CleanDownloadedImagesCommand extends ContainerAwareCommand
$io->text('Retrieve valid folders attached to a user');
$entries = $this->getContainer()->get('wallabag_core.entry_repository')->findAllEntriesIdByUserId();
$entries = $this->getContainer()->get(EntryRepository::class)->findAllEntriesIdByUserId();
// retrieve _valid_ folders from existing entries
$validPaths = [];

View file

@ -9,6 +9,7 @@ use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Style\SymfonyStyle;
use Wallabag\CoreBundle\Entity\Entry;
use Wallabag\CoreBundle\Repository\EntryRepository;
use Wallabag\UserBundle\Entity\User;
use Wallabag\UserBundle\Repository\UserRepository;
@ -67,7 +68,7 @@ class CleanDuplicatesCommand extends ContainerAwareCommand
private function cleanDuplicates(User $user)
{
$em = $this->getContainer()->get('doctrine.orm.entity_manager');
$repo = $this->getContainer()->get('wallabag_core.entry_repository');
$repo = $this->getContainer()->get(EntryRepository::class);
$entries = $repo->findAllEntriesIdAndUrlByUserId($user->getId());

View file

@ -9,6 +9,7 @@ use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Style\SymfonyStyle;
use Wallabag\CoreBundle\Helper\EntriesExport;
use Wallabag\CoreBundle\Repository\EntryRepository;
use Wallabag\UserBundle\Repository\UserRepository;
class ExportCommand extends ContainerAwareCommand
@ -44,7 +45,7 @@ class ExportCommand extends ContainerAwareCommand
return 1;
}
$entries = $this->getContainer()->get('wallabag_core.entry_repository')
$entries = $this->getContainer()->get(EntryRepository::class)
->getBuilderForAllByUser($user->getId())
->getQuery()
->getResult();

View file

@ -10,6 +10,7 @@ use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Style\SymfonyStyle;
use Wallabag\CoreBundle\Event\EntrySavedEvent;
use Wallabag\CoreBundle\Helper\ContentProxy;
use Wallabag\CoreBundle\Repository\EntryRepository;
use Wallabag\UserBundle\Repository\UserRepository;
class ReloadEntryCommand extends ContainerAwareCommand
@ -42,7 +43,7 @@ class ReloadEntryCommand extends ContainerAwareCommand
}
}
$entryRepository = $this->getContainer()->get('wallabag_core.entry_repository');
$entryRepository = $this->getContainer()->get(EntryRepository::class);
$entryIds = $entryRepository->findAllEntriesIdByUserId($userId);
$nbEntries = \count($entryIds);

View file

@ -24,6 +24,8 @@ use Wallabag\CoreBundle\Form\Type\IgnoreOriginUserRuleType;
use Wallabag\CoreBundle\Form\Type\TaggingRuleImportType;
use Wallabag\CoreBundle\Form\Type\TaggingRuleType;
use Wallabag\CoreBundle\Form\Type\UserInformationType;
use Wallabag\CoreBundle\Repository\EntryRepository;
use Wallabag\CoreBundle\Repository\TagRepository;
use Wallabag\CoreBundle\Tools\Utils;
use Wallabag\UserBundle\Repository\UserRepository;
@ -562,7 +564,7 @@ class ConfigController extends Controller
// manually remove tags to avoid orphan tag
$this->removeAllTagsByUserId($this->getUser()->getId());
$this->get('wallabag_core.entry_repository')->removeAllByUserId($this->getUser()->getId());
$this->get(EntryRepository::class)->removeAllByUserId($this->getUser()->getId());
break;
case 'archived':
if ($this->get('doctrine')->getConnection()->getDatabasePlatform() instanceof \Doctrine\DBAL\Platforms\SqlitePlatform) {
@ -572,7 +574,7 @@ class ConfigController extends Controller
// manually remove tags to avoid orphan tag
$this->removeTagsForArchivedByUserId($this->getUser()->getId());
$this->get('wallabag_core.entry_repository')->removeArchivedByUserId($this->getUser()->getId());
$this->get(EntryRepository::class)->removeArchivedByUserId($this->getUser()->getId());
break;
}
@ -691,7 +693,7 @@ class ConfigController extends Controller
return;
}
$this->get('wallabag_core.entry_repository')
$this->get(EntryRepository::class)
->removeTags($userId, $tags);
// cleanup orphan tags
@ -713,7 +715,7 @@ class ConfigController extends Controller
*/
private function removeAllTagsByUserId($userId)
{
$tags = $this->get('wallabag_core.tag_repository')->findAllTags($userId);
$tags = $this->get(TagRepository::class)->findAllTags($userId);
$this->removeAllTagsByStatusAndUserId($tags, $userId);
}
@ -724,7 +726,7 @@ class ConfigController extends Controller
*/
private function removeTagsForArchivedByUserId($userId)
{
$tags = $this->get('wallabag_core.tag_repository')->findForArchivedArticlesByUser($userId);
$tags = $this->get(TagRepository::class)->findForArchivedArticlesByUser($userId);
$this->removeAllTagsByStatusAndUserId($tags, $userId);
}

View file

@ -21,6 +21,8 @@ use Wallabag\CoreBundle\Form\Type\SearchEntryType;
use Wallabag\CoreBundle\Helper\ContentProxy;
use Wallabag\CoreBundle\Helper\PreparePagerForEntries;
use Wallabag\CoreBundle\Helper\Redirect;
use Wallabag\CoreBundle\Repository\EntryRepository;
use Wallabag\CoreBundle\Repository\TagRepository;
class EntryController extends Controller
{
@ -58,7 +60,7 @@ class EntryController extends Controller
$label = substr($label, 1);
$remove = true;
}
$tag = $this->get('wallabag_core.tag_repository')->findOneByLabel($label);
$tag = $this->get(TagRepository::class)->findOneByLabel($label);
if ($remove) {
if (null !== $tag) {
$tagsToRemove[] = $tag;
@ -77,7 +79,7 @@ class EntryController extends Controller
if (isset($values['entry-checkbox'])) {
foreach ($values['entry-checkbox'] as $id) {
/** @var Entry * */
$entry = $this->get('wallabag_core.entry_repository')->findById((int) $id)[0];
$entry = $this->get(EntryRepository::class)->findById((int) $id)[0];
$this->checkUserAction($entry);
@ -272,7 +274,7 @@ class EntryController extends Controller
public function showUnreadAction(Request $request, $page)
{
// load the quickstart if no entry in database
if (1 === (int) $page && 0 === $this->get('wallabag_core.entry_repository')->countAllEntriesByUser($this->getUser()->getId())) {
if (1 === (int) $page && 0 === $this->get(EntryRepository::class)->countAllEntriesByUser($this->getUser()->getId())) {
return $this->redirect($this->generateUrl('quickstart'));
}
@ -347,7 +349,7 @@ class EntryController extends Controller
public function redirectRandomEntryAction($type = 'all')
{
try {
$entry = $this->get('wallabag_core.entry_repository')
$entry = $this->get(EntryRepository::class)
->getRandomEntry($this->getUser()->getId(), $type);
} catch (NoResultException $e) {
$bag = $this->get('session')->getFlashBag();
@ -600,7 +602,7 @@ class EntryController extends Controller
*/
private function showEntries($type, Request $request, $page)
{
$repository = $this->get('wallabag_core.entry_repository');
$repository = $this->get(EntryRepository::class);
$searchTerm = (isset($request->get('search_entry')['term']) ? $request->get('search_entry')['term'] : '');
$currentRoute = (null !== $request->query->get('currentRoute') ? $request->query->get('currentRoute') : '');
@ -660,7 +662,7 @@ class EntryController extends Controller
}
}
$nbEntriesUntagged = $this->get('wallabag_core.entry_repository')
$nbEntriesUntagged = $this->get(EntryRepository::class)
->countUntaggedEntriesByUser($this->getUser()->getId());
return $this->render(
@ -724,6 +726,6 @@ class EntryController extends Controller
*/
private function checkIfEntryAlreadyExists(Entry $entry)
{
return $this->get('wallabag_core.entry_repository')->findByUrlAndUserId($entry->getUrl(), $this->getUser()->getId());
return $this->get(EntryRepository::class)->findByUrlAndUserId($entry->getUrl(), $this->getUser()->getId());
}
}

View file

@ -8,6 +8,8 @@ use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
use Symfony\Component\Routing\Annotation\Route;
use Wallabag\CoreBundle\Entity\Entry;
use Wallabag\CoreBundle\Helper\EntriesExport;
use Wallabag\CoreBundle\Repository\EntryRepository;
use Wallabag\CoreBundle\Repository\TagRepository;
/**
* The try/catch can be removed once all formats will be implemented.
@ -57,11 +59,11 @@ class ExportController extends Controller
{
$method = ucfirst($category);
$methodBuilder = 'getBuilderFor' . $method . 'ByUser';
$repository = $this->get('wallabag_core.entry_repository');
$repository = $this->get(EntryRepository::class);
$title = $method;
if ('tag_entries' === $category) {
$tag = $this->get('wallabag_core.tag_repository')->findOneBySlug($request->query->get('tag'));
$tag = $this->get(TagRepository::class)->findOneBySlug($request->query->get('tag'));
$entries = $repository->findAllByTagId(
$this->getUser()->getId(),

View file

@ -15,6 +15,7 @@ use Symfony\Component\Routing\Annotation\Route;
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
use Wallabag\CoreBundle\Entity\Tag;
use Wallabag\CoreBundle\Helper\PreparePagerForEntries;
use Wallabag\CoreBundle\Repository\EntryRepository;
use Wallabag\UserBundle\Entity\User;
class FeedController extends Controller
@ -114,7 +115,7 @@ class FeedController extends Controller
UrlGeneratorInterface::ABSOLUTE_URL
);
$entriesByTag = $this->get('wallabag_core.entry_repository')->findAllByTagId(
$entriesByTag = $this->get(EntryRepository::class)->findAllByTagId(
$user->getId(),
$tag->getId(),
$sorts[$sort]
@ -185,7 +186,7 @@ class FeedController extends Controller
*/
private function showEntries($type, User $user, $page = 1)
{
$repository = $this->get('wallabag_core.entry_repository');
$repository = $this->get(EntryRepository::class);
switch ($type) {
case 'starred':

View file

@ -6,6 +6,7 @@ use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Routing\Annotation\Route;
use Wallabag\CoreBundle\Entity\IgnoreOriginInstanceRule;
use Wallabag\CoreBundle\Repository\IgnoreOriginInstanceRuleRepository;
/**
* IgnoreOriginInstanceRuleController controller.
@ -21,7 +22,7 @@ class IgnoreOriginInstanceRuleController extends Controller
*/
public function indexAction()
{
$rules = $this->get('wallabag_core.ignore_origin_instance_rule_repository')->findAll();
$rules = $this->get(IgnoreOriginInstanceRuleRepository::class)->findAll();
return $this->render('WallabagCoreBundle:IgnoreOriginInstanceRule:index.html.twig', [
'rules' => $rules,

View file

@ -7,6 +7,7 @@ use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Routing\Annotation\Route;
use Wallabag\CoreBundle\Entity\SiteCredential;
use Wallabag\CoreBundle\Helper\CryptoProxy;
use Wallabag\CoreBundle\Repository\SiteCredentialRepository;
use Wallabag\UserBundle\Entity\User;
/**
@ -25,7 +26,7 @@ class SiteCredentialController extends Controller
{
$this->isSiteCredentialsEnabled();
$credentials = $this->get('wallabag_core.site_credential_repository')->findByUser($this->getUser());
$credentials = $this->get(SiteCredentialRepository::class)->findByUser($this->getUser());
return $this->render('WallabagCoreBundle:SiteCredential:index.html.twig', [
'credentials' => $credentials,

View file

@ -16,6 +16,8 @@ use Wallabag\CoreBundle\Form\Type\RenameTagType;
use Wallabag\CoreBundle\Helper\PreparePagerForEntries;
use Wallabag\CoreBundle\Helper\Redirect;
use Wallabag\CoreBundle\Helper\TagsAssigner;
use Wallabag\CoreBundle\Repository\EntryRepository;
use Wallabag\CoreBundle\Repository\TagRepository;
class TagController extends Controller
{
@ -86,9 +88,9 @@ class TagController extends Controller
*/
public function showTagAction()
{
$tags = $this->get('wallabag_core.tag_repository')
$tags = $this->get(TagRepository::class)
->findAllFlatTagsWithNbEntries($this->getUser()->getId());
$nbEntriesUntagged = $this->get('wallabag_core.entry_repository')
$nbEntriesUntagged = $this->get(EntryRepository::class)
->countUntaggedEntriesByUser($this->getUser()->getId());
$renameForms = [];
@ -113,7 +115,7 @@ class TagController extends Controller
*/
public function showEntriesForTagAction(Tag $tag, $page, Request $request)
{
$entriesByTag = $this->get('wallabag_core.entry_repository')->findAllByTagId(
$entriesByTag = $this->get(EntryRepository::class)->findAllByTagId(
$this->getUser()->getId(),
$tag->getId()
);
@ -165,13 +167,13 @@ class TagController extends Controller
return $this->redirect($redirectUrl);
}
$tagFromRepo = $this->get('wallabag_core.tag_repository')->findOneByLabel($newTag->getLabel());
$tagFromRepo = $this->get(TagRepository::class)->findOneByLabel($newTag->getLabel());
if (null !== $tagFromRepo) {
$newTag = $tagFromRepo;
}
$entries = $this->get('wallabag_core.entry_repository')->findAllByTagId(
$entries = $this->get(EntryRepository::class)->findAllByTagId(
$this->getUser()->getId(),
$tag->getId()
);
@ -207,7 +209,7 @@ class TagController extends Controller
$currentRoute = $request->query->has('currentRoute') ? $request->query->get('currentRoute') : '';
/** @var QueryBuilder $qb */
$qb = $this->get('wallabag_core.entry_repository')->getBuilderForSearchByUser($this->getUser()->getId(), $filter, $currentRoute);
$qb = $this->get(EntryRepository::class)->getBuilderForSearchByUser($this->getUser()->getId(), $filter, $currentRoute);
$em = $this->getDoctrine()->getManager();
$entries = $qb->getQuery()->getResult();
@ -237,7 +239,7 @@ class TagController extends Controller
public function removeTagAction(Tag $tag, Request $request)
{
foreach ($tag->getEntriesByUserId($this->getUser()->getId()) as $entry) {
$this->get('wallabag_core.entry_repository')->removeTag($this->getUser()->getId(), $tag);
$this->get(EntryRepository::class)->removeTag($this->getUser()->getId(), $tag);
}
// remove orphan tag in case no entries are associated to it

View file

@ -17,7 +17,7 @@ services:
Wallabag\CoreBundle\Form\Type\EntryFilterType:
class: Wallabag\CoreBundle\Form\Type\EntryFilterType
arguments:
- "@wallabag_core.entry_repository"
- '@Wallabag\CoreBundle\Repository\EntryRepository'
- "@security.token_storage"
tags:
- { name: form.type }
@ -63,7 +63,7 @@ services:
arguments:
- '@Graby\SiteConfig\ConfigBuilder'
- "@security.token_storage"
- "@wallabag_core.site_credential_repository"
- '@Wallabag\CoreBundle\Repository\SiteCredentialRepository'
- '@logger'
tags:
- { name: monolog.logger, channel: graby }
@ -101,14 +101,14 @@ services:
Wallabag\CoreBundle\Helper\TagsAssigner:
class: Wallabag\CoreBundle\Helper\TagsAssigner
arguments:
- "@wallabag_core.tag_repository"
- '@Wallabag\CoreBundle\Repository\TagRepository'
Wallabag\CoreBundle\Helper\RuleBasedTagger:
class: Wallabag\CoreBundle\Helper\RuleBasedTagger
arguments:
- "@rulerz"
- "@wallabag_core.tag_repository"
- "@wallabag_core.entry_repository"
- '@Wallabag\CoreBundle\Repository\TagRepository'
- '@Wallabag\CoreBundle\Repository\EntryRepository'
- "@logger"
Wallabag\CoreBundle\Helper\RuleBasedIgnoreOriginProcessor:
@ -116,22 +116,22 @@ services:
arguments:
- "@rulerz"
- "@logger"
- "@wallabag_core.ignore_origin_instance_rule_repository"
- '@Wallabag\CoreBundle\Repository\IgnoreOriginInstanceRuleRepository'
# repository as a service
wallabag_core.entry_repository:
Wallabag\CoreBundle\Repository\EntryRepository:
class: Wallabag\CoreBundle\Repository\EntryRepository
factory: [ "@doctrine.orm.default_entity_manager", getRepository ]
arguments:
- WallabagCoreBundle:Entry
wallabag_core.tag_repository:
Wallabag\CoreBundle\Repository\TagRepository:
class: Wallabag\CoreBundle\Repository\TagRepository
factory: [ "@doctrine.orm.default_entity_manager", getRepository ]
arguments:
- WallabagCoreBundle:Tag
wallabag_core.site_credential_repository:
Wallabag\CoreBundle\Repository\SiteCredentialRepository:
class: Wallabag\CoreBundle\Repository\SiteCredentialRepository
factory: [ "@doctrine.orm.default_entity_manager", getRepository ]
arguments:
@ -139,7 +139,7 @@ services:
calls:
- [ setCrypto, [ '@Wallabag\CoreBundle\Helper\CryptoProxy' ] ]
wallabag_core.ignore_origin_instance_rule_repository:
Wallabag\CoreBundle\Repository\IgnoreOriginInstanceRuleRepository:
class: Wallabag\CoreBundle\Repository\IgnoreOriginInstanceRuleRepository
factory: [ "@doctrine.orm.default_entity_manager", getRepository ]
arguments:

View file

@ -9,6 +9,7 @@ use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorage;
use Symfony\Component\Security\Core\Authentication\Token\UsernamePasswordToken;
use Tests\Wallabag\CoreBundle\WallabagCoreTestCase;
use Wallabag\CoreBundle\GuzzleSiteAuthenticator\GrabySiteConfigBuilder;
use Wallabag\CoreBundle\Repository\SiteCredentialRepository;
class GrabySiteConfigBuilderTest extends WallabagCoreTestCase
{
@ -300,7 +301,7 @@ class GrabySiteConfigBuilderTest extends WallabagCoreTestCase
$builder = new GrabySiteConfigBuilder(
$grabyConfigBuilderMock,
$tokenStorage,
$this->getClient()->getContainer()->get('wallabag_core.site_credential_repository'),
$this->getClient()->getContainer()->get(SiteCredentialRepository::class),
$logger
);