thetwelvelabs/techne 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

thetwelvelabs/techne

Composer 安装命令:

composer require thetwelvelabs/techne

包简介

Finite State Machine implementation

README 文档

README

================================

A simple PHP implementation of a Finite-State Machine

Installation

Use Composer to install this library in your project

Create your composer.json file

  {
      "require": {
          "thetwelvelabs/techne": "0.2.*@dev"
      }
  }

Download composer into your application root

  $ curl -s http://getcomposer.org/installer | php

Install your dependencies

  $ php composer.phar install

Usage

Let's use a light switch as a simple example.
A light switch as two states: on and off. The state of a light switch is transitioned from one to the other by flipping the switch. We'll assume that the initial state of the light switch is 'off'

Define your FSM

  $machine = new StateMachine\FiniteStateMachine();
  $machine->setInitialState('off');

Define the transitions

  $turnOff = new StateMachine\Transition('on', 'off');
  $turnOn = new StateMachine\Transition('off', 'on');

Add a guard to the turnOn transition

  // flipping the switch on requires electricity
  $hasElectricity = true;
  $turnOn->before(function() use ($hasElectricity) {
      return $hasElectricity ? true : false;
  });

Define the events

  $machine->addEvent('flip', array($turnOn, $turnOff));

Transition from off to on

  $machine->flip();  
  echo $machine->getCurrentState();
  // prints 'on'  

Transition back to off

  $machine->flip();  
  echo $machine->getCurrentState();
  // prints 'off'  

统计信息

  • 总下载量: 2.47k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 41
  • 点击次数: 2
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 41
  • Watchers: 1
  • Forks: 1
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2012-11-17

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固