Download the PHP package uuf6429/state-engine without Composer

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

🚦 State Engine / Machine (PHP)

CI codecov Minimum PHP Version License Latest Stable Version Latest Unstable Version

This library provides some interfaces and a basic implementation of a State Engine or State Machine.

✨ Highlights:

🔌 Installation

The recommended and easiest way to install this library is through Composer:

🧐 Why?

In principle such an engine is easy to implement, but in practice it is typically implemented badly or forgotten.

For instance, one might have an is_active field thinking there will not be other states and then later on an is_pending field is needed, at which point refactoring flags to state is too late.

In any case, this library abstracts away that situation or at least decreases the amount of code.

🤔 How?

There are a few key parts to how this works:

🚀 Usage

You have the possibility to use it from scratch or plug it into your existing. There are basically three parts to it:

  1. configuring the engine (creating states and transitions)
  2. using the engine (eg, in a web controller or service)
  3. (optionally) handling events (with the same event dispatcher provided to the engine)

A slightly different situation would be when you need to provide a list of valid transitions, for example to the user. In this case, having the StateTraversion trait on the repository would be useful.

From Scratch

Here's a quick & dirty example with the provided implementation (that assumes that there is a "door" model):

From Scratch (Custom)

You don't like how the Engine works? Or you feel that State could have more details? Then you're in luck! With the whole library based on interfaces, you can easily replace parts of the implementation. For example, you could store states or transitions in a database, in which case you can have your own TransitionRepository that accesses the database.

Existing Code

The library provides some flexibility so that you can connect your existing code with it. In more complicated scenarios, you may have to build a small layer to bridge the gap. The example below illustrates how one can handle models with flags instead of a single state.

😎 Examples & Testing

You can find some examples in this readme as well as the tests, some of which are explained below.

JiraIssueTest State Engine

This test provides a realistic example of how Jira Issue states could be set up.

The test also generates the Mermaid diagram below, thanks to the Mermaidable trait:

TurnstileTest State Machine

This test illustrates how a state machine can be used to model a turnstile gate. As before, here's the generated diagram:

Here's how the state machine definition looks like and how it could be used:


All versions of state-engine with dependencies

PHP Build Version
Package Version
Requires php Version ^7.4 || ^8.0
psr/event-dispatcher Version ^1.0
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 uuf6429/state-engine contains the following files

Loading the files please wait ...