Skip to content

Commit 258a42d

Browse files
authored
Refactor de l'injection de certaines anciennes classes (#1939)
Il y avait plusieurs façons de les injecter (constructeur ou factory à injecter). Ces classes doivent maintenant toujours passer par l'injection dans le constructeur.
1 parent 937e899 commit 258a42d

File tree

8 files changed

+48
-104
lines changed

8 files changed

+48
-104
lines changed

app/config/services.yml

Lines changed: 14 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -120,9 +120,6 @@ services:
120120
$mailchimp: '@app.mailchimp_api'
121121
$listId: "%mailchimp_members_list%"
122122

123-
Afup\Site\Utils\Configuration:
124-
autowire: true
125-
126123
AppBundle\Email\Mailer\Adapter\MailerAdapter:
127124
class: AppBundle\Email\Mailer\Adapter\PhpMailerAdapter
128125
factory: [AppBundle\Email\Mailer\Adapter\PhpMailerAdapter, createFromConfiguration]
@@ -143,33 +140,31 @@ services:
143140
autowire: true
144141
arguments: ["%qr_code_salt%"]
145142

143+
Afup\Site\Utils\Configuration:
144+
autowire: true
145+
146+
Afup\Site\Utils\LegacyConnectionFactory: ~
147+
Afup\Site\Utils\Base_De_Donnees:
148+
factory: '@Afup\Site\Utils\LegacyConnectionFactory'
149+
146150
Afup\Site\Forum\AppelConferencier:
147-
class: Afup\Site\Forum\AppelConferencier
148-
factory: ['@AppBundle\LegacyModelFactory', 'createObject']
149-
arguments:
150-
- 'Afup\Site\Forum\AppelConferencier'
151+
autowire: true
151152

152153
Afup\Site\Forum\Forum:
153-
class: Afup\Site\Forum\Forum
154-
factory: ['@AppBundle\LegacyModelFactory', 'createObject']
155-
arguments:
156-
- 'Afup\Site\Forum\Forum'
154+
autowire: true
157155

158156
Afup\Site\Utils\Pays:
159-
class: Afup\Site\Utils\Pays
160-
factory: ['@AppBundle\LegacyModelFactory', 'createObject']
161-
arguments:
162-
- 'Afup\Site\Utils\Pays'
157+
autowire: true
163158

164159
Afup\Site\Forum\Inscriptions:
165-
class: Afup\Site\Forum\Inscriptions
166-
factory: ['@AppBundle\LegacyModelFactory', 'createObject']
167-
arguments:
168-
- 'Afup\Site\Forum\Inscriptions'
160+
autowire: true
169161

170162
Afup\Site\Association\CotisationsFactory:
171163
autowire: true
172164

165+
Afup\Site\Forum\Facturation:
166+
autowire: true
167+
173168
Afup\Site\Association\Cotisations:
174169
factory: ['@Afup\Site\Association\CotisationsFactory', 'create']
175170

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Afup\Site\Utils;
6+
7+
final class LegacyConnectionFactory
8+
{
9+
private Base_De_Donnees $bdd;
10+
11+
public function __invoke(): Base_De_Donnees
12+
{
13+
if (!isset($this->bdd)) {
14+
if (isset($GLOBALS['AFUP_DB']) === false) {
15+
throw new \RuntimeException('Could not find the legacy database connexion');
16+
}
17+
18+
$this->bdd = $GLOBALS['AFUP_DB'];
19+
}
20+
21+
return $this->bdd;
22+
}
23+
}

sources/AppBundle/Controller/Admin/Event/PendingBankwiresAction.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
use AppBundle\Event\Model\Repository\InvoiceRepository;
1515
use AppBundle\Event\Model\Repository\TicketRepository;
1616
use AppBundle\Event\Model\Ticket;
17-
use AppBundle\LegacyModelFactory;
1817
use DateTime;
1918
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
2019
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
@@ -30,11 +29,11 @@ public function __construct(
3029
private readonly EventActionHelper $eventActionHelper,
3130
private readonly InvoiceRepository $invoiceRepository,
3231
private readonly TicketRepository $ticketRepository,
33-
private readonly LegacyModelFactory $legacyModelFactory,
3432
private readonly Emails $emails,
3533
private readonly EventDispatcherInterface $eventDispatcher,
3634
private readonly CsrfTokenManagerInterface $csrfTokenManager,
3735
private readonly EventSelectFactory $eventSelectFactory,
36+
private readonly Facturation $facturation,
3837
) {}
3938

4039
public function __invoke(Request $request): Response
@@ -74,8 +73,7 @@ private function setInvoicePaid(Event $event, Invoice $invoice): void
7473
$this->invoiceRepository->save($invoice);
7574
$tickets = $this->ticketRepository->getByReference($invoice->getReference());
7675

77-
$forumFacturation = $this->legacyModelFactory->createObject(Facturation::class);
78-
$forumFacturation->envoyerFacture($invoice->getReference());
76+
$this->facturation->envoyerFacture($invoice->getReference());
7977
$this->addFlash('notice', sprintf('La facture %s a été marquée comme payée', $invoice->getReference()));
8078

8179
foreach ($tickets as $ticket) {

sources/AppBundle/Controller/Admin/Event/StatsAction.php

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,7 @@
99
use AppBundle\Event\Form\EventCompareSelectType;
1010
use AppBundle\Event\Model\Repository\EventRepository;
1111
use AppBundle\Event\Model\Repository\EventStatsRepository;
12-
use AppBundle\Event\Model\Repository\TicketRepository;
1312
use AppBundle\Event\Model\Repository\TicketTypeRepository;
14-
use AppBundle\LegacyModelFactory;
1513
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
1614
use Symfony\Component\HttpFoundation\Request;
1715
use Symfony\Component\HttpFoundation\Response;
@@ -20,11 +18,10 @@ class StatsAction extends AbstractController
2018
{
2119
public function __construct(
2220
private readonly EventActionHelper $eventActionHelper,
23-
private readonly LegacyModelFactory $legacyModelFactory,
24-
private readonly TicketRepository $ticketRepository,
2521
private readonly TicketTypeRepository $ticketTypeRepository,
2622
private readonly EventStatsRepository $eventStatsRepository,
2723
private readonly EventRepository $eventRepository,
24+
private readonly Inscriptions $inscriptions,
2825
) {}
2926

3027
public function __invoke(Request $request): Response
@@ -43,8 +40,7 @@ public function __invoke(Request $request): Response
4340
'events' => $this->eventRepository->getAll(),
4441
]);
4542

46-
$legacyInscriptions = $this->legacyModelFactory->createObject(Inscriptions::class);
47-
$stats = $legacyInscriptions->obtenirSuivi($event->getId(), $comparedEvent->getId());
43+
$stats = $this->inscriptions->obtenirSuivi($event->getId(), $comparedEvent->getId());
4844
$ticketTypes = [];
4945

5046
$chart = [

sources/AppBundle/Controller/Event/Ticket/PayboxCallbackAction.php

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
use AppBundle\Event\Model\Repository\InvoiceRepository;
1212
use AppBundle\Event\Model\Repository\TicketRepository;
1313
use AppBundle\Event\Model\Ticket;
14-
use AppBundle\LegacyModelFactory;
1514
use AppBundle\Payment\PayboxResponse;
1615
use AppBundle\Payment\PayboxResponseFactory;
1716
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
@@ -29,9 +28,9 @@ public function __construct(
2928
private readonly EventDispatcherInterface $eventDispatcher,
3029
private readonly Emails $emails,
3130
private readonly InvoiceRepository $invoiceRepository,
32-
private readonly LegacyModelFactory $legacyModelFactory,
3331
private readonly TicketRepository $ticketRepository,
3432
private readonly EventActionHelper $eventActionHelper,
33+
private readonly Facturation $facturation,
3534
) {}
3635

3736
public function __invoke(string $eventSlug, Request $request): Response
@@ -68,11 +67,7 @@ public function __invoke(string $eventSlug, Request $request): Response
6867
$tickets = $this->ticketRepository->getByReference($invoice->getReference());
6968

7069
if ($paymentStatus === Ticket::STATUS_PAID) {
71-
/**
72-
* @var Facturation $forumFacturation
73-
*/
74-
$forumFacturation = $this->legacyModelFactory->createObject(Facturation::class);
75-
$forumFacturation->envoyerFacture($invoice->getReference());
70+
$this->facturation->envoyerFacture($invoice->getReference());
7671
}
7772

7873
foreach ($tickets as $ticket) {

sources/AppBundle/Controller/Event/Ticket/PaymentAction.php

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
use AppBundle\Event\Model\Repository\InvoiceRepository;
1515
use AppBundle\Event\Model\Repository\TicketRepository;
1616
use AppBundle\Event\Model\Ticket;
17-
use AppBundle\LegacyModelFactory;
1817
use AppBundle\Payment\PayboxFactory;
1918
use Psr\Log\LoggerInterface;
2019
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
@@ -30,10 +29,10 @@ public function __construct(
3029
private readonly LoggerInterface $logger,
3130
private readonly Emails $emails,
3231
private readonly InvoiceRepository $invoiceRepository,
33-
private readonly LegacyModelFactory $legacyModelFactory,
3432
private readonly TicketRepository $ticketRepository,
3533
private readonly PayboxFactory $payboxFactory,
3634
private readonly EventActionHelper $eventActionHelper,
35+
private readonly Facturation $facturation,
3736
) {}
3837

3938
public function __invoke($eventSlug, Request $request): Response
@@ -80,8 +79,7 @@ public function __invoke($eventSlug, Request $request): Response
8079

8180
$invoiceRepository->save($invoice);
8281

83-
$forumFacturation = $this->legacyModelFactory->createObject(Facturation::class);
84-
$forumFacturation->envoyerFacture($invoice->getReference());
82+
$this->facturation->envoyerFacture($invoice->getReference());
8583

8684
$ticketRepository = $this->ticketRepository;
8785
$tickets = $ticketRepository->getByInvoiceWithDetail($invoice);
@@ -104,8 +102,7 @@ public function __invoke($eventSlug, Request $request): Response
104102
$params['bankAccount'] = $bankAccountFactory->createApplyableAt($invoice->getinvoiceDate());
105103

106104
// For bankwire, companies need to retrieve the invoice
107-
$forumFacturation = $this->legacyModelFactory->createObject(Facturation::class);
108-
$forumFacturation->envoyerFacture($invoiceRef);
105+
$this->facturation->envoyerFacture($invoiceRef);
109106
}
110107

111108
return $this->render('event/ticket/payment.html.twig', $params);

sources/AppBundle/Controller/Event/Ticket/TicketAction.php

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
use AppBundle\Event\Model\Repository\TicketRepository;
1616
use AppBundle\Event\Model\Ticket;
1717
use AppBundle\Event\Ticket\PurchaseTypeFactory;
18-
use AppBundle\LegacyModelFactory;
1918
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
2019
use Symfony\Component\HttpFoundation\Request;
2120
use Symfony\Component\HttpFoundation\Response;
@@ -25,10 +24,10 @@ final class TicketAction extends AbstractController
2524
public function __construct(
2625
private readonly PurchaseTypeFactory $purchaseTypeFactory,
2726
private readonly InvoiceRepository $invoiceRepository,
28-
private readonly LegacyModelFactory $legacyModelFactory,
2927
private readonly TicketRepository $ticketRepository,
3028
private readonly EventActionHelper $eventActionHelper,
3129
private readonly TicketEventTypeRepository $ticketEventTypeRepository,
30+
private readonly Facturation $facturation,
3231
) {}
3332

3433
public function __invoke($eventSlug, Request $request): Response
@@ -86,10 +85,7 @@ public function __invoke($eventSlug, Request $request): Response
8685

8786
$invoice->setTickets($tickets);
8887

89-
/**
90-
* @todo: voir où le mettre ça
91-
*/
92-
$reference = $this->legacyModelFactory->createObject(Facturation::class)->creerReference($event->getId(), $invoice->getLabel());
88+
$reference = $this->facturation->creerReference($event->getId(), $invoice->getLabel());
9389
$invoice->setReference($reference);
9490
$invoiceRepository->saveWithTickets($invoice);
9591

sources/AppBundle/LegacyModelFactory.php

Lines changed: 0 additions & 56 deletions
This file was deleted.

0 commit comments

Comments
 (0)