PHP code example of sidfate / fsm

1. Go to this page and download the library: Download sidfate/fsm 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/ */

    

sidfate / fsm example snippets


$fsm = new Fsm([
    'init'=> 'green',
    'events'=> [
        ['name'=> 'warn', 'from'=> 'green', 'to'=> 'yellow'],
        ['name'=> 'stop', 'from'=> 'yellow', 'to'=> 'red'],
        ['name'=> 'go', 'from'=> 'red', 'to'=> 'green'],
    ]
]);

$fsm->onWarn(function () {
   echo 'I am warn';
});

echo $fsm->now();	// green
$fsm->warn();		// I am warn
echo $fsm->now();	// yellow