This is a Doctrine binding for trf4php.

2.0.0 2018-03-19 21:51 UTC

This package is not auto-updated.

Last update: 2023-03-18 07:24:59 UTC


Latest Stable Version

master: Build Status Coverage Status 1.2: Build Status Coverage Status

This is a Doctrine binding for trf4php

Using trf4php-doctrine


/* @var $em \Doctrine\ORM\EntityManager */
$tm = new DoctrineTransactionManager($em);

Using transactions

/* @var $tm TransactionManager */
try {
    // database modifications
} catch (TransactionException $e) {

Transactional EntityManager

If a transaction fails, you have to close your EntityManager. Doctrine says that after closing an EM, you have to create another one if you want to use database. TransactionalEntityManagerReloader does it automatically.

To enable this feature, you have to do the following steps:

  • Use EntityManagerProxy in DoctrineTransactionManager
  • Attach TransactionalEntityManagerReloader observer to DoctrineTransactionManager
$tm = new DoctrineTransactionManager(new DefaultEntityManagerProxy());
$emFactory = new DefaultEntityManagerFactory($conn, $config);
$tm->attach(new TransactionalEntityManagerReloader($emFactory));

If you would like to use a shared, non-transactional EntityManager, pass it to the constructor of DefaultEntityManagerProxy. In this case you can use the proxy object without starting a transaction, which is not recommended, but sometimes necessary.

This feature is also useful in integration tests. You can rollback in tearDown() thus you don't need to reinitialize the database. It highly speed-up your tests.



Transactional EntityManager

Create an EntityManager right after you start a transaction.