operation-state
, (*1)
operation-state
Simple PHP classes to handle Operation States for executable actions, with the
ability to undo. In other words, helper for transactions and rollbacks within PHP., (*2)
Its purpose is to provide a reliable method for executing actions, and being able to
undo those actions when applicable. The functionality will allow you create multiple
groups of executable actions and their respective undo actions., (*3)
Usage
use Sadekbaroudi\OperationState\OperationStateManager;
use Sadekbaroudi\OperationState\OperationState;
$yourClass = new YourClassName();
// Instantiate the manager
$osm = new OperationStateManager();
// Note that the setExecute and setUndo require PHP is_callable compliant parameters, as OperationState uses those methods
$os = new OperationState();
$os->setExecute(array($yourClass, 'yourMethod'), array('param1', $param2, array('foo' => 'bar')));
$os->setUndo(array($yourClass, 'undoMethod'), array('param1'));
$osm->add($os);
try {
$osm->execute($os);
} catch ( OperationStateException $e ) {
$osm->undo($os);
throw $e;
}
Installation
Operation State can be installed with Composer by adding
the library as a dependency to your composer.json file., (*4)
{
"require": {
"sadekbaroudi/operation-state": "*@dev"
}
}
Please refer to the Composer's documentation
for installation and usage instructions., (*5)