tarfin-labs/event-machine
最新稳定版本:2.1.2
Composer 安装命令:
composer require tarfin-labs/event-machine
包简介
An event-driven state machine library for PHP, providing an expressive language to define and manage application states, enabling developers to create complex workflows with ease and maintainability.
README 文档
README
EventMachine is a PHP library for creating and managing event-driven state machines. It is designed to be simple and easy to use, while providing powerful functionality for managing complex state transitions. This library is heavily influenced by XState, a popular JavaScript state machine library.
---
title: traffic_lights_machine
---
stateDiagram-v2
[*] --> Red
Red --> Yellow: TIMER_RED <br/>do / wait_for_red_light
Yellow --> Green: TIMER_YELLOW <br/>do / wait_for_yellow_light
Green --> Red: TIMER_GREEN <br/>do / wait_for_green_light
Red --> PowerOff: [is_power_off]
Yellow --> PowerOff: [is_power_off]
Green --> PowerOff: [is_power_off]
Red : Red<br/>entry / turn_on_red_light<br/>exit / turn_off_red_light
Yellow : Yellow<br/>entry / turn_on_yellow_light<br/>exit / turn_off_yellow_light
Green : Green<br/>entry / turn_on_green_light<br/>exit / turn_off_green_light
Loading
Installation
You can install the package via composer:
composer require tarfin-labs/event-machine
You can publish and run the migrations with:
php artisan vendor:publish --tag="event-machine-migrations"
php artisan migrate
You can publish the config file with:
php artisan vendor:publish --tag="event-machine-config"
This is the contents of the published config file:
return [
];
Usage
$machine = MachineDefinition::define( config: [ 'initial' => 'green', 'context' => [ 'value' => 1, ], 'states' => [ 'green' => [ 'on' => [ 'TIMER' => [ [ 'target' => 'yellow', 'guards' => 'isOneGuard', ], [ 'target' => 'red', 'guards' => 'isTwoGuard', ], [ 'target' => 'pedestrian', ], ], ], ], 'yellow' => [], 'red' => [], 'pedestrian' => [], ], ], behavior: [ 'guards' => [ 'isOneGuard' => function (ContextManager $context, array $event): bool { return $context->get('value') === 1; }, 'isTwoGuard' => function (ContextManager $context, array $event): bool { return $context->get('value') === 2; }, ], ], );
Testing
composer test
Changelog
Please see CHANGELOG for more information on what has changed recently.
Contributing
Please see CONTRIBUTING for details.
Security Vulnerabilities
Please review our security policy on how to report security vulnerabilities.
Credits
License
The MIT License (MIT). Please see License File for more information.
统计信息
- 总下载量: 7.85k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 15
- 点击次数: 1
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2023-04-07