2017 © Pedro PelĂĄez
 

library states-life-cycle

Component to extend the behavior of teknoo/states and provide a service to manage life cycles of stated class instances and automated their behavior

image

teknoo/states-life-cycle

Component to extend the behavior of teknoo/states and provide a service to manage life cycles of stated class instances and automated their behavior

  • Sunday, October 29, 2017
  • by frenchcomp
  • Repository
  • 2 Watchers
  • 1 Stars
  • 5,383 Installations
  • PHP
  • 2 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 27 Versions
  • 0 % Grown

The README.md

Teknoo Software - States Life Cyclable extension

SensioLabsInsight Build Status, (*1)

This extention provides some new behavior to your stated class : - Automated stated class : to switch automatically to states defined by validation rules defined in class by assertions - Lifecycable stated class : to dispatch states updates from a stated class to observer - Traceable stated class : to keep evolution of states in the lifecycle of your stated class - Scenario : to create easily scenarii in php or yaml between stated class instances and others application's components, (*2)

Shorts Examples

/**
 * File Person/States/English.php
 */
class English extends \Teknoo\States\State\AbstractState 
{
    // ...
}

/**
 * File Person/States/French.php
 */
class French extends \Teknoo\States\State\AbstractState 
{
    // ...
}

/**
 * File Person.php
 */
class Person extends \Teknoo\States\Proxy\Standard implements AutomatedInterface, LifeCyclableInterface
{
    private $nationality;

    public function setNationality(string $nationality): Person 
    {
        $this->nationality = $nationality;

        //To update states of this instance according to its assertions and
        //dispatch states change to observer
        $this->updateStates();

        return $this;
    }

    public function setTravel(Travel $travel): Person
    {
        // ...
    }

    public function getTravel(): Travel
    {
        // ...
    }


    /**
     * @return AssertionInterface[]
     */
    public function getStatesAssertions(): array
    {
        return [
            (new Assertion([French::class]))->with('nationality', new IsEqual('Fr')),
            (new Assertion([English::class]))->with('nationality', new IsNotEqual('Fr'))
        ];
    }
}

/**
 * File Travel/States/Schengen.php
 */
class Schengen extends \Teknoo\States\State\AbstractState 
{
    // ...
}

/**
 * File Travel/States/Uk.php
 */
class Uk extends \Teknoo\States\State\AbstractState 
{
    // ...
}

/**
 * File Travel.php
 */
class Travel extends \Teknoo\States\Proxy\Standard 
{
    // ..
}

//Scenario
//Use the helper generator to get needed instance of observer and event dispatcher, it's not a mandatory tool
$di = include 'src/generator.php';

//Scenario to enable Schengen state to travel of French man
$di->get(ManagerInterface::class)
    ->registerScenario(
        (new ScenarioBuilder($di->get(TokenizerInterface::class)))
        ->towardStatedClass('demo\Person')
        ->onIncomingState('French')
        ->run(function (EventInterface $event) {
            $person = $event->getObserved();
            $person->getTravel()->switchState('Schengen');
        })
        ->build(new Scenario())
);

//Scenario to enable UK state to travel of English man
$di->get(ManagerInterface::class)
    ->registerScenario(
        (new ScenarioBuilder($di->get(TokenizerInterface::class)))
        ->towardStatedClass('demo\Person')
        ->onIncomingState('English')
        ->run(function (EventInterface $event) {
            $person = $event->getObserved();
            $person->getTravel()->switchState('UK');
        })
        ->build(new Scenario())
);


//Demo
$frenchMan = new Person();
$travel1 = new Travel();
$frenchMan->setTravel($travel1);

print_r($travel1->listEnabledStates()); //Print []
$frenchMan->setNationality('Fr');
print_r($travel1->listEnabledStates()); //Print ['Schengen"]

$englishMan = new Person();
$travel2 = new Travel();
$frenchMan->setTravel($travel2);

print_r($travel2->listEnabledStates()); //Print []
$englishMan->setNationality('En');
print_r($travel2->listEnabledStates()); //Print ['UK"]
$englishMan->setNationality('Fr');
print_r($travel2->listEnabledStates()); //Print ['Schengen"]

Full Example

Examples of using this library is available in the folder demo., (*3)

Installation & Requirements

To install this library with composer, run this command :, (*4)

composer require teknoo/states-life-cycle

You must install a event dispatcher, like symfony/event-dispatcher., (*5)

composer require symfony/event-dispatcher

The library provide a native support of Symfony Event Dispatcher. If you use another event dispatcher, you must write you own EventDispatcherBridgeInterface., (*6)

Next, you must configure the generator, with the event dispatcher bridge defined in demo/EventDispatcherBridge.php :, (*7)

$di = include 'src/generator.php';

A PHP-DI configuration is available into src/di.php. You can use PHP-DI with Symfony with PHP-DI Symfony Bridge., (*8)

This library requires :, (*9)

* PHP 7+
* Teknoo Software States 3.1+
* PHP-DI
* Symfony event dispatcher (not required)
* Symfony yaml to parse yaml scenarii (not required)

How to create an observed stated class and Scenarri

Quick How-to to learn how use this library : Startup., (*10)

API Documentation

Generated documentation from the library with PhpDocumentor : Coming soon, (*11)

Credits

Richard Déloge - richarddeloge@gmail.com - Lead developer. Teknoo Software - http://teknoo.software, (*12)

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., (*13)

License

States Life Cycle is licensed under the MIT License - see the licenses folder for details, (*14)

Contribute :)

You are welcome to contribute to this project. Fork it on Github, (*15)

The Versions

29/10 2017

dev-feature-east

dev-feature-east http://teknoo.software/states

Component to extend the behavior of teknoo/states and provide a service to manage life cycles of stated class instances and automated their behavior

  Sources   Download

MIT

The Requires

 

The Development Requires

by Richard Déloge

pattern class states life cycle state pattern behavioral software design pattern

27/10 2017

dev-master

9999999-dev http://teknoo.software/states

Component to extend the behavior of teknoo/states and provide a service to manage life cycles of stated class instances and automated their behavior

  Sources   Download

MIT

The Requires

 

The Development Requires

by Richard Déloge

pattern class states life cycle state pattern behavioral software design pattern

27/10 2017

dev-states-life-cycle-3.0

dev-states-life-cycle-3.0 http://teknoo.software/states

Component to extend the behavior of teknoo/states and provide a service to manage life cycles of stated class instances and automated their behavior

  Sources   Download

MIT

The Requires

 

The Development Requires

by Richard Déloge

pattern class states life cycle state pattern behavioral software design pattern

02/10 2017

3.0.0-beta4

3.0.0.0-beta4 http://teknoo.software/states

Component to extend the behavior of teknoo/states and provide a service to manage life cycles of stated class instances and automated their behavior

  Sources   Download

MIT

The Requires

 

The Development Requires

by Richard Déloge

pattern class states life cycle state pattern behavioral software design pattern

25/07 2017

3.0.0-beta3

3.0.0.0-beta3 http://teknoo.software/states

Component to extend the behavior of teknoo/states and provide a service to manage life cycles of stated class instances and automated their behavior

  Sources   Download

MIT

The Requires

 

The Development Requires

by Richard Déloge

pattern class states life cycle state pattern behavioral software design pattern

23/07 2017

3.0.0-beta2

3.0.0.0-beta2 http://teknoo.software/states

Component to extend the behavior of teknoo/states and provide a service to manage life cycles of stated class instances and automated their behavior

  Sources   Download

MIT

The Requires

 

The Development Requires

by Richard Déloge

pattern class states life cycle state pattern behavioral software design pattern

05/07 2017

3.0.0-beta1

3.0.0.0-beta1 http://teknoo.software/states

Component to extend the behavior of teknoo/states and provide a service to manage life cycles of stated class instances and automated their behavior

  Sources   Download

MIT

The Requires

 

The Development Requires

by Richard Déloge

pattern class states life cycle state pattern behavioral software design pattern

26/02 2017

dev-next

dev-next http://teknoo.software/states

Component to extend the behavior of teknoo/states and provide a service to manage life cycles of stated class instances and automated their behavior

  Sources   Download

MIT

The Requires

 

The Development Requires

by Richard Déloge

pattern class states life cycle state pattern behavioral software design pattern

26/02 2017

dev-states-life-cycle-2.0

dev-states-life-cycle-2.0 http://teknoo.software/states

Component to extend the behavior of teknoo/states and provide a service to manage life cycles of stated class instances and automated their behavior

  Sources   Download

MIT

The Requires

 

The Development Requires

by Richard Déloge

pattern class states life cycle state pattern behavioral software design pattern

15/02 2017

2.0.1

2.0.1.0 http://teknoo.software/states

Component to extend the behavior of teknoo/states and provide a service to manage life cycles of stated class instances and automated their behavior

  Sources   Download

MIT

The Requires

 

The Development Requires

by Richard Déloge

pattern class states life cycle state pattern behavioral software design pattern

06/01 2017

2.0.0

2.0.0.0 http://teknoo.software/states

Component to extend the behavior of teknoo/states and provide a service to manage life cycles of stated class instances and automated their behavior

  Sources   Download

MIT

The Requires

 

The Development Requires

by Richard Déloge

pattern class states life cycle state pattern behavioral software design pattern

21/12 2016

2.0.0-beta1

2.0.0.0-beta1 http://teknoo.software/states

Component to extend the behavior of teknoo/states and provide a service to manage life cycles of stated class instances and automated their behavior

  Sources   Download

MIT

The Requires

 

The Development Requires

by Richard Déloge

pattern class states life cycle state pattern behavioral software design pattern

31/10 2016

2.0.0-alpha4

2.0.0.0-alpha4 http://teknoo.software/states

Component to extend the behavior of teknoo/states and provide a service to manage life cycles of stated class instances and automated their behavior

  Sources   Download

MIT

The Requires

 

The Development Requires

by Richard Déloge

pattern class states life cycle state pattern behavioral software design pattern

27/10 2016

2.0.0-alpha3

2.0.0.0-alpha3 http://teknoo.software/states

Component to extend the behavior of teknoo/states and provide a service to manage life cycles of stated class instances and automated their behavior

  Sources   Download

MIT

The Requires

 

The Development Requires

by Richard Déloge

pattern class states life cycle state pattern behavioral software design pattern

11/10 2016

2.0.0-alpha2

2.0.0.0-alpha2 http://teknoo.software/states

Component to extend the behavior of teknoo/states and provide a service to manage life cycles of stated class instances and automated their behavior

  Sources   Download

MIT

The Requires

 

The Development Requires

by Richard Déloge

pattern class states life cycle state pattern behavioral software design pattern

07/10 2016

2.0.0-alpha1

2.0.0.0-alpha1 http://teknoo.software/states

Component to extend the behavior of teknoo/states and provide a service to manage life cycles of stated class instances and automated their behavior

  Sources   Download

MIT

The Requires

 

The Development Requires

by Richard Déloge

pattern class states life cycle state pattern behavioral software design pattern

02/09 2016

dev-states-life-cycle-1.0

dev-states-life-cycle-1.0 http://teknoo.software/states

Component to extend the behavior of teknoo/states and provide a service to manage life cycles of stated class instances and automated their behavior

  Sources   Download

MIT

The Requires

 

The Development Requires

by Richard Déloge

pattern class states life cycle state pattern behavioral software design pattern

02/09 2016

1.0.3

1.0.3.0 http://teknoo.software/states

Component to extend the behavior of teknoo/states and provide a service to manage life cycles of stated class instances and automated their behavior

  Sources   Download

MIT

The Requires

 

The Development Requires

by Richard Déloge

pattern class states life cycle state pattern behavioral software design pattern

02/09 2016

1.0.2

1.0.2.0 http://teknoo.software/states

Component to extend the behavior of teknoo/states and provide a service to manage life cycles of stated class instances and automated their behavior

  Sources   Download

MIT

The Requires

 

The Development Requires

by Richard Déloge

pattern class states life cycle state pattern behavioral software design pattern

04/08 2016

1.0.1

1.0.1.0 http://teknoo.software/states

Component to extend the behavior of teknoo/states and provide a service to manage life cycles of stated class instances and automated their behavior

  Sources   Download

MIT

The Requires

 

The Development Requires

by Richard Déloge

pattern class states life cycle state pattern behavioral software design pattern

26/07 2016

1.0.0

1.0.0.0 http://teknoo.software/states

Component to extend the behavior of teknoo/states and provide a service to manage life cycles of stated class instances and automated their behavior

  Sources   Download

MIT

The Requires

 

The Development Requires

by Richard Déloge

pattern class states life cycle state pattern behavioral software design pattern

09/04 2016

1.0.0-RC1

1.0.0.0-RC1 http://teknoo.software/states

Component to extend the behavior of teknoo/states and provide a service to manage life cycles of stated class instances and automated their behavior

  Sources   Download

MIT

The Requires

 

The Development Requires

by Richard Déloge

pattern class states life cycle state pattern behavioral software design pattern

02/02 2016

1.0.0-beta5

1.0.0.0-beta5 http://teknoo.software/states

Component to extend the behavior of teknoo/states and provide a service to manage life cycles of stated class instances and automated their behavior

  Sources   Download

MIT

The Requires

 

The Development Requires

by Richard Déloge

pattern class states life cycle state pattern behavioral software design pattern

20/01 2016

1.0.0-beta4

1.0.0.0-beta4 http://teknoo.software/states

Component to extend the behavior of teknoo/states and provide a service to manage life cycles of stated class instances and automated their behavior

  Sources   Download

MIT

The Requires

 

The Development Requires

by Richard Déloge

pattern class states life cycle state pattern behavioral software design pattern

19/01 2016

1.0.0-beta3

1.0.0.0-beta3 http://teknoo.software/states

Component to extend the behavior of teknoo/states and provide a service to manage life cycles of stated class instances and automated their behavior

  Sources   Download

MIT

The Requires

 

The Development Requires

by Richard Déloge

pattern class states life cycle state pattern behavioral software design pattern

17/01 2016

1.0.0-beta2

1.0.0.0-beta2 http://teknoo.software/states

Component to extend the behavior of teknoo/states and provide a service to manage life cycles of stated class instances and automated their behavior

  Sources   Download

MIT

The Requires

 

The Development Requires

by Richard Déloge

pattern class states life cycle state pattern behavioral software design pattern

29/11 2015

1.0.0-alpha1

1.0.0.0-alpha1 http://teknoo.software/states

Component to extend the behavior of teknoo/states and provide a service to manage lifes cycles of stated class instances and automated their beahvior

  Sources   Download

MIT

The Requires

 

The Development Requires

by Richard Déloge

pattern class states life cycle state pattern behavioral software design pattern