Skip to content

alvlapo/comedian

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

COMEDIAN

Build Status

! UNDER DEVELOPMENT !

A finite state machine for php

Requirements and installation

  • PHP 7.1+

Usage

State definition

Simple state definition

$state = new NormalState('state');

$state
  ->event('publish', 'published')
  ->trigger('beforePublish', function() { /* exec before $state->publish() run */ })
  ->trigger('onExit', function() { return /* will be executed when leaving this state */; });
  
$state->publish(); // return 'published'

Class based state definition

// file SimpleState.php
class SimpleState implements StateInterface {
  
  // public method it is event
  public function publish()
  {
    return 'published';
  }
  
  // before<*> or after<*> it is triggers
  // runs before and after event execute
  public function beforePublish()
  {
    return true;
  }
  
  // This is trigger like an 'onExit', 'onReset'
  public function onExit()
  {
    return true;
  }
}

$state = new SimpleState();
$state->publish(); // return 'published'

Inspired by

  • workflux - Finite state machine for php.
  • UnderStated - A PHP Finite State Machine
  • S-Flow - A lightweight library for defining state machines that supports conditional transitions

About

A finite state machine for php

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages