Skip to content

Commit dcdcd18

Browse files
committed
Updated pipeline contracts to v0.5
1 parent 3bc1ba7 commit dcdcd18

File tree

8 files changed

+215
-96
lines changed

8 files changed

+215
-96
lines changed

composer.json

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
"php": "^8.2",
2020
"psr/log": "^3.0",
2121
"php-etl/bucket": "*",
22-
"php-etl/pipeline-contracts": "0.4.*",
22+
"php-etl/pipeline-contracts": "0.5.*",
2323
"php-etl/bucket-contracts": "0.2.*"
2424
},
2525
"require-dev": {
@@ -31,7 +31,7 @@
3131
"rector/rector": "^0.15"
3232
},
3333
"provide": {
34-
"php-etl/pipeline-implementation": "0.3.0"
34+
"php-etl/pipeline-implementation": "0.5.0"
3535
},
3636
"autoload": {
3737
"psr-4": {
@@ -46,12 +46,13 @@
4646
"config": {
4747
"bin-dir": "bin",
4848
"allow-plugins": {
49-
"infection/extension-installer": true
49+
"infection/extension-installer": true,
50+
"php-http/discovery": true
5051
}
5152
},
5253
"extra": {
5354
"branch-alias": {
54-
"dev-main": "0.5.x-dev"
55+
"dev-main": "0.6.x-dev"
5556
}
5657
}
5758
}

composer.lock

Lines changed: 63 additions & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Extractor/IteratorExtractor.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
namespace Kiboko\Component\Pipeline\Extractor;
66

7+
use Kiboko\Component\Bucket\AcceptanceResultBucket;
78
use Kiboko\Contract\Pipeline\ExtractorInterface;
89

910
class IteratorExtractor implements ExtractorInterface

src/Pipeline.php

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@
1414
use Kiboko\Contract\Pipeline\RejectionInterface;
1515
use Kiboko\Contract\Pipeline\RunnableInterface;
1616
use Kiboko\Contract\Pipeline\StateInterface;
17+
use Kiboko\Contract\Pipeline\StepCodeInterface;
18+
use Kiboko\Contract\Pipeline\StepRejectionInterface;
19+
use Kiboko\Contract\Pipeline\StepStateInterface;
1720
use Kiboko\Contract\Pipeline\TransformerInterface;
1821
use Kiboko\Contract\Pipeline\TransformingInterface;
1922
use 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

src/PipelineRunner.php

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
use Kiboko\Contract\Pipeline\PipelineRunnerInterface;
1111
use Kiboko\Contract\Pipeline\RejectionInterface;
1212
use Kiboko\Contract\Pipeline\StateInterface;
13+
use Kiboko\Contract\Pipeline\StepRejectionInterface;
14+
use Kiboko\Contract\Pipeline\StepStateInterface;
1315
use Psr\Log\LoggerInterface;
1416
use Psr\Log\LogLevel;
1517
use Psr\Log\NullLogger;
@@ -23,12 +25,9 @@ public function __construct(private readonly LoggerInterface $logger = new NullL
2325
public function run(
2426
\Iterator $source,
2527
\Generator $coroutine,
26-
RejectionInterface $rejection,
27-
StateInterface $state,
28+
StepRejectionInterface $rejection,
29+
StepStateInterface $state,
2830
): \Iterator {
29-
$state->initialize();
30-
$rejection->initialize();
31-
3231
$wrapper = new GeneratorWrapper();
3332
$wrapper->rewind($source, $coroutine);
3433

@@ -69,8 +68,5 @@ public function run(
6968

7069
$wrapper->next($source);
7170
}
72-
73-
$state->teardown();
74-
$rejection->teardown();
7571
}
7672
}

src/StepCode.php

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Kiboko\Component\Pipeline;
6+
7+
use Kiboko\Contract\Pipeline\StepCodeInterface;
8+
9+
final class StepCode implements StepCodeInterface
10+
{
11+
private function __construct(
12+
private readonly string $reference,
13+
) {
14+
}
15+
16+
public static function fromString(string $reference): self
17+
{
18+
return new self($reference);
19+
}
20+
21+
public function __toString(): string
22+
{
23+
return $this->reference;
24+
}
25+
}

tests/unit/PipelineRunnerTest.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
use Kiboko\Component\Pipeline\PipelineRunner;
1010
use Kiboko\Contract\Pipeline\NullRejection;
1111
use Kiboko\Contract\Pipeline\NullState;
12+
use Kiboko\Contract\Pipeline\NullStepRejection;
13+
use Kiboko\Contract\Pipeline\NullStepState;
1214
use PHPUnit\Framework\TestResult;
1315
use Psr\Log\NullLogger;
1416

@@ -115,7 +117,7 @@ public function testRun(\Iterator $source, callable $callback, array $expected):
115117
{
116118
$run = new PipelineRunner(new NullLogger());
117119

118-
$it = $run->run($source, $callback(), new NullRejection(), new NullState());
120+
$it = $run->run($source, $callback(), new NullStepRejection(), new NullStepState());
119121

120122
$this->assertIteration(new \ArrayIterator($expected), $it);
121123
}

0 commit comments

Comments
 (0)