PHPackages                             unialteri/states-bundle - 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-bundle

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

unialteri/states-bundle
=======================

Symfony bunde to create PHP 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 thus improve maintainability. (Build on the Teknoo Software States library)

3.0.2(8y ago)2523MITPHPPHP ~7.0

Since Dec 13Pushed 8y ago3 watchersCompare

[ Source](https://github.com/TeknooSoftware/statesBundle)[ Packagist](https://packagist.org/packages/unialteri/states-bundle)[ Docs](http://teknoo.software/states)[ RSS](/packages/unialteri-states-bundle/feed)WikiDiscussions master Synced today

READMEChangelogDependencies (12)Versions (51)Used By (0)

Teknoo Software - States bundle
===============================

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

[![SensioLabsInsight](https://camo.githubusercontent.com/507d28dcc5df140681c5f746b41558e2192c918f9f1f46558f32ce3fcd6832cd/68747470733a2f2f696e73696768742e73656e73696f6c6162732e636f6d2f70726f6a656374732f30616636623861372d383039302d343663632d626435662d6438366339663730323832612f6d696e692e706e67)](https://insight.sensiolabs.com/projects/0af6b8a7-8090-46cc-bd5f-d86c9f70282a) [![Build Status](https://camo.githubusercontent.com/321f8d92e3c2047cca17757c52ffcf47f9310916778b1c6448fd7d230d5d8fe0/68747470733a2f2f7472617669732d63692e6f72672f54656b6e6f6f536f6674776172652f73746174657342756e646c652e7376673f6272616e63683d6e657874)](https://travis-ci.org/TeknooSoftware/statesBundle)

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.

This package is bundle to adapt the library [`States`](http://teknoo.software/states) to Symfony 2+.

Short Example
-------------

[](#short-example)

```
/**
 * File States/English.php
 */
class English extends \Teknoo\States\State\AbstractState
{
    public function sayHello(): string
    {
        return 'Good morning, '.$this->name;
    }

    public function displayDate(\DateTime $now): string
    {
        return $now->format('%m %d, %Y');
    }
}

/**
 * File States/French.php
 */
class French extends \Teknoo\States\State\AbstractState
{
    public function sayHello(): string
    {
        return 'Bonjour, '.$this->name;
    }

    public function displayDate(\DateTime $now): string
    {
        return $now->format('%d %m %Y');
    }
}

/**
 * File MyClass.php
 */
class MyClass extends \Teknoo\Bundle\StatesBundle\Entity\IntegratedEntity
{
    /**
     * @ORM\Column(type="string", length=250)
     * @var string
     */
    private $name;

    /**
     * @param string $name
     * @return self
     */
    public function setName(string $name): MyClass
    {
        $this->name = $name;

        return $this;
    }
}

$frenchMan = new MyClass();
$frenchMan->switchState('French');
$frenchMan->setName('Roger');

$englishMan = new MyClass();
$englishMan->switchState('Enflish');
$englishMan->setName('Richard');

$now = new \DateTime('2016-07-01');

foreach ([$frenchMan, $englishMan] as $man) {
    echo $man->sayHello().PHP_EOL;
    echo 'Date: '.$man->displayDate($now);
}

//Display
Bonjour Roger
Date: 01 07 2016
Good morning Richard
Date: 07 01, 2016

```

Installation &amp; Requirements
-------------------------------

[](#installation--requirements)

This library requires :

```
* PHP 7+
* Composer
* States 2+
* Symfony 2.7+

```

Instruction to install the States bundle with Symfony 2+ : [Install](docs/install.md).

This library support Doctrine, but Doctrine is not mandatory. (Stated classes can be use without Doctrine)
\* Doctrine (Orm or Odm/Mongo)

Symfony Use
-----------

[](#symfony-use)

For main States's features, the bundle is transparent :

- States bundle's services are private and are not available. Only the loader is accessible via : `@teknoo.states.loader`
- Your Symfony's Doctrine entity (ORM) must use the trait `Teknoo\Bundle\StatesBundle\Entity\IntegratedTrait`.
    - Alternative, you can inherits `Teknoo\Bundle\StatesBundle\Entity\IntegratedEntity`.
- Your Symfony's Doctrine document (ODM) must use the trait `Teknoo\Bundle\StatesBundle\Document\IntegratedTrait`.
    - Alternative, you can inherits `Teknoo\Bundle\StatesBundle\Entity\IntegratedDocument`.

With the extension States Life cyclable :

- Observer instance to register a stated class and observe it : `@teknoo.states.lifecyclable.service.observer`
- Manager to register scenarii about stated class: `@teknoo.states.lifecyclable.service.manager`
- Prototype to create a new Yaml Scenario Builder `@teknoo.states.lifecyclable.prototype.scenario_yaml_builder`
- Prototype to create a new Scenario Builder `@teknoo.states.lifecyclable.prototype.scenario_builder`
- prototype to create a new Scenario : `@teknoo.states.lifecyclable.prototype.scenario`

Documentation to use States with Symfony 2+ : [Symfony](docs/symfony.md).

Quick startup
-------------

[](#quick-startup)

Quick How-to to learn how use this library : [Startup](https://github.com/TeknooSoftware/states/blob/master/docs/howto/quick-startup.md).

Example
-------

[](#example)

An example of using this library is available in the folder : [Demo](https://github.com/TeknooSoftware/states/blob/master/demo/demo_article.php).

API Documentation
-----------------

[](#api-documentation)

Generated documentation from the library with PhpDocumentor : [Open](https://cdn.rawgit.com/TeknooSoftware/states/master/docs/api/index.html).

Behavior Documentation
----------------------

[](#behavior-documentation)

Documentation to explain how this library works : [Behavior](https://github.com/TeknooSoftware/states/blob/master/docs/howto/behavior.md).

Credits
-------

[](#credits)

Richard Déloge -  - Lead developer. Teknoo Software -

About Teknoo Software
---------------------

[](#about-teknoo-software)

**Teknoo Software** is a PHP software editor, founded by Richard Déloge. Teknoo Software's DNA is simple : Provide to our partners and to the community a set of high quality services or software, sharing knowledge and skills.

License
-------

[](#license)

States is licensed under the MIT and GPL3+ Licenses - see the licenses folder for details

Contribute :)
-------------

[](#contribute-)

You are welcome to contribute to this project. [Fork it on Github](CONTRIBUTING.md)

###  Health Score

32

—

LowBetter than 72% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity15

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity71

Established project with proven stability

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~24 days

Recently: every ~96 days

Total

46

Last Release

3072d ago

Major Versions

1.1.0-beta4 → 2.0.0-beta22015-10-31

1.1.0 → 2.0.0-rc12015-12-05

1.1.2 → 2.0.0-rc52016-02-01

1.1.3 → 2.2.22016-08-04

2.2.3 → 3.0.0-alpha12016-10-09

PHP version history (4 changes)0.9.1-rcPHP &gt;=5.4.0

2.0.0-beta2PHP &gt;5.6

1.1.0-beta5PHP &gt;=5.4,&lt;7

2.0.1PHP ~7.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/e78f8fa644d9bbbd96dc92b2210e1290250522e56365345442c56eb8d042fb53?d=identicon)[frenchcomp](/maintainers/frenchcomp)

---

Top Contributors

[![frenchcomp](https://avatars.githubusercontent.com/u/1397905?v=4)](https://github.com/frenchcomp "frenchcomp (36 commits)")

---

Tags

symfonybundleclasspatternstatesstate patternbehavioral software design pattern

###  Code Quality

TestsPHPUnit

Code StylePHP\_CodeSniffer

### Embed Badge

![Health badge](/badges/unialteri-states-bundle/health.svg)

```
[![Health](https://phpackages.com/badges/unialteri-states-bundle/health.svg)](https://phpackages.com/packages/unialteri-states-bundle)
```

###  Alternatives

[teknoo/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.

1138.5k18](/packages/teknoo-states)[artgris/maintenance-bundle

Symfony Bundle to place your Symfony website in maintenance mode

2697.5k](/packages/artgris-maintenance-bundle)[ekreative/uuid-extra-bundle

Paramconverter, Normalizer and Form Type for Ramsey Uuid

18168.6k](/packages/ekreative-uuid-extra-bundle)[fsi/datagrid-bundle

FSi Datagrid Bundle

1859.8k1](/packages/fsi-datagrid-bundle)[glooby/task-bundle

Scheduling of tasks for symfony made simple

3216.3k](/packages/glooby-task-bundle)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
