Files
svc-essensplanung/src/Data/Infrastructure/Doctrine/EntityManagerTransactionManager.php
T

32 lines
737 B
PHP

<?php
declare(strict_types=1);
namespace App\Data\Infrastructure\Doctrine;
use App\Logic\Common\TransactionManagerInterface;
use Doctrine\ORM\EntityManagerInterface;
/**
* Bridge von Doctrine\EntityManager auf `TransactionManagerInterface`.
*
* Verwendet Doctrine 3 `doInTransaction()` (commit + rollback).
*/
final class EntityManagerTransactionManager implements TransactionManagerInterface
{
public function __construct(
private readonly EntityManagerInterface $em,
) {
}
public function execute(\Closure $work): mixed
{
try {
return $this->em->wrapInTransaction($work);
} catch (\Throwable $e) {
$this->em->clear();
throw $e;
}
}
}