Download the PHP package eftec/statemachineone without Composer

On this page you can find all versions of the php package eftec/statemachineone. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package statemachineone

StateMachineOne

It is State Machine library written on PHP aimed to business process.
This library has only a simple external dependency, it is a minimalist (yet complete) library with only 3 classes.

Since this library is PHP native, then it could run in Laravel, Symfony and any other frameworks.

Packagist Total Downloads [Maintenance]() [composer]() [php]() [php]() [CocoaPods]()

What is a state machine?.

A State Machine (also called Automata) is a procedural execution of a job based in states. Every job must have a single state at the same time, such as "INITIATED","PENDING","IN PROCESS" and so on, and the job changes of state (transition) according to some logic or condition. Such conditions could be a field, a time or a custom function.

The target of this library is to ease the process to create a state machine for business.

Table of Contents

Notes

Example, ChopSuey Chinese Delivery Food.

We need to create a process to deliver Chinese food at home. Is it easy?. Well, let's find it out.

Fields (ChopSuey's exercise)

Fields are values used for out State Machine. In this example, I am not including other values that it could be useful (such as money, customer name, address and such) because they are not part or used by the state machine.

States (ChopSuey's exercise)

It must include all the possible situation. The real world is not as easy as: sell and money.

Transitions (ChopSuey's exercise)

Final Code (ChopSuey's example)

Example/ChopSuey.php

Other examples

Example/BuyMilk.php (buy milk)

Example/Car.php (car parking)

Transition language

Let's say the next transition

The transition is written as follows:

The transition language is written with the next syntax.

Transition when

It adds a condition so where the transition must be done. For example:

In this case, the state changes from STATE_ONE to STATE_TWO when field is zero.

It could also exist multiple initial states

Types of transition:

It compares a constant. The binary operator for comparison are

Values of the field could be as the next ones:

  • on() it is the on value (1)

  • off() it is the off value (0)

  • undef() it is the undefined value (-1)

  • flip() indicates that the value will be flipped (1=>0 and 0=>1). Example (x=1) x = flip(), now (x=0). If the value is not zero, then it's flipped to zero.

For example

Transition set

We could add one or many change of variables when a transition is done.

In this case, when we are in "STATE_ONE" and field=0, then we change to state "STATE_TWO", and we assign the field=1

Examples:

It sets a field of the job.

Where the function (global) must be defined as myfunc(Job $job,$input) {}

  • The first value could be a field or a (global) variable

It sets the field to the value 0

It increases the value of field by 1 (field=field+1)

It decreases the value of field by 1 (field=field-1)

Transition else

It works similar than "set" but it is executed when the transition is not done.

In this case, it sets the field2="not done" until the transition is done.

Note: This operation is called every time the expression is evaluated. So it could be evaluated many times.

Transition timeout (in seconds)

The state chances from STATE_ONE to STATE_TWO when the field is zero, or has elapsed 3600 seconds elapsed in the STATE_ONE.

It sets the timeout between the time of current state and the current time. If a timeout happens, then the transition is executed.

Transition fulltimeout (in seconds)

The state chances from STATE_ONE to STATE_TWO when the field is zero, or has elapsed (since the start of the job) 3600 seconds.

It sets the timeout between the time of initial state and the current time. If a timeout happens, then the transition is executed.

JOB

What is a job?

Let's say we have a blueprint to build the house. The job is the action to build the house and the blueprint are the transitions.
So, the job is an operative part of our work-flow.

A job keeps values, including the current state, and it has a lifecycle, while the workflow (the transitions) doesn't keep any single value. It is possible to create a short life job that works in a single web thread. However, if we need to keep the values, then we could use a database or a file system (flat file).

Creating a job

There are several ways to create a job. One of them is using the GUI and other is via code.

Creating a job via code

Running the state machine in a job

Getting a job

Database and jobs.

Fields used in Job

Flags

It is possible to store one or multiples flags inside a job.
A flag is a state or value that:

Example of creates an array of flags:

GUI

This library has a build-in GUI for testing.

Classes

StateMachineOne It is the main class. Job It is the model class for the job
Transition It is the model class for the transitions.

Cache Configuration

It is possible to cache all the configurations.

Saving configuration

Loading configuration:

Log Format

Commonly, the log format could be of the type info or error. Flag could show a different type.

[info]

state,,changed,,Parked,,1,,Idling,,2,,0,,change

[error]

state,,transition,,text,,1,,message // when a check of the job fails

savejob,,message // when to save a job fails.

changestate,,idjob,,idstate,newstate // when the change of a state fails

License

Dual license (LGPL 3.0 and Commercial). See LICENSE file.

Version

What is missing


All versions of statemachineone with dependencies

PHP Build Version
Package Version
Requires php Version >=7.4
eftec/pdoone Version ^4.8
eftec/minilang Version ^2.28
ext-ctype Version *
ext-json Version *
eftec/documentstoreone Version ^1.27
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package eftec/statemachineone contains the following files

Loading the files please wait ....