承接 grazulex/laravel-statecraft 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

grazulex/laravel-statecraft

Composer 安装命令:

composer require grazulex/laravel-statecraft

包简介

A declarative and testable way to model entity state transitions (orders, documents, processes…) with guard conditions, actions, and events.

README 文档

README

Laravel Statecraft

Advanced State Machine implementation for Laravel applications. Declarative state management with support for conditions, actions, and complex workflows through YAML configuration.

Latest Version Total Downloads License PHP Version Laravel Version Tests Code Style

📖 Table of Contents

Overview

Laravel Statecraft is a powerful state machine implementation for Laravel that provides declarative state management through YAML configuration. Build complex workflows with conditional transitions, guards, actions, and comprehensive state tracking.

Perfect for order processing, user workflows, approval systems, and any application requiring sophisticated state management.

🎯 Use Cases

Laravel Statecraft is perfect for:

  • Order Processing - Complex e-commerce order workflows
  • User Registration - Multi-step user onboarding flows
  • Approval Systems - Document or request approval workflows
  • Content Management - Publishing and moderation workflows
  • Business Processes - Any multi-state business logic

✨ Features

  • 🚀 Declarative Configuration - Define state machines in YAML files
  • 🔄 Flexible Transitions - Conditional transitions with guards and actions
  • 🎯 Event System - Built-in events for state changes and transitions
  • 📊 State History - Track all state changes with timestamps
  • 🛡️ Guards & Actions - Pre/post transition validation and processing
  • 🔗 Model Integration - Seamless Eloquent model integration
  • 📋 YAML Support - Human-readable state machine definitions
  • 🎨 Artisan Commands - CLI tools for state machine management
  • Validation - Comprehensive state machine validation
  • 📈 Visualization - Export state machines to Mermaid diagrams
  • 🧪 Test-Friendly - Built-in testing utilities
  • Performance - Optimized for speed with caching support

📦 Installation

Detailed installation instructions are available in our wiki: 📦 Installation & Setup

Quick install via Composer:

composer require grazulex/laravel-statecraft

💡 Auto-Discovery
The service provider will be automatically registered thanks to Laravel's package auto-discovery.

Publish configuration:

php artisan vendor:publish --tag=statecraft-config

Publish migrations (if using history tracking):

php artisan vendor:publish --tag=statecraft-migrations
php artisan migrate

🚀 Quick Start

For a complete getting started guide, visit: 🚀 Basic Usage Guide

1. Create a State Machine Definition

php artisan statecraft:make OrderStateMachine --model=Order

2. Define Your State Machine in YAML

# state-machines/OrderStateMachine.yaml
name: OrderStateMachine
model: App\Models\Order
initial_state: pending

states:
  - name: pending
    description: Order is pending payment
  - name: paid
    description: Order has been paid
  - name: shipped
    description: Order has been shipped

transitions:
  - name: pay
    from: pending
    to: paid
    guard: PaymentGuard
    action: ProcessPayment

3. Add the Trait to Your Model

use Grazulex\LaravelStatecraft\HasStateMachine;

class Order extends Model
{
    use HasStateMachine;
    
    protected $stateMachine = 'OrderStateMachine';
}

4. Use State Transitions

// Create a new order (starts in 'pending' state)
$order = Order::create(['total' => 100.00]);

// Transition to next state
$order->transition('pay'); // Moves to 'paid' state

// Check current state
echo $order->currentState(); // 'paid'

📚 Complete Documentation

Our comprehensive documentation is available in the GitHub Wiki:

🏗️ Core Concepts

🔧 Advanced Topics

📖 Getting Started

💡 Examples & Use Cases

Explore real-world implementations and patterns:

🔧 Requirements

  • PHP 8.2 or higher
  • Laravel 11.x or higher
  • Optional: Redis for caching (recommended for production)

🧪 Testing

Comprehensive testing guide: 🧪 Testing Guide

composer test
composer test:coverage
composer test:types

🚀 Performance

Laravel Statecraft is optimized for production use with caching support and minimal overhead. See our ⚙️ Configuration Guide for performance optimization tips.

🤝 Contributing

We welcome contributions! Please see CONTRIBUTING.md for details.

Before contributing:

  1. Read our Code of Conduct
  2. Check the issue tracker
  3. Review our 📚 Complete Documentation

🔒 Security

If you discover a security vulnerability, please send an e-mail via the security policy. All security vulnerabilities will be promptly addressed.

📄 License

Laravel Statecraft is open-sourced software licensed under the MIT license.

Made with ❤️ for the Laravel community

Resources

Community Links

grazulex/laravel-statecraft 适用场景与选型建议

grazulex/laravel-statecraft 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 5 次下载、GitHub Stars 达 8, 最近一次更新时间为 2025 年 07 月 17 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「flow」 「workflow」 「steps」 「laravel」 「modular」 「pipeline」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 grazulex/laravel-statecraft 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 grazulex/laravel-statecraft 我们能提供哪些服务?
定制开发 / 二次开发

基于 grazulex/laravel-statecraft 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 5
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 9
  • 点击次数: 28
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 8
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-07-17