A lightweight PHP state machine library using PHP Enums to manage stateful objects with transitions, events, and Symfony integration.
Finite is a lightweight PHP library for implementing finite state machines in applications. It allows developers to define states and transitions for stateful objects using PHP Enums, enabling structured management of object lifecycles and business logic. The library provides event-driven transitions, Symfony integration, and tools to avoid scattered conditional checks in domain code.
PHP developers building applications with complex stateful workflows, such as content management systems, order processing, or document approval pipelines. It's particularly useful for Symfony projects needing integrated state management.
Developers choose Finite for its simplicity, low dependency footprint, and modern use of PHP Enums to encapsulate state behavior. It offers a clean alternative to manual state handling, with built-in event systems and Symfony/Twig integrations out of the box.
A Simple PHP Finite State Machine
Open-Awesome is built by the community, for the community. Submit a project, suggest an awesome list, or help improve the catalog on GitHub.
Leverages PHP Enums to define states and transitions, reducing boilerplate and providing type safety, as shown in the DocumentState example in the README.
Emphasizes a lightweight design with few external dependencies, making it easy to integrate into projects without bloat, as highlighted in the philosophy section.
Includes a Symfony bundle with Twig helpers for template checks and console commands for graph visualization, streamlining usage in Symfony-based applications.
Dispatches PSR-14 events for guards and post-transition actions, allowing flexible custom logic without modifying core library code, as demonstrated with CanTransitionEvent and PostTransitionEvent.
Encourages adding business logic as methods on state Enums, such as isDeletable() and isPrintable(), avoiding conditional checks in domain code for cleaner organization.
Requires PHP 8.1 or higher due to its reliance on Enums, excluding projects on older PHP versions and limiting adoption in legacy environments.
Focuses on basic state transitions without built-in support for advanced features like hierarchical states or concurrency, which may be insufficient for complex workflows.
Version 2 introduced significant changes, such as moving from state properties to enum methods, potentially requiring code migration and causing disruption for users upgrading.