1. Go to this page and download the library: Download byjg/statemachine library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
byjg / statemachine example snippets
$stA = new State("A");
$stB = new State("B");
$stC = new State("C");
$stD = new State("D");
$transitionA_B = new Transition($stA, $stB);
$transitionA_C = new Transition($stA, $stC);
$transitionB_D = new Transition($stB, $stD, function($data) {
return !is_null($data);
});
$stN = new State('SOMESTATE', function ($data) {
// execute some operation with the data
})
// After run and return $stN object
// We can do this:
$resultState = $stateMachine->autoTransitionFrom('STATE', [... data ...]));
$resultState->process(); // This will run the closure defined with the data used to validate it.