PHPackages                             unialteri/states - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. unialteri/states

Abandoned → [teknoo/states](/?search=teknoo%2Fstates)Library[Utility &amp; Helpers](/categories/utility)

unialteri/states
================

Library to create classes following the State pattern in PHP. This can be a cleaner way for an object to change its behavior at runtime without resorting to large monolithic conditional statements and this improve maintainability and workflow writing.

7.1.5(3mo ago)101.0k2BSD-3-ClausePHPPHP ^8.4

Since Nov 16Pushed 2mo ago3 watchersCompare

[ Source](https://github.com/TeknooSoftware/states)[ Packagist](https://packagist.org/packages/unialteri/states)[ Docs](https://teknoo.software/libraries/states)[ GitHub Sponsors](https://github.com/sponsors/TeknooSoftware)[ Patreon](https://www.patreon.com/teknoo_software)[ RSS](/packages/unialteri-states/feed)WikiDiscussions master Synced today

READMEChangelogDependencies (10)Versions (183)Used By (0)

Teknoo Software - States library
================================

[](#teknoo-software---states-library)

[![Latest Stable Version](https://camo.githubusercontent.com/2bb2e7a2409191c78f9d748f0450aec4d51525da51df297e12614c9ff890eaa1/68747470733a2f2f706f7365722e707567782e6f72672f74656b6e6f6f2f7374617465732f762f737461626c65)](https://packagist.org/packages/teknoo/states)[![Latest Unstable Version](https://camo.githubusercontent.com/dce7afd7e4eccd18a68be226a6a0db5bf8df6489a2f69da29539a85fff36c17f/68747470733a2f2f706f7365722e707567782e6f72672f74656b6e6f6f2f7374617465732f762f756e737461626c65)](https://packagist.org/packages/teknoo/states)[![Total Downloads](https://camo.githubusercontent.com/44da4c913c51efec8584b92a333d0234ccc1dcff5149715fc27d997a269cb973/68747470733a2f2f706f7365722e707567782e6f72672f74656b6e6f6f2f7374617465732f646f776e6c6f616473)](https://packagist.org/packages/teknoo/states)[![License](https://camo.githubusercontent.com/929909020c1e920cd04762daa1133ee3f66705cbf87deb70ecedf49279d16e61/68747470733a2f2f706f7365722e707567782e6f72672f74656b6e6f6f2f7374617465732f6c6963656e7365)](https://packagist.org/packages/teknoo/states)[![PHPStan](https://camo.githubusercontent.com/441b5874ce4df0a2defc892979c96c46889b69cb32119d04f0b48626349f8bc9/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f5048505374616e2d656e61626c65642d627269676874677265656e2e7376673f7374796c653d666c6174)](https://github.com/phpstan/phpstan)

States allows you to create PHP classes following the [State Pattern](http://en.wikipedia.org/wiki/State_pattern) in PHP. This can be a cleaner way for an object to change its behavior at runtime without resorting to large monolithic conditional statements and this improve maintainability and workflows writing.

Features
--------

[](#features)

- **Create Several States** : Split classes in states to avoid un-understandable large monolithic statements.
- **Inherit States and Classes** : Complete and factorize states thanks to inheritance.
    - Stated classes can be also inherited.
- **Automate States Switching** : Define states switching rules based on object's properties.
- **Implement Every Where**: Thanks to traits and interfaces, use this pattern on your existing code.
    - Compatible with Doctrine.

A complete documentation is available in [documentation/README.md](documentation/README.md)

Quick Example
-------------

[](#quick-example)

```
