tarfin-labs/event-machine
Composer 安装命令:
composer require tarfin-labs/event-machine
包简介
Event-driven state machines for Laravel with event sourcing, type-safe context, and full audit trail.
README 文档
README
Event-driven state machines for Laravel
Documentation · Installation · Why EventMachine?
Why EventMachine?
Your business logic deserves better than nested if-statements.
EventMachine brings the power of finite state machines to Laravel, inspired by XState. Define your states, transitions, and behaviors declaratively - and let the machine handle the complexity.
The Problem
// Without state machines: scattered conditionals, hidden rules, impossible to test if ($order->status === 'pending' && $user->can('approve') && !$order->isExpired()) { if ($order->total > 10000 && !$order->hasSecondApproval()) { // More nested logic... } }
The Solution
// With EventMachine: clear states, explicit transitions, testable behaviors MachineDefinition::define( config: [ 'initial' => 'pending', 'states' => [ 'pending' => [ 'on' => [ 'APPROVE' => [ 'target' => 'approved', 'guards' => [CanApproveGuard::class, NotExpiredGuard::class], ], ], ], 'approved' => [ 'entry' => NotifyCustomerAction::class, ], ], ], );
Key Benefits
| Feature | Description |
|---|---|
| Event Sourced | Every transition persisted. Full audit trail. Replay history. |
| Behaviors | Guards validate, calculators compute, actions execute. |
| Parallel Dispatch | True parallel execution via Laravel queues. 5s + 2s = 5s, not 7s. |
| Testable | Fake any behavior. Assert states. Verify transitions. |
| Type-Safe Context | Spatie Data powered. Validated. IDE autocompletion. |
| Archival | Compress millions of events. Restore any machine instantly. |
| Laravel Native | Eloquent, DI, Artisan commands. Built for Laravel. |
Installation
composer require tarfin-labs/event-machine
php artisan vendor:publish --tag="event-machine-migrations"
php artisan migrate
AI Agent Skill
EventMachine ships with an official Agent Skill so AI coding agents can write correct, idiomatic EventMachine code — it loads naming conventions, best practices, testing patterns, and the full VitePress documentation on demand.
Install via npx skills — works with 45+ agents including Claude Code, Cursor, GitHub Copilot, Cline, Codex, OpenCode, Gemini CLI, Warp, Amp, and many others:
npx skills add tarfin-labs/event-machine#plugin-dist
The CLI detects your installed agents and wires the skill into the right location. The plugin-dist branch is a self-contained, materialized snapshot published automatically on every release tag.
What the skill loads:
- Immediately (when the skill triggers): naming conventions, 13 best-practice summaries, core concepts, quick-start snippets, testing API cheat-sheet, Laravel integration map, delegation/parallel gotcha tables.
- On demand (when the agent needs deeper detail): curated cheat-sheets under
references/and the full 87-page documentation underdocs/.
Read the full skill guide at eventmachine.dev/getting-started/agent-skill.
Support Policy
Only the latest major version (currently v7) receives bug fixes and security patches. All previous versions are end of life. See the Upgrading Guide for step-by-step migration from any version.
Eloquent Integration
class Order extends Model { use HasMachines; protected $casts = [ 'machine' => MachineCast::class.':'.OrderMachine::class, ]; } // Use it naturally $order = Order::create(); $order->machine->send(['type' => 'SUBMIT']); $order->machine->send(['type' => 'APPROVE']); $order->machine->state->matches('approved'); // true $order->machine->state->history->count(); // 3 events tracked
Documentation
For guards, actions, calculators, hierarchical states, parallel dispatch, validation, testing, and more:
Credits
- Yunus Emre Deligöz
- Fatih Aydın
- Yunus Emre Nalbant
- Faruk Can
- Turan Karatuğ
- Yılmaz Demir
- Maybe you? Contribute →
License
MIT License. See LICENSE for details.
tarfin-labs/event-machine 适用场景与选型建议
tarfin-labs/event-machine 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 9.44k 次下载、GitHub Stars 达 19, 最近一次更新时间为 2023 年 04 月 07 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「workflow」 「fsm」 「laravel」 「state-machine」 「event-sourcing」 「finite-state-machine」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 tarfin-labs/event-machine 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 tarfin-labs/event-machine 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 tarfin-labs/event-machine 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Workflow for NetCommons Plugin
Finite state machine for php.
Workflow logger
A state Machine library for business processes
Approval Workflow Engine for Filament
Operational approvals engine for Laravel applications.
统计信息
- 总下载量: 9.44k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 19
- 点击次数: 23
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2023-04-07