2017 © Pedro Peláez
 

library stateeventbroker

Advanced Stateautomaton for Eventbroker

image

anon767/stateeventbroker

Advanced Stateautomaton for Eventbroker

  • Friday, July 27, 2018
  • by anon767
  • Repository
  • 0 Watchers
  • 0 Stars
  • 0 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 1 Versions
  • 0 % Grown

The README.md

Advanced Eventdriven State Automaton

This Library provides managing state and state-transitions. It applies rules by considering the current state and the incoming events. It can handle multiple events aswell what makes it actually a pushdown automaton., (*1)

Install

composer require anon767/stateeventbroker

Or, (*2)

"require": {
    "anon767/stateeventbroker": "*"
  }

Usage

First you should define some Events lets start with a simple example:, (*3)

define("IDLE_STATE", "idle");  
define("CLEAN_STATE", "cleaning");  
define("DOOR_CLOSED_EVENT", "doorcloses");  
define("ITSSIXOCLOCK_EVENT", "sixoclock"); 

These are basically two States and events. Now its time to program the automaton. This is quite easy and works like that:, (*4)

$rules = [  
 ["oldState" => IDLE_STATE, "event" => new Events([new Event(DOOR_CLOSED_EVENT), new Event(ITSSIXOCLOCK_EVENT)]), "action" => $startRobo, "newState" => CLEAN_STATE],  
  ["oldState" => CLEAN_STATE, "event" => new Event(DOOR_CLOSED_EVENT), "action" => $stopRobo, "newState" => IDLE_STATE],  
];

You see? If the automaton is in Idle State and the two above defined events came in we let the library trigger the "startRobo" callback and transit to the next state "CLEAN_STATE". If we are in the CLEAN_STATE and the door closed event comes in, we trigger a stopRobo callback and go back to the Idle state., (*5)

$startRobo = function (Event $event) {  
  $this->assertEquals(ITSSIXOCLOCK_EVENT, $event->identifier);  
};  

$stopRobo = function (Event $event) {  
  $this->assertEquals(DOOR_CLOSED_EVENT, $event->identifier);  
};

These are the two callbacks from the Test Case. They get executed if the above mentioned transitions kicked in., (*6)

Using the actual state automaton is as simple as:, (*7)

$this->stateAutomaton = new StateAutomaton(IDLE_STATE);  
$this->broker = new Broker($this->stateAutomaton);
$this->stateAutomaton->addRules($rules);
//for example following event comes in:
$this->broker->onMessage(DOOR_CLOSED_EVENT);

The Versions

27/07 2018

dev-master

9999999-dev

Advanced Stateautomaton for Eventbroker

  Sources   Download

MIT

The Requires

  • php >=5.0

 

The Development Requires