All Projects → Metabor → Statemachine

Metabor / Statemachine

Licence: mit
Statemachine in PHP 5.6 / PHP 7

Projects that are alternatives of or similar to Statemachine

Redstone
Redstone has a State Machine
Stars: ✭ 36 (-63.64%)
Mutual labels:  state-machine
Hal
🔴 A non-deterministic finite-state machine for Android & JVM that won't let you down
Stars: ✭ 63 (-36.36%)
Mutual labels:  state-machine
Finity
A finite state machine library for Node.js and the browser with a friendly configuration DSL.
Stars: ✭ 88 (-11.11%)
Mutual labels:  state-machine
Formatwith
String extensions for named parameterized string formatting.
Stars: ✭ 44 (-55.56%)
Mutual labels:  state-machine
Aws Power Tuner Ui
AWS Lambda Power Tuner UI is an open source project creating a deployable easy to use website built on a layered technology stack allowing you to optimize your Lambda functions for cost and/or performance in a data-driven way via an easy to use UI.
Stars: ✭ 52 (-47.47%)
Mutual labels:  state-machine
Xstateful
A wrapper for xstate that stores state, handles transitions, emits events for state changes and actions/activities, and includes an optional reducer framework for updating state and invoking side-effects
Stars: ✭ 81 (-18.18%)
Mutual labels:  state-machine
Mineflayer Statemachine
A state machine plugin for Mineflayer to aid in designing more complex behavior trees.
Stars: ✭ 32 (-67.68%)
Mutual labels:  state-machine
Workflow Swift
A Swift and Kotlin library for making composable state machines, and UIs driven by those state machines.
Stars: ✭ 92 (-7.07%)
Mutual labels:  state-machine
River Admin
🚀 A shiny admin interface for django-river built with DRF, Vue & Vuetify
Stars: ✭ 55 (-44.44%)
Mutual labels:  state-machine
Jstate
Advanced state machines in Java.
Stars: ✭ 84 (-15.15%)
Mutual labels:  state-machine
Yii2 Lifecycle Behavior
Define the lifecycle of a model by defining allowed status changes.
Stars: ✭ 47 (-52.53%)
Mutual labels:  state-machine
React Context Hook
A React.js global state manager with Hooks
Stars: ✭ 50 (-49.49%)
Mutual labels:  state-machine
Tulip Control
Temporal Logic Planning toolbox
Stars: ✭ 81 (-18.18%)
Mutual labels:  state-machine
Pylstar
An implementation of the LSTAR Grammatical Inference Algorithm
Stars: ✭ 41 (-58.59%)
Mutual labels:  state-machine
React Automata
A state machine abstraction for React
Stars: ✭ 1,316 (+1229.29%)
Mutual labels:  state-machine
Kfin State Machine
Kotlin Finite State Machine
Stars: ✭ 36 (-63.64%)
Mutual labels:  state-machine
State Machine
🤖 A state machine library for Kotlin, with extensions for Android.
Stars: ✭ 72 (-27.27%)
Mutual labels:  state-machine
Finite
UI as finite-state machine
Stars: ✭ 99 (+0%)
Mutual labels:  state-machine
Makina
A simple hierarchical state machine compiler that generates C.
Stars: ✭ 93 (-6.06%)
Mutual labels:  state-machine
Statemachineone
State Machine library for PHP
Stars: ✭ 84 (-15.15%)
Mutual labels:  state-machine

metabor/statemachine

Statemachine in PHP 5.6 / PHP 7

Support

Gitter

Gitter chat

Continuous Integration/Deployment

TravisCI

Build Status

Open Issues

Open Issues

Package Information

Packagist

Packagist Packagist Packagist Packagist

Compatibility

MetaborStd Version

Dependency Status

VersionEye

Dependency Status

Test Coverage

Scrutinizer

Code Coverage

Code Quality

Codeship

Codeship Status

Codacy

Codacy

Code Climate

Code Climate

Scrutinizer

Scrutinizer Code Quality

SensioLabsInsight

SensioLabsInsight

Other

License Gittip

Quickstart examples

Once installed, let's use a sample statemachine:

<?php
require_once 'vendor/autoload.php';

use Metabor\Statemachine\Process;
use Metabor\Statemachine\State;
use Metabor\Statemachine\Statemachine;
use Metabor\Statemachine\Transition;

$closed = new State('closed');
$opened = new State('opened');

$eventOpen = 'open';
$eventClose = 'close';
$closed->addTransition(new Transition($opened, $eventOpen));
$closed->addTransition(new Transition($closed, $eventClose));
$opened->addTransition(new Transition($opened, $eventOpen));
$opened->addTransition(new Transition($closed, $eventClose));

// adding some action to events
// the parts of observing the event and executing the command are separated in this example
// normaly it could be put all together into your own command (base)class
$openCommand = new \Metabor\Callback\Callback(
        function ()
        {
            echo 'motor is opening door' . PHP_EOL;
        });
$observerForOpenEvent = new \Metabor\Observer\Callback($openCommand);
$closed->getEvent($eventOpen)->attach($observerForOpenEvent);

$closeCommand = new \Metabor\Callback\Callback(
        function ()
        {
            echo 'motor is closing door' . PHP_EOL;
        });
$observerForCloseEvent = new \Metabor\Observer\Callback($closeCommand);
$opened->getEvent($eventClose)->attach($observerForCloseEvent);

// stateful subject that belongs to this statemachine
$subject = new stdClass();

// start process with closed status;
$initialState = $closed;
$process = new Process('process name', $initialState);

$statemachine = new Statemachine($subject, $process);

echo 'Status:' . $statemachine->getCurrentState()->getName() . PHP_EOL;

echo 'Event:' . $eventOpen . PHP_EOL;
$statemachine->triggerEvent($eventOpen);
echo 'Status:' . $statemachine->getCurrentState()->getName() . PHP_EOL;

// opening an open door would not activate the motor
echo 'Event:' . $eventOpen . PHP_EOL;
$statemachine->triggerEvent($eventOpen);
echo 'Status:' . $statemachine->getCurrentState()->getName() . PHP_EOL;

echo 'Event:' . $eventClose . PHP_EOL;
$statemachine->triggerEvent($eventClose);
echo 'Status:' . $statemachine->getCurrentState()->getName() . PHP_EOL;

Features

This library implements a finite-state machine in PHP 5.3.

It was first developed for a talk at a conference. The example from my talk is available on Github and Packagist as metabor/statemachine-example.

In the namespace MetaborStd are abstract types defined that are exemplified implemented in this project. If you have to implement or use a statemachine in your project, feel free to either use this libary at all or replace the parts that didn't fit your needs by using the MetaborStd Interfaces.

Process Graph Drawing

The library supports visualizing of the process graph by using clue/graph and GraphViz "Graph Visualization Software".

Install

The recommended way to install this library is through composer. New to composer?

{
    "require": {
        "metabor/statemachine": "~1.2"
    }
}

Optional recommendation: In order to be able to use the process graph drawing feature you'll have to install GraphViz (dot executable). Users of Debian/Ubuntu-based distributions may simply invoke sudo apt-get install graphviz, Windows users have to download GraphViZ for Windows and remaining users should install from GraphViz homepage. To use this feature you also have to add this to your composer.json:

{
    "require": {
        "graphp/graphviz": "*",
        "clue/graph": "*",
        "metabor/statemachine": "~1.2"
    }
}

An example how to draw and display the graph, can be found in metabor/statemachine-example.

Tests

This library uses phpunit for its extensive testsuite. You can either use a global installation or rely on the one composer installs when you first run $ composer install. This sets up the developer environment, so that you can now run it from the project root directory:

$ php vendor/bin/phpunit

Contributing

If you encounter any issues, please don't hesitate to drop us a line, file a bug report or even best provide us with a patch / pull request and/or unit test to reproduce your problem.

Besides directly working with the code, any additional documentation, additions to our readme or even fixing simple typos are appreciated just as well.

Any feedback and/or contribution is welcome!

License

Released under the terms of the permissive MIT license.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].