Download the PHP package teknoo/states without Composer

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

Teknoo Software - States library

Latest Stable Version Latest Unstable Version Total Downloads License PHPStan

States allows you 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 this improve maintainability and workflows writing.

Features

A complete documentation is available in documentation/README.md

Quick Example

<?php

declare(strict_types=1);

require 'vendor/autoload.php';

use Teknoo\States\Automated\AutomatedInterface;
use Teknoo\States\Automated\AutomatedTrait;
use Teknoo\States\Automated\Assertion\Property;
use Teknoo\States\Automated\Assertion\Property\IsEqual;
use Teknoo\States\Proxy\ProxyInterface;
use Teknoo\States\Proxy\ProxyTrait;
use Teknoo\States\State\AbstractState;

class English extends AbstractState
{
    public function sayHello(): \Closure
    {
        return function(): string {
            return 'Good morning, '.$this->name;
        };
    }

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

class French extends AbstractState
{
    public function sayHello(): \Closure
    {
        return function(): string {
            return 'Bonjour, '.$this->name;
        };
    }

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

class Person implements ProxyInterface, AutomatedInterface
{
    use ProxyTrait;
    use AutomatedTrait;

    private string $name;

    private string $country;

    public function __construct()
    {
        $this->initializeStateProxy();
    }

    protected static function statesListDeclaration(): array
    {
        return [
            English::class,
            French::class
        ];
    }

    protected function listAssertions(): array
    {
        return [
            (new Property([English::class]))
                ->with('country', new IsEqual('en')),
            (new Property([French::class]))
                ->with('country', new IsEqual('fr')),
        ];
    }

    public function setName(string $name): Person
    {
        $this->name = $name;

        return $this;
    }

    public function setCountry(string $country): Person
    {
        $this->country = $country;
        $this->updateStates();

        return $this;
    }
}

$frenchMan = new Person();
$frenchMan->setCountry('fr');
$frenchMan->setName('Roger');

$englishMan = new Person();
$englishMan->setCountry('en');
$englishMan->setName('Richard');

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

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

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

Full Example

An example of using this library is available in the folder : Demo.

Support this project

This project is free and will remain free. It is fully supported by the activities of the EIRL. If you like it and help me maintain it and evolve it, don't hesitate to support me on Patreon or Github.

Thanks :) Richard.

Credits

EIRL Richard Déloge - https://deloge.io - Lead developer. SASU Teknoo Software - https://teknoo.software

About Teknoo Software

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

License

State is licensed under the MIT License - see the licenses folder for details.

Installation & Requirements

To install this library with composer, run this command :

composer require teknoo/states

This library requires :

* PHP 8.1+
* A PHP autoloader (Composer is recommended)
* Teknoo/Immutable (for Automated features).

A complete documentation is available in documentation/README.md

News from Teknoo State 6.0

This library requires PHP 8.1 or newer. Some change causes bc breaks :

News from Teknoo State 5.0

This library requires PHP 8.0 or newer. Some change causes bc breaks :

News from Teknoo State 4.0

This library requires PHP 7.4 or newer. Some change causes bc breaks :

Quick How-to to implement your first stated class

Quick How-to to learn how to use this library : Startup.

Evolutions in 3.x versions

From the version 3.2, the internal api has been redesigned to

From the version 3.1, this library provide base implementation for doctrine from teknoo/statesBundle.

From the version 3.0, this library has been redesigned to

From the version 2.0, this library has been redesigned to

Contribute :)

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


All versions of states with dependencies

PHP Build Version
Package Version
Requires php Version ^8.2
teknoo/immutable Version ^3.0.17
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 contains the following files

Loading the files please wait ....