Skip to content

Commit

Permalink
Fix: deprecated doctrine ObjectManager
Browse files Browse the repository at this point in the history
  • Loading branch information
BeBlood committed May 13, 2024
1 parent 2e17492 commit e85f2ff
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 19 deletions.
16 changes: 8 additions & 8 deletions Manager/DoctrineTransactionManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,33 +2,33 @@

namespace IDCI\Bundle\PaymentBundle\Manager;

use Doctrine\Common\Persistence\ObjectManager;
use Doctrine\ORM\EntityManagerInterface;
use IDCI\Bundle\PaymentBundle\Entity\Transaction;
use IDCI\Bundle\PaymentBundle\Exception\NoTransactionFoundException;
use IDCI\Bundle\PaymentBundle\Model\Transaction as TransactionModel;

class DoctrineTransactionManager implements TransactionManagerInterface
{
/**
* @var ObjectManager
* @var EntityManagerInterface
*/
private $om;
private $em;

public function __construct(?ObjectManager $om = null)
public function __construct(?EntityManagerInterface $em = null)
{
$this->om = $om;
$this->em = $em;
}

public function saveTransaction(TransactionModel $transaction)
{
$this->om->persist($transaction);
$this->om->flush();
$this->em->persist($transaction);
$this->em->flush();
}

public function retrieveTransactionByUuid(string $transactionUuid): TransactionModel
{
$transaction = $this
->om
->em
->getRepository(Transaction::class)
->findOneBy(['id' => $transactionUuid])
;
Expand Down
21 changes: 13 additions & 8 deletions Manager/PaymentManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace IDCI\Bundle\PaymentBundle\Manager;

use Doctrine\Common\Persistence\ObjectManager;
use Doctrine\ORM\EntityManagerInterface;
use IDCI\Bundle\PaymentBundle\Entity\PaymentGatewayConfiguration;
use IDCI\Bundle\PaymentBundle\Exception\NoPaymentGatewayConfigurationFoundException;
use IDCI\Bundle\PaymentBundle\Gateway\PaymentGatewayRegistryInterface;
Expand All @@ -15,9 +15,9 @@
class PaymentManager
{
/**
* @var ObjectManager
* @var EntityManagerInterface
*/
private $om;
private $em;

/**
* @var PaymentGatewayRegistryInterface
Expand All @@ -34,23 +34,28 @@ class PaymentManager
*/
private $dispatcher;

/**
* @var LoggerInterface
*/
private $logger;

/**
* @var array
*/
private $paymentGatewayConfigurations;

public function __construct(
?ObjectManager $om = null,
?EntityManagerInterface $em = null,
PaymentGatewayRegistryInterface $paymentGatewayRegistry,
TransactionManagerInterface $transactionManager,
EventDispatcherInterface $dispatcher,
LoggerInterface $logger,
array $paymentGatewayConfigurations
) {
$this->om = $om;
$this->dispatcher = $dispatcher;
$this->em = $em;
$this->paymentGatewayRegistry = $paymentGatewayRegistry;
$this->transactionManager = $transactionManager;
$this->dispatcher = $dispatcher;
$this->logger = $logger;
$this->paymentGatewayConfigurations = $paymentGatewayConfigurations;
}
Expand All @@ -60,7 +65,7 @@ public function getAllPaymentGatewayConfigurationFromDoctrine(): array
$paymentGatewayConfigurations = [];

$doctrinePaymentGatewayConfigurations = $this
->om
->em
->getRepository(PaymentGatewayConfiguration::class)
->findAll()
;
Expand Down Expand Up @@ -100,7 +105,7 @@ public function getAllPaymentGatewayConfiguration(): array
;
}

if (!$this->om) {
if (!$this->em) {
return $paymentGatewayConfigurations;
}

Expand Down
10 changes: 10 additions & 0 deletions Payment/PaymentContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@

class PaymentContext implements PaymentContextInterface
{
/**
* @var EventDispatcherInterface
*/
private $dispatcher;

/**
* @var PaymentGatewayConfigurationInterface
*/
Expand All @@ -28,6 +33,11 @@ class PaymentContext implements PaymentContextInterface
*/
private $transactionManager;

/**
* @var LoggerInterface
*/
private $logger;

/**
* @var Transaction
*/
Expand Down
6 changes: 3 additions & 3 deletions Resources/config/services.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,15 @@ services:
$logger: '@monolog.logger.payment'

# Manager
Doctrine\Common\Persistence\ObjectManager: null
Doctrine\ORM\EntityManagerInterface: null

IDCI\Bundle\PaymentBundle\Manager\DoctrineTransactionManager:
arguments:
$om: '@?doctrine.orm.entity_manager'
$em: '@?doctrine.orm.entity_manager'

IDCI\Bundle\PaymentBundle\Manager\PaymentManager:
arguments:
$om: '@?doctrine.orm.entity_manager'
$em: '@?doctrine.orm.entity_manager'
$paymentGatewayConfigurations: '%idci_payment.gateway_configurations%'

IDCI\Bundle\PaymentBundle\Manager\TransactionManagerInterface: '@IDCI\Bundle\PaymentBundle\Manager\DoctrineTransactionManager'
Expand Down

0 comments on commit e85f2ff

Please sign in to comment.