2017 © Pedro Peláez
 

library transaction

Library to handle transaction during multiple actions

image

sk/transaction

Library to handle transaction during multiple actions

  • Monday, November 21, 2016
  • by skroczek
  • Repository
  • 1 Watchers
  • 0 Stars
  • 17 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 2 Versions
  • 0 % Grown

The README.md

Transaction

Build Status SensioLabsInsight Coverage Status, (*1)

Introduction

This library claims to provide an easy way to implement secure transactions during nearly everything., (*2)

Installation

This library can be easily installed via composer, (*3)

composer require sk/transaction

or just add it to your composer.json file directly., (*4)

Usage

As a basic usage example, the CallbackTransaction is used to demonstrate the behaviour during three api calls:, (*5)


<?php use SK\Transaction\CallbackTransaction; use SK\Transaction\Exception\RollbackException; use SK\Transaction\ParameterBag; use Acme\Api1Client; use Acme\Api2Client; use Acme\Api3Client; $api1Client = new Api1Client(); $callbackTransaction = new CallbackTransaction( // Do something important function (ParameterBag $parameters) use ($api1Client) { $api1Client->doSomethingImportant($parameters); }, // Roll back if an exception in one of the next transaction(s) occurred. // For more information see interface \SK\Transaction\OwnExceptionRollback function () use ($api1Client) { $api1Client->rollback(); } ); $api2Client = new Api2Client(); $callbackTransaction2 = new CallbackTransaction( function (ParameterBag $parameters = null) use ($api2Client) { $api2Client->doSomethingImportant($parameters); }, function () use ($api2Client) { $api2Client->rollback(); } ); $api3Client = new Api3Client(); $callbackTransaction2 = new CallbackTransaction( function (ParameterBag $parameters) use ($api3Client) { $api3Client->doSomethingImportant($parameters); }, function () use ($api3Client) { // This will never executed. For more information see \SK\Transaction\OwnExceptionRollback $api3Client->rollback(); } ); $callbackTransaction->append($callbackTransaction2); $callbackTransaction->append($callbackTransaction3); // or // $callbackTransaction2->append($callbackTransaction3); try { $callbackTransaction->execute(); } catch (RollbackException $e) { // Something really bad happens // But you can get the Exception which causes the rollback $e->getOrigin(); // And you can get the exception which occurred during rollback $e->getPrevious(); } catch (\Exception $e) { // An exception occurred, but all executed actions was rolled back successfully }

ToDo

  • Write more documentation
  • Fix typos

License

This library is under the MIT license. See the complete license in the LICENCE file., (*6)

The Versions

21/11 2016

dev-master

9999999-dev

Library to handle transaction during multiple actions

  Sources   Download

MIT

The Requires

 

The Development Requires

by Sebastian Kroczek

20/11 2016

v1.0.0

1.0.0.0

Library to handle transaction during multiple actions

  Sources   Download

MIT

The Requires

 

The Development Requires

by Sebastian Kroczek