Download the PHP package teknoo/states-life-cycle without Composer

On this page you can find all versions of the php package teknoo/states-life-cycle. 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 states-life-cycle

Teknoo Software - States Life Cyclable extension

SensioLabsInsight Build Status

This extention provides some new behavior to your stated class :

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.

Installation & Requirements

To install this library with composer, run this command :

composer require teknoo/states-life-cycle

You must install a event dispatcher, like symfony/event-dispatcher.

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.

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

$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.

This library requires :

* 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.

API Documentation

Generated documentation from the library with PhpDocumentor : Coming soon

Credits

Richard Déloge - [email protected] - Lead developer. Teknoo Software - http://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

States Life Cycle is licensed under the MIT License - see the licenses folder for details

Contribute :)

You are welcome to contribute to this project. Fork it on Github


All versions of states-life-cycle with dependencies

PHP Build Version
Package Version
Requires php Version ~7.0
teknoo/states Version ~3.1.0-beta3
psr/container-implementation Version ^1.0.0
php-di/php-di Version ^5.4
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 teknoo/states-life-cycle contains the following files

Loading the files please wait ...