Download the PHP package byjg/statemachine without Composer

On this page you can find all versions of the php package byjg/statemachine. 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 statemachine

State Machine

Build Status Opensource ByJG GitHub source GitHub license GitHub release

This component implements a Finite State Machine, which can define several states and group them in a collection of transitions (from one state to another state). In addition, each state can have a conditional allowing move to another state.

Differently from other State machines, this implementation doesn't have an initial or final state.

Basic Example

Let's use the following example.

We have the states A, B, C, and D, and it's their possible transitions.

First, we create the states:

Then, we define the transitions. Note that each transition object can have a closure that receives a mixed type data. This closure needs to return true or false, allowing or not the transition.

After creating the states and the transition, we can create the State Machine:

We can validate the transition using the method canTransition($from, $to). Some examples:

We can also check if a state is initial or final:

Other ways to create the State Machine

Alternatively, you can create the state machine using the createMachine factory method with arguments as follows:

Using the Auto Transition

Another feature of this component is that depending on the state you are in and the data you pass to the state machine, it can decide what is the next state you can be.

Let's analyze the following states.

The transition is only possible if some conditions are satisfied. So, let's create the state, the possible transitions and its conditions.

The method autoTransitionFrom will check if is possible do the transition with the actual data and to what state.

When auto transitioned the state object returned have the ->getData() with the data used to validate it.

Also, it is possible create the transition with a closure to process the state.

e.g.

Other Methods

Create multiple transactions

Get possible states from a specific state

Get the State object

Install

Dependencies


Open source ByJG


All versions of statemachine with dependencies

PHP Build Version
Package Version
No informations.
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 byjg/statemachine contains the following files

Loading the files please wait ....