Download the PHP package stateflow/engine without Composer

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

StateFlow Engine

A clean, auditable state machine for PHP 8.2+

Latest Version PHP Version License


Why StateFlow?

Stop scattering state logic across your codebase:

Feature Ad-hoc if statements StateFlow
See all states Scattered One place
See all transitions Scattered One place
Invalid transitions Silent bugs Throws exception
Typos Silent bugs Throws exception
Side effects Easy to forget Defined with hooks
Audit trail Build it yourself Built-in events
Testing Hard Easy
New developer onboarding "Read the whole codebase" "Read this class"

Installation

Requires PHP 8.2 or higher.


Quick Start

1. Define your states and transitions

2. Create and use the state machine

That's it! The library enforces valid transitions. You handle persistence.


Core Concepts

States

States are the possible values your subject can have. Define them as a const array:

Transitions

Transitions define how to move between states. Each transition has:

Subjects

A subject is the thing that has state. It can be:


API Reference

Creating a State Machine

Applying Transitions

Reading State

Initializing New Subjects

Introspection

Validation


Guards

Guards are conditions that must pass before a transition is allowed.

Defining Guards

Create a workflow class with guard methods:

Using Guards

Multiple Guards

You can have multiple guards for the same transition. All must pass:


Hooks

Hooks run code at specific points during a transition.

Available Hooks

Hook Triggers on When
#[Before('transition')] Transition name After guards, before state change
#[OnExit('state')] State name Before leaving the state
#[OnEnter('state')] State name After entering the state
#[After('transition')] Transition name After everything

Execution Order

Defining Hooks

Hook Signature

All hooks receive the same parameters:

Guards must return bool. Other hooks return void.


Events & Audit Trail

Listen to transition events for logging, auditing, or triggering side effects.

Registering Listeners

TransitionEvent Properties

Multiple Listeners

Note: Listeners are only called for successful transitions. Failed transitions (invalid state, guard rejected) do not trigger listeners.


Custom State Accessor

By default, StateFlow reads/writes state using common patterns:

For special cases, provide a custom accessor:

Or implement StateAccessorInterface:


Visualizing Your State Machine

Export to Mermaid for documentation:

Output:

Renders as:

Paste this into GitHub, GitLab, Notion, or any Mermaid-compatible tool.


Framework Integration

Laravel / Eloquent

With Service Container

Symfony / Doctrine


Error Handling

Exception Types


Testing

StateFlow makes testing easy:


Complete Example


License

MIT License. See LICENSE for details.


Contributing

Contributions are welcome! Please feel free to submit a Pull Request.


Credits

Created by Enmanuel Varela Pividori.


All versions of engine with dependencies

PHP Build Version
Package Version
Requires php Version ^8.2
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 stateflow/engine contains the following files

Loading the files please wait ...