1
0
mirror of synced 2025-02-20 14:13:15 +03:00

Implemented support for closure return on EntityManager::transactional. Fixes DDC-1125

This commit is contained in:
Guilherme Blanco 2011-04-25 18:32:43 -03:00
parent 4d561651a1
commit 26bd3e3811
2 changed files with 18 additions and 1 deletions

View File

@ -203,13 +203,18 @@ class EntityManager implements ObjectManager
public function transactional(Closure $func)
{
$this->conn->beginTransaction();
try {
$func($this);
$return = $func($this);
$this->flush();
$this->conn->commit();
return $return ?: true;
} catch (Exception $e) {
$this->close();
$this->conn->rollback();
throw $e;
}
}

View File

@ -143,4 +143,16 @@ class EntityManagerTest extends \Doctrine\Tests\OrmTestCase
$this->_em->close();
$this->_em->$methodName(new \stdClass());
}
/**
* @group DDC-1125
*/
public function testTransactionalAcceptsReturn()
{
$return = $this->_em->transactional(function ($em) {
return 'foo';
});
$this->assertEquals('foo', $return);
}
}