Skip to content

Commit

Permalink
Merge pull request #3 from remi-san/dbal-fix
Browse files Browse the repository at this point in the history
Add a Tx Manager for doctrine DBAL
  • Loading branch information
remi-san authored Jul 10, 2018
2 parents ebead91 + 26ffaff commit 8550db8
Showing 1 changed file with 64 additions and 0 deletions.
64 changes: 64 additions & 0 deletions src/Doctrine/DoctrineDbalConnectionTransactionManager.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
<?php

namespace RemiSan\TransactionManager\Doctrine;

use Doctrine\DBAL\Connection;
use Doctrine\DBAL\ConnectionException;
use RemiSan\TransactionManager\Exception\BeginException;
use RemiSan\TransactionManager\Exception\CommitException;
use RemiSan\TransactionManager\Exception\RollbackException;
use RemiSan\TransactionManager\Transactional;

final class DoctrineDbalConnectionTransactionManager implements Transactional
{
/**
* @var Connection
*/
private $dbalConnection;

/**
* Constructor.
*
* @param Connection $dbalConnection
*/
public function __construct(Connection $dbalConnection)
{
$this->dbalConnection = $dbalConnection;
}

/**
* {@inheritdoc}
*/
public function beginTransaction()
{
try {
$this->dbalConnection->beginTransaction();
} catch (\Exception $e) {
throw new BeginException('Cannot begin Doctrine DBAL transaction');
}
}

/**
* {@inheritdoc}
*/
public function commit()
{
try {
$this->dbalConnection->commit();
} catch (ConnectionException $e) {
throw new CommitException('Cannot commit Doctrine DBAL transaction');
}
}

/**
* {@inheritdoc}
*/
public function rollback()
{
try {
$this->dbalConnection->commit();
} catch (ConnectionException $e) {
throw new RollbackException('Cannot rollback Doctrine DBAL transaction');
}
}
}

0 comments on commit 8550db8

Please sign in to comment.