thephpleague / tactician-doctrine

Tactician plugins for the Doctrine ORM, primarily transactions
MIT License
57 stars 13 forks source link

Using EntityManagerInterface::transactional #6

Closed pawelbaranski closed 9 years ago

pawelbaranski commented 9 years ago

Hi,

Did you consider using EntityManagerInterface::transactional($func)

https://github.com/doctrine/doctrine2/blob/master/lib/Doctrine/ORM/EntityManager.php

instead duplicates the "transactional()" responsibility in TransactionMiddleware::execute ?

rosstuck commented 9 years ago

Hi @pawelbaranski, indeed I did! However, transactional() tampers with the closure's return value, passing back true if the original value is null. Since Tactician allows return values (it's optionally a command bus in the GoF sense rather than the CQRS sense), there's no way to tell if the true was the original return value or not, etc. See here: https://github.com/doctrine/doctrine2/blob/master/lib/Doctrine/ORM/EntityManager.php#L238

So, rather than finagle with that, I just do the transaction management by hand. It's a minimal amount of code and easy to track.

Thanks for the suggestion though!