1414use Kiboko \Contract \Pipeline \RejectionInterface ;
1515use Kiboko \Contract \Pipeline \RunnableInterface ;
1616use Kiboko \Contract \Pipeline \StateInterface ;
17+ use Kiboko \Contract \Pipeline \StepCodeInterface ;
18+ use Kiboko \Contract \Pipeline \StepRejectionInterface ;
19+ use Kiboko \Contract \Pipeline \StepStateInterface ;
1720use Kiboko \Contract \Pipeline \TransformerInterface ;
1821use Kiboko \Contract \Pipeline \TransformingInterface ;
1922use Kiboko \Contract \Pipeline \WalkableInterface ;
@@ -23,8 +26,11 @@ class Pipeline implements PipelineInterface, WalkableInterface, RunnableInterfac
2326 private readonly \AppendIterator $ source ;
2427 private iterable $ subject ;
2528
26- public function __construct (private readonly PipelineRunnerInterface $ runner , ?\Iterator $ source = null )
27- {
29+ public function __construct (
30+ private readonly PipelineRunnerInterface $ runner ,
31+ private readonly StateInterface $ state ,
32+ ?\Iterator $ source = null
33+ ) {
2834 $ this ->source = new \AppendIterator ();
2935 $ this ->source ->append ($ source ?? new \EmptyIterator ());
3036
@@ -39,14 +45,14 @@ public function feed(...$data): void
3945 private function passThroughCoroutine (): \Generator
4046 {
4147 $ line = yield ;
42- while ($ line = yield $ line ) {
43- }
48+ while ($ line = yield $ line );
4449 }
4550
4651 public function extract (
52+ StepCodeInterface $ stepCode ,
4753 ExtractorInterface $ extractor ,
48- RejectionInterface $ rejection ,
49- StateInterface $ state ,
54+ StepRejectionInterface $ rejection ,
55+ StepStateInterface $ state ,
5056 ): ExtractingInterface {
5157 $ extract = $ extractor ->extract ();
5258 if (\is_array ($ extract )) {
@@ -84,9 +90,10 @@ public function extract(
8490 }
8591
8692 public function transform (
93+ StepCodeInterface $ stepCode ,
8794 TransformerInterface $ transformer ,
88- RejectionInterface $ rejection ,
89- StateInterface $ state ,
95+ StepRejectionInterface $ rejection ,
96+ StepStateInterface $ state ,
9097 ): TransformingInterface {
9198 if ($ transformer instanceof FlushableInterface) {
9299 $ iterator = new \AppendIterator ();
@@ -125,9 +132,10 @@ public function transform(
125132 }
126133
127134 public function load (
135+ StepCodeInterface $ stepCode ,
128136 LoaderInterface $ loader ,
129- RejectionInterface $ rejection ,
130- StateInterface $ state ,
137+ StepRejectionInterface $ rejection ,
138+ StepStateInterface $ state ,
131139 ): LoadingInterface {
132140 if ($ loader instanceof FlushableInterface) {
133141 $ iterator = new \AppendIterator ();
@@ -168,7 +176,11 @@ public function load(
168176
169177 public function walk (): \Iterator
170178 {
179+ $ this ->state ->initialize ();
180+
171181 yield from $ this ->subject ;
182+
183+ $ this ->state ->teardown ();
172184 }
173185
174186 public function run (int $ interval = 1000 ): int
0 commit comments