Download the PHP package konsulting/fluent-state-machine without Composer

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

Fluent State Machine

A simple fluent implementation of a state machine. If you've ever battled with trying to control and report state for an object in your php project - a state machine will help.

There are a few notable php state machine libraries around already - but didn't quite fit right, although we've used them in projects before. This is not an exhaustive list.

Installation

composer require konsulting/state-machine

Simple Example

We can construct a basic state machine easily, using a door as an example:

When constructing a StateMachine, the first state is assumed to be the default.

We can then try to transition the state machine to a new state:

We can also check if a transition is possible:

Real usage

In real usage, we will have a object (model) where the state machine is responsible for controlling the transitions that can be applied (and therefore controlling the models behaviour)

This can be accomplished two ways with this library.

  1. We can attach a model to the state machine, and the state machine can manipulate the model. In very simple cases, this may be enough.

  2. We can attach the state machine to a model, and the model's methods use the state machine to determine if it is able to proceed with an action.

Real usage 1 - attach a model to the state machine

As you will see, only the state machine retains the state information and we use it to control the flow in the script.

Side note: This example makes use of automatic wiring to use a model method called the same name as the transition (in camelCase). We can also define a method specifically by passing a string, or any other callable.

Real usage 2 - attach the state machine to a model

For this we extend the AttachableStateMachine which is set up to allow us to programmatically define the state machine, and accepts a model as its' constructor.

The end point is that we use the model in the natural manner we want to.

In the door class' methods we pass through a callback to be run as part of the transition. We are also able to pass through a callback to be run if the transition fails (instead of throwing an exception).

The AttachedStateMachine defines itself during construction. It grabs the current status from the model, and makes sure to stamp it back when setting the current status.

We also stop the auto wiring, so the state machine doesn't end up in an infinite loop trying to call it's calling method.

Contributing

Contributions are welcome and will be fully credited. We will accept contributions by Pull Request.

Please:

Testing

We use PHPUnit

Run tests using PHPUnit: vendor/bin/phpunit


All versions of fluent-state-machine with dependencies

PHP Build Version
Package Version
Requires php Version ^7.0 | ^8.0
danielstjules/stringy Version ^3.1
symfony/event-dispatcher Version ^3.3 | ^4.0 | 5.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 konsulting/fluent-state-machine contains the following files

Loading the files please wait ....