Skip to content

Commit a6d71e8

Browse files
committed
Fix: inject logger in services instead of using $this->get() in controller
1 parent ec01166 commit a6d71e8

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

Controller/PaymentGatewayController.php

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,21 +21,20 @@ class PaymentGatewayController extends AbstractController
2121
*/
2222
private $paymentManager;
2323

24-
public function __construct(PaymentManager $paymentManager)
24+
public function __construct(PaymentManager $paymentManager, Logger $logger)
2525
{
2626
$this->paymentManager = $paymentManager;
27+
$this->logger = $logger;
2728
}
2829

2930
/**
3031
* @Route("/{configuration_alias}/callback", name="idci_payment_payment_gateway_callback", methods={"GET", "POST"})
3132
*/
3233
public function callbackAction(Request $request, EventDispatcherInterface $dispatcher, $configuration_alias)
3334
{
34-
$logger = $this->container->get('monolog.logger.payment');
35-
3635
$data = $request->isMethod(Request::METHOD_POST) ? $request->request->all() : $request->query->all();
3736

38-
$logger->info(
37+
$this->logger->info(
3938
sprintf(
4039
'[gateway configuration alias: %s, data: %s, ip: %s]',
4140
$configuration_alias,

Resources/config/services.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,11 @@ services:
99
resource: '../../*'
1010
exclude: '../../{Entity,Repository,Tests,Event/Subscriber}'
1111

12+
# Controller
13+
IDCI\Bundle\PaymentBundle\Controller\PaymentGatewayController:
14+
arguments:
15+
$logger: '@monolog.logger.payment'
16+
1217
# Manager
1318
Doctrine\Common\Persistence\ObjectManager: null
1419

0 commit comments

Comments
 (0)