@@ -82,6 +82,45 @@ $result = Flowpipe::make()
82
82
// Result: "HELLO-WORLD!"
83
83
```
84
84
85
+ ### <span style =" color : #88C600 ;" >🎯 Factory Methods</span >
86
+
87
+ ** <span style =" color : #D2D200 ;" >Laravel Flowpipe</span >** provides convenient factory methods for creating instances with specific tracers:
88
+
89
+ ``` php
90
+ use Grazulex\LaravelFlowpipe\Flowpipe;
91
+
92
+ // Create with debug tracing (logs to file or console)
93
+ $debugFlow = Flowpipe::debug(true, 'flowpipe'); // logToFile=true, channel='flowpipe'
94
+ $result = $debugFlow
95
+ ->send($data)
96
+ ->through($steps)
97
+ ->thenReturn();
98
+
99
+ // Create with performance tracing
100
+ $perfFlow = Flowpipe::performance();
101
+ $result = $perfFlow
102
+ ->send($data)
103
+ ->through($steps)
104
+ ->thenReturn();
105
+
106
+ // Create with database tracing
107
+ $dbFlow = Flowpipe::database('custom_traces_table');
108
+ $result = $dbFlow
109
+ ->send($data)
110
+ ->through($steps)
111
+ ->thenReturn();
112
+
113
+ // Create with test tracing (for unit tests)
114
+ $testFlow = Flowpipe::test();
115
+ $result = $testFlow
116
+ ->send($data)
117
+ ->through($steps)
118
+ ->thenReturn();
119
+
120
+ // Standard make method (no tracing by default)
121
+ $flow = Flowpipe::make(); // or Flowpipe::make($customTracer)
122
+ ```
123
+
85
124
### <span style =" color : #D2D200 ;" >🛡️ Error Handling with Retry</span >
86
125
87
126
``` php
@@ -508,6 +547,82 @@ $result = Flowpipe::make()
508
547
->thenReturn();
509
548
```
510
549
550
+ ### <span style =" color : #88C600 ;" >🔧 Built-in Step Types</span >
551
+
552
+ ** <span style =" color : #00B470 ;" >Laravel Flowpipe</span >** includes various specialized step types for common operations:
553
+
554
+ ``` php
555
+ use Grazulex\LaravelFlowpipe\Flowpipe;
556
+
557
+ // Cache step - cache expensive operations
558
+ $result = Flowpipe::make()
559
+ ->send($userData)
560
+ ->cache('user_profile_' . $userData['id'], 3600) // Cache for 1 hour
561
+ ->through([
562
+ fn($data, $next) => $next(fetchUserProfile($data)),
563
+ ])
564
+ ->thenReturn();
565
+
566
+ // Transform step - transform data structure
567
+ $result = Flowpipe::make()
568
+ ->send($rawData)
569
+ ->transform(function ($data) {
570
+ return [
571
+ 'name' => strtoupper($data['name']),
572
+ 'email' => strtolower($data['email']),
573
+ 'created_at' => now(),
574
+ ];
575
+ })
576
+ ->through([
577
+ fn($data, $next) => $next(saveUser($data)),
578
+ ])
579
+ ->thenReturn();
580
+
581
+ // Validation step - validate data using Laravel validation
582
+ $result = Flowpipe::make()
583
+ ->send($inputData)
584
+ ->validate([
585
+ 'name' => 'required|string|max:255',
586
+ 'email' => 'required|email|unique:users',
587
+ 'age' => 'required|integer|min:18',
588
+ ])
589
+ ->through([
590
+ fn($data, $next) => $next(processValidData($data)),
591
+ ])
592
+ ->thenReturn();
593
+
594
+ // Batch step - process data in batches
595
+ $result = Flowpipe::make()
596
+ ->send($largeDataset)
597
+ ->batch(100) // Process 100 items at a time
598
+ ->through([
599
+ fn($batch, $next) => $next(processBatch($batch)),
600
+ ])
601
+ ->thenReturn();
602
+
603
+ // Rate limiting step - prevent API abuse
604
+ $result = Flowpipe::make()
605
+ ->send($apiRequest)
606
+ ->rateLimit('api_calls', 60, 1) // 60 calls per minute
607
+ ->through([
608
+ fn($data, $next) => $next(callExternalAPI($data)),
609
+ ])
610
+ ->thenReturn();
611
+
612
+ // Combine multiple step types
613
+ $result = Flowpipe::make()
614
+ ->send($complexData)
615
+ ->validate(['data' => 'required|array'])
616
+ ->transform(fn($data) => ['processed' => $data['data']])
617
+ ->cache('complex_operation', 1800)
618
+ ->batch(50)
619
+ ->rateLimit('processing', 30, 1)
620
+ ->through([
621
+ fn($data, $next) => $next(performComplexOperation($data)),
622
+ ])
623
+ ->thenReturn();
624
+ ```
625
+
511
626
### <span style =" color : #00B470 ;" >Error Handling in Production Workflows</span >
512
627
513
628
``` php
@@ -624,6 +739,19 @@ public function test_user_processing_flow()
624
739
$this->assertEquals('JOHN', $result);
625
740
$this->assertCount(1, $tracer->count());
626
741
}
742
+
743
+ // Or use the factory method for cleaner tests:
744
+ public function test_user_processing_flow_with_factory()
745
+ {
746
+ $result = Flowpipe::test()
747
+ ->send(['name' => 'John'])
748
+ ->through([
749
+ fn($data, $next) => $next(strtoupper($data['name'])),
750
+ ])
751
+ ->thenReturn();
752
+
753
+ $this->assertEquals('JOHN', $result);
754
+ }
627
755
```
628
756
629
757
## <span style =" color : #88C600 ;" >⚡ Performance</span >
@@ -668,10 +796,15 @@ public function test_user_processing_flow()
668
796
669
797
### <span style =" color : #88C600 ;" >Static Methods</span >
670
798
671
- - ** <span style =" color : #FF9900 ;" >` group(string $name, array $steps) ` </span >** - Define a reusable step group
672
- - ** <span style =" color : #D2D200 ;" >` hasGroup(string $name) ` </span >** - Check if a group exists
673
- - ** <span style =" color : #88C600 ;" >` getGroups() ` </span >** - Get all registered groups
674
- - ** <span style =" color : #00B470 ;" >` clearGroups() ` </span >** - Clear all registered groups (useful for testing)
799
+ - ** <span style =" color : #FF9900 ;" >` make(?Tracer $tracer = null) ` </span >** - Create a new flowpipe instance
800
+ - ** <span style =" color : #D2D200 ;" >` debug(bool $logToFile = false, string $logChannel = 'default') ` </span >** - Create instance with debug tracer
801
+ - ** <span style =" color : #88C600 ;" >` performance() ` </span >** - Create instance with performance tracer
802
+ - ** <span style =" color : #00B470 ;" >` database(string $tableName = 'flowpipe_traces') ` </span >** - Create instance with database tracer
803
+ - ** <span style =" color : #FF9900 ;" >` test() ` </span >** - Create instance with test tracer (for testing)
804
+ - ** <span style =" color : #D2D200 ;" >` group(string $name, array $steps) ` </span >** - Define a reusable step group
805
+ - ** <span style =" color : #88C600 ;" >` hasGroup(string $name) ` </span >** - Check if a group exists
806
+ - ** <span style =" color : #00B470 ;" >` getGroups() ` </span >** - Get all registered groups
807
+ - ** <span style =" color : #FF9900 ;" >` clearGroups() ` </span >** - Clear all registered groups (useful for testing)
675
808
676
809
### <span style =" color : #00B470 ;" >Conditional Steps</span >
677
810
0 commit comments