Skip to content

Commit a068824

Browse files
committed
wip
1 parent b551eb2 commit a068824

File tree

3 files changed

+231
-1
lines changed

3 files changed

+231
-1
lines changed

README.md

Lines changed: 73 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ Create powerful business workflows with simple, maintainable code.
1010

1111
## ✨ Why Choose This Workflow Engine?
1212

13-
- 🎨 **Simple & Intuitive** - Array-based workflow definitions that are easy to understand
13+
- 🎨 **Simple & Intuitive** - Array-based workflow definitions and fluent WorkflowBuilder API
14+
- 🏷️ **Modern PHP 8.3+ Attributes** - Declarative configuration with #[WorkflowStep], #[Retry], #[Timeout]
1415
- 🔒 **Type Safety First** - Built with enums, strong typing, and modern PHP features
1516
-**Laravel Native** - Seamless integration with Laravel's ecosystem and helpers
1617
- 🧩 **Extensible** - Easy to extend with custom actions and storage adapters
@@ -279,6 +280,77 @@ $definition = [
279280

280281
## 🔧 Core Features
281282

283+
### Modern PHP 8.3+ Attributes
284+
285+
Enhance your workflow actions with declarative attributes for configuration:
286+
287+
```php
288+
<?php
289+
290+
namespace App\Actions;
291+
292+
use SolutionForest\WorkflowEngine\Attributes\WorkflowStep;
293+
use SolutionForest\WorkflowEngine\Attributes\Timeout;
294+
use SolutionForest\WorkflowEngine\Attributes\Retry;
295+
use SolutionForest\WorkflowEngine\Attributes\Condition;
296+
use SolutionForest\WorkflowEngine\Contracts\WorkflowAction;
297+
use SolutionForest\WorkflowEngine\Core\ActionResult;
298+
use SolutionForest\WorkflowEngine\Core\WorkflowContext;
299+
300+
#[WorkflowStep(
301+
id: 'send_email',
302+
name: 'Send Welcome Email',
303+
description: 'Sends a welcome email to new users'
304+
)]
305+
#[Timeout(minutes: 5)]
306+
#[Retry(attempts: 3, backoff: 'exponential')]
307+
#[Condition('user.email is not null')]
308+
class SendWelcomeEmailAction implements WorkflowAction
309+
{
310+
public function execute(WorkflowContext $context): ActionResult
311+
{
312+
$user = $context->getData('user');
313+
314+
// Send email logic here
315+
Mail::to($user['email'])->send(new WelcomeEmail($user));
316+
317+
return ActionResult::success(['email_sent' => true]);
318+
}
319+
}
320+
```
321+
322+
#### Available Attributes:
323+
324+
- **`#[WorkflowStep]`** - Define step metadata (id, name, description, config)
325+
- **`#[Timeout]`** - Set execution timeouts (seconds, minutes, hours)
326+
- **`#[Retry]`** - Configure retry behavior (attempts, backoff strategy, delays)
327+
- **`#[Condition]`** - Add conditional execution rules
328+
329+
### WorkflowBuilder Fluent API
330+
331+
Create workflows with an intuitive, chainable API:
332+
333+
```php
334+
use SolutionForest\WorkflowEngine\Core\WorkflowBuilder;
335+
336+
$workflow = WorkflowBuilder::create('user-onboarding')
337+
->description('Complete user onboarding process')
338+
->addStep('welcome', SendWelcomeEmailAction::class)
339+
->addStep('setup', SetupUserAction::class, ['template' => 'premium'])
340+
->when('user.plan === "premium"', function($builder) {
341+
$builder->addStep('premium-setup', PremiumSetupAction::class);
342+
})
343+
->email('tips-email', '{{ user.email }}', 'Getting Started Tips')
344+
->delay(hours: 24)
345+
->addStep('complete', CompleteOnboardingAction::class)
346+
->build();
347+
348+
// Start the workflow
349+
$workflowId = $workflow->start('user-001', [
350+
'user' => ['email' => 'john@example.com', 'plan' => 'premium']
351+
]);
352+
```
353+
282354
### Modern PHP 8.3+ Enums
283355

284356
```php

docs/advanced-features.md

Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,128 @@
11
# Advanced Features
22

3+
## PHP 8.3+ Attributes
4+
5+
Use declarative attributes to configure your workflow actions:
6+
7+
### WorkflowStep Attribute
8+
9+
Define step metadata directly on your action classes:
10+
11+
```php
12+
<?php
13+
14+
namespace App\Actions;
15+
16+
use SolutionForest\WorkflowEngine\Attributes\WorkflowStep;
17+
use SolutionForest\WorkflowEngine\Contracts\WorkflowAction;
18+
19+
#[WorkflowStep(
20+
id: 'send_email',
21+
name: 'Send Welcome Email',
22+
description: 'Sends a welcome email to new users',
23+
config: ['template' => 'welcome', 'async' => true],
24+
required: true,
25+
order: 1
26+
)]
27+
class SendWelcomeEmailAction implements WorkflowAction
28+
{
29+
// Action implementation...
30+
}
31+
```
32+
33+
### Timeout Attribute
34+
35+
Set execution timeouts for your actions:
36+
37+
```php
38+
use SolutionForest\WorkflowEngine\Attributes\Timeout;
39+
40+
// Single time unit
41+
#[Timeout(seconds: 30)]
42+
#[Timeout(minutes: 5)]
43+
#[Timeout(hours: 1)]
44+
45+
// Combined time units
46+
#[Timeout(minutes: 5, seconds: 30)] // 5 minutes 30 seconds
47+
class LongRunningAction implements WorkflowAction
48+
{
49+
// Action will timeout after specified duration
50+
}
51+
```
52+
53+
### Retry Attribute
54+
55+
Configure automatic retry behavior:
56+
57+
```php
58+
use SolutionForest\WorkflowEngine\Attributes\Retry;
59+
60+
// Basic retry configuration
61+
#[Retry(attempts: 3)]
62+
63+
// With backoff strategy
64+
#[Retry(attempts: 5, backoff: 'exponential')]
65+
#[Retry(attempts: 3, backoff: 'linear', delay: 1000)]
66+
67+
// Maximum delay cap
68+
#[Retry(attempts: 5, backoff: 'exponential', delay: 1000, maxDelay: 30000)]
69+
class UnreliableApiAction implements WorkflowAction
70+
{
71+
// Will automatically retry on failure
72+
}
73+
```
74+
75+
Available backoff strategies:
76+
- `linear` - Fixed delay between retries
77+
- `exponential` - Exponentially increasing delay
78+
- `fixed` - Same delay for all retries
79+
80+
### Condition Attribute
81+
82+
Add conditional execution rules:
83+
84+
```php
85+
use SolutionForest\WorkflowEngine\Attributes\Condition;
86+
87+
// Single condition
88+
#[Condition('user.email is not null')]
89+
90+
// Multiple conditions (repeatable attribute)
91+
#[Condition('user.email is not null')]
92+
#[Condition('order.amount > 100')]
93+
#[Condition('user.premium = true', operator: 'or')]
94+
class ConditionalAction implements WorkflowAction
95+
{
96+
// Only executes if conditions are met
97+
}
98+
```
99+
100+
Condition expressions support:
101+
- Property access: `user.email`, `order.amount`
102+
- Comparisons: `>`, `<`, `>=`, `<=`, `=`, `!=`
103+
- Null checks: `is null`, `is not null`
104+
- Operators: `and`, `or`
105+
106+
### Combining Attributes
107+
108+
You can use multiple attributes together:
109+
110+
```php
111+
#[WorkflowStep(
112+
id: 'process_payment',
113+
name: 'Process Payment',
114+
description: 'Processes customer payment'
115+
)]
116+
#[Timeout(minutes: 2)]
117+
#[Retry(attempts: 3, backoff: 'exponential')]
118+
#[Condition('order.amount > 0')]
119+
#[Condition('payment.method is not null')]
120+
class ProcessPaymentAction implements WorkflowAction
121+
{
122+
// Robust payment processing with timeout, retries, and conditions
123+
}
124+
```
125+
3126
## Error Handling and Retries
4127

5128
### Automatic Retries

docs/getting-started.md

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,41 @@ class CreateUserProfileAction implements WorkflowAction
9999
}
100100
```
101101

102+
### Enhanced Actions with Attributes
103+
104+
Use PHP 8.3+ attributes to add configuration directly to your action classes:
105+
106+
```php
107+
<?php
108+
109+
namespace App\Actions;
110+
111+
use SolutionForest\WorkflowEngine\Attributes\WorkflowStep;
112+
use SolutionForest\WorkflowEngine\Attributes\Timeout;
113+
use SolutionForest\WorkflowEngine\Attributes\Retry;
114+
use SolutionForest\WorkflowEngine\Contracts\WorkflowAction;
115+
use SolutionForest\WorkflowEngine\Core\WorkflowContext;
116+
use SolutionForest\WorkflowEngine\Core\ActionResult;
117+
118+
#[WorkflowStep(
119+
id: 'create_profile',
120+
name: 'Create User Profile',
121+
description: 'Creates a new user profile in the database'
122+
)]
123+
#[Timeout(seconds: 30)]
124+
#[Retry(attempts: 3, backoff: 'exponential')]
125+
class CreateUserProfileAction implements WorkflowAction
126+
{
127+
public function execute(WorkflowContext $context): ActionResult
128+
{
129+
// Same implementation as above
130+
// Now with automatic timeout and retry handling
131+
}
132+
}
133+
```
134+
135+
See the [Advanced Features](advanced-features.md) guide for more details on attributes.
136+
102137
## Workflow States
103138

104139
Workflows have built-in states that you can monitor:

0 commit comments

Comments
 (0)