Skip to content

Latest commit

 

History

History
46 lines (36 loc) · 760 Bytes

File metadata and controls

46 lines (36 loc) · 760 Bytes

Transaction

@Transaction annotation gives a transactional context around a method.

  • begin transaction
  • execute()
  • commit
  • rollback on exception
class AUseCase
{
    /**
     * @Transaction
     */
    public function execute(UseCaseRequest $useCaseRequest)
    {
        // do things
        
        return $useCaseResponse;
    }
}

Exceptions occurring during the transaction can be mapped so that the method returns another exception instead

class AUseCase
{
    /**
     * @Transaction(exceptions={
     *     "SomeInfrastructureException"="SomeDomainException"
     * })
     */
    public function execute(UseCaseRequest $useCaseRequest)
    {
        // do things
        
        return $useCaseResponse;
    }
}