1. Go to this page and download the library: Download sonsofphp/state-machine 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/ */
sonsofphp / state-machine example snippets
use SonsOfPHP\Component\StateMachine\StateMachine;
$sm = new StateMachine([
'graph' => 'order',
'supports' => [
OrderInterface::class,
],
'transitions' => [
'create' => [
'from' => 'draft',
'to' => 'new',
],
'fulfill' => [
'from' => 'new',
'to' => 'fulfilled',
],
'cancel' => [
'from' => ['draft', 'new', 'fulfilled'],
'to' => 'fulfilled',
],
],
]);
// Check if state can change
$sm->can($order, 'create');
// Apply transition
$sm->apply($order, 'fulfil');
// Get Current State
$sm->getState($order);
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.