PHPackages                             jeyroik/extas-m - 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. jeyroik/extas-m

ActiveLibrary

jeyroik/extas-m
===============

EXTendable State Machine.

4.0.3(6y ago)05404PHP

Since Jun 15Pushed 2y ago1 watchersCompare

[ Source](https://github.com/jeyroik/extas-m)[ Packagist](https://packagist.org/packages/jeyroik/extas-m)[ RSS](/packages/jeyroik-extas-m/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (10)Dependencies (3)Versions (18)Used By (4)

extas-m
=======

[](#extas-m)

Пакет машины состояния для Extas'a.

Установка
=========

[](#установка)

`composer require jeyroik/extas-m:*`

Использование
=============

[](#использование)

Использование демонстрационной машины состояния
-----------------------------------------------

[](#использование-демонстрационной-машины-состояния)

Сразу же после установки можно запустить демонстрационную машину состояния:

```
use extas\components\SystemContainer as Container;
use extas\interfaces\machines\IMachineRepository;
use extas\interfaces\machines\IMachine;

$machineRepo = Container::getItem(IMachineRepository::class);
$machine = $machineRepo->one([IMachine::FIELD__NAME => 'extas.demo']);
$machine->run('init', ['anything' => 'you want']);
```

Вы должны увидеть следующий вывод:

```
Initialized demo machine with the context:
[
    'anything' => 'you want'
]
Set to context initialized = true
Finished demo machine with the context:
[
    'anything' => 'you want',
    'initialized' => true
]

```

Кроме того, можно посмотреть цепочку переходов состояний из одного в другое:

```
echo '' . print_r($machine->getDump(), true) . ';
```

Вы должны увидеть следующее:

```
[
    [
        'state_from' => 'extas.demo.not initialized yet',
        'state_to' => 'extas.demo.init',
        'context' => [
            'anything' => 'you want'
        ]
    ],
    [
        'state_from' => 'extas.demo.init',
        'state_to' => 'extas.demo.end',
        'context' => [
            'anything' => 'you want',
            'initialized' => true
        ]
    ]
]

```

Создание своей машины состояния
-------------------------------

[](#создание-своей-машины-состояния)

### Создание конфигурации машины

[](#создание-конфигурации-машины)

Для начала необходимо сконфигурировать машину и состояния. Их необходимо указать в extas-совместимой конфигурации.

```
{
  "machine_states": [
    {
      "name": "init",
      "title": "Инициализация",
      "description": "Состояние инициализации машины"
    },
    {
      "name": "hello",
      "title": "Привет",
      "description": "Приветствие",
      "parameters": [{"name": "text"}]
    },
    {
      "name": "space",
      "title": "Пробел",
      "description": "Состояние пробела",
      "parameters": [{"name": "text"}]
    },
    {
      "name": "end",
      "title": "Конец",
      "description": "завершающее состояние машины",
      "parameters": [{"name": "text"}]
    },
    {
      "name": "someone",
      "title": "Некто",
      "description": "Состояние незнакомца",
      "parameters": [{"name": "text"}, {"name": "user"}]
    },
    {
      "name": "print_html",
      "title": "Вывести HTML",
      "description": "Вывод HTML",
      "parameters": [{"name": "data"}]
    },
    {
      "name": "print_json",
      "title": "Вывод JSON",
      "description": "Вывод JSON",
      "parameters": [{"name": "data"}]
    }
  ],
  "machines": [
    {
      "name": "hello_world",
      "title": "Привет мир",
      "description": "Данная машина выводит приветственное сообщение миру",
      "states": [
        {
          "name": "init",
          "on_success": {"state": "hello"},
          "on_failure": {"state": "end"}
        },
        {
          "name": "hello",
          "on_success": {"state": "space"},
          "on_failure": {"state": "end"}
        },
        {
          "name": "space",
          "on_success": {"state": "world"},
          "on_failure": {"state": "end"}
        },
        {
          "name": "world",
          "on_success": {"state": "end"},
          "on_failure": {"state": "someone"}
        },
        {
          "name": "end",
          "on_success": {"machine": "sub_machine", "state": "print_html"}
        },
        {
          "name": "someone"
        }
      ]
    },
    {
      "name": "sub_machine",
      "parameters": [{"name": "text"}],
      "states": [
        {
          "name": "print_html",
          "on_failure": {"state": "print_json"}
        },
        {
          "name": "print_json"
        }
      ]
    }
  ]
}
```

- `Параметры состояния` - это необходимые для состояния параметры контекста. Если хотя бы один из параметров отсутствует в контексте, то состояние считается не валидным и его запуск будет отменён.
- `Параметры машины` - это параметры для всех состояний, используемых в данной машине.

### Создание плагинов для состояний

[](#создание-плагинов-для-состояний)

Далее необходимо создать плагины для обработки состояний.

```
use extas\components\plugins\Plugin;

class PluginStateHello extends Plugin
{
    public function __invoke($state, &$context, $machine, &$isSuccess)
    {
        $context['text'] = $context['text'] . 'hello';
        $isSuccess = true;
    }
}

class PluginStateSpace extends Plugin
{
    public function __invoke($state, &$context, $machine, &$isSuccess)
    {
        $context['text'] = $context['text'] . ' ';
        $isSuccess = true;
    }
}

class PluginStateWorld extends Plugin
{
    public function __invoke($state, &$context, $machine, &$isSuccess)
    {
        $context['text'] = $context['text'] . 'world';
        $isSuccess = true;
    }
}
```

### Установка машины, состояний и плагинов

[](#установка-машины-состояний-и-плагинов)

`/vendor/bin/extas i`

### Запуск машины состояния

[](#запуск-машины-состояния)

```
$machine = $machineRepo->one([IMachine::FIELD__NAME => 'hello_world'])
$machine->run('hello', ['text' => '']); // "hello world"
/**
 * [
 *    [
 *      "state_from" => "hello_world.init",
 *      "state_to" => "hello_world.hello",
 *      "context" => [
 *        "text" => ""
 *      ]
 *    ],
 *    [
 *      "state_from" => "hello_world.hello",
 *      "state_to" => "hello_world.hello",
 *      "context" => [
 *        "text" => "hello"
 *      ]
 *    ],
 *    [
 *      "state_from" => "hello_world.space",
 *      "state_to" => "hello_world.hello",
 *      "context" => [
 *        "text" => "hello "
 *      ]
 *    ],
 *    [
 *      "state_from" => "hello_world.world",
 *      "state_to" => "hello_world.end",
 *      "context" => [
 *        "text" => "hello world"
 *      ]
 *    ],
 *    [
 *      "state_from" => "hello_world.end",
 *      "state_to" => "sub_machine.print_html",
 *      "context" => [
 *        "text" => "hello world"
 *      ]
 *    ]
 * ]
 */
$machine->dump();
```

###  Health Score

32

—

LowBetter than 71% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity12

Limited adoption so far

Community13

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 ~129 days

Recently: every ~168 days

Total

15

Last Release

1065d ago

Major Versions

0.1.5 → 1.0.02018-06-15

1.0.0 → 2.0.02018-07-03

2.2.3 → 3.0.32019-07-24

3.0.3 → 4.0.02020-03-13

### Community

Maintainers

![](https://www.gravatar.com/avatar/2aaec5c4bade6ab2b5d1a0f7d97ab4e0ff2ce83937f76499b2888ad16cde5e04?d=identicon)[jeyroik](/maintainers/jeyroik)

---

Top Contributors

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

---

Tags

extasphpstate-machine

### Embed Badge

![Health badge](/badges/jeyroik-extas-m/health.svg)

```
[![Health](https://phpackages.com/badges/jeyroik-extas-m/health.svg)](https://phpackages.com/packages/jeyroik-extas-m)
```

PHPackages © 2026

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