pixielity/laravel-workflow
Composer 安装命令:
composer require pixielity/laravel-workflow
包简介
Workflow engine for Laravel applications with state management and transitions
README 文档
README
This directory contains standard reference implementations and documentation for creating workflows and steps.
📚 Documentation
Start here to understand the patterns:
- WORKFLOW_PATTERNS.md - Quick reference guide with golden rules and checklists
- YIELD_PATTERN_EXPLAINED.md - Deep dive into yield vs yield from with visual diagrams
- Workflows/README.md - Comprehensive documentation with templates
🎯 Reference Implementation
Workflows/CreatePolicy/ - Complete working example demonstrating all patterns:
CreatePolicyWorkflow.php- Main workflow orchestrationSteps/ValidatePolicyDataStep.php- Validation step (no retries)Steps/CreatePolicyStep.php- Database operation step (with retries)Steps/NotifyPolicyCreatedStep.php- Notification step (with retries)
🚀 Quick Start
Creating a New Workflow
- Create workflow folder:
Workflows/MyWorkflow/ - Create workflow class extending
Workflow - Create
Steps/subfolder for workflow-specific steps - Follow the patterns in
CreatePolicy/example
Creating a New Step
- Extend
Stepbase class - Use typed parameters in
execute()method - Implement
before()hook for validation - Set
$name,$enableLogging,$maxRetriesproperties - Return structured data (array or DTO)
📖 Key Patterns
Yield Usage
// In main execute() - use `yield from` for helper methods
public function execute(): Generator
{
yield from $this->validate();
$data = yield from $this->create();
}
// In helper methods - use `yield` for steps
protected function validate(): Generator
{
$result = yield $this->step(ValidateStep::class, $dto);
}
Argument Mapping
// Step with typed parameters
public function execute(MyDto $dto, MyService $service): array
{
// Auto-mapped to $this->args->dto and $this->args->service
}
// Access in hooks
protected function before(): void
{
/** @phpstan-ignore-next-line property.notFound */
$dto = $this->args->dto;
}
Response Types
// Workflows return WorkflowResponse
return WorkflowResponse::success(['data' => $result]);
// Steps return structured data
return ['success' => true, 'data' => $result];
🎓 Learning Path
- Start: Read WORKFLOW_PATTERNS.md for quick overview
- Understand: Read YIELD_PATTERN_EXPLAINED.md to understand yield usage
- Study: Review Workflows/CreatePolicy/ reference implementation
- Reference: Use Workflows/README.md as detailed reference
- Build: Create your own workflow following the patterns
✅ Checklist
Before creating a workflow, ensure you understand:
- [ ] When to use
yieldvsyield from - [ ] How arguments are auto-mapped to
$this->args - [ ] How to return
WorkflowResponsefrom workflows - [ ] How to use
WorkflowStatusenum - [ ] How to implement
before()hook in steps - [ ] How to set retry configuration per step
- [ ] How to access step arguments via DataObject
🔍 Common Issues
| Issue | Solution |
|---|---|
| "Generator object instead of result" | Use yield from for helper methods, not yield |
| "Step not executing" | Use yield for steps, not yield from |
| "Can't access $this->args->property" | Add @phpstan-ignore-next-line property.notFound |
| "Arguments not mapped" | Ensure parameter names match what you access in $this->args |
📁 Directory Structure
examples/
├── README.md # This file
├── WORKFLOW_PATTERNS.md # Quick reference
├── YIELD_PATTERN_EXPLAINED.md # Yield pattern deep dive
└── Workflows/
├── README.md # Detailed documentation
└── CreatePolicy/ # Reference implementation
├── CreatePolicyWorkflow.php
└── Steps/
├── ValidatePolicyDataStep.php
├── CreatePolicyStep.php
└── NotifyPolicyCreatedStep.php
🤝 Contributing
When adding new examples:
- Follow the established patterns
- Add comprehensive docblocks
- Include pattern notes in comments
- Update this README if adding new concepts
- Ensure code passes diagnostics
📞 Support
If you're unsure about a pattern:
- Check WORKFLOW_PATTERNS.md quick reference
- Review CreatePolicy/ example
- Read YIELD_PATTERN_EXPLAINED.md for yield questions
- Consult Workflows/README.md for detailed docs
统计信息
- 总下载量: 0
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 4
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2026-02-09