|
| 1 | +<?php |
| 2 | + |
| 3 | +declare(strict_types=1); |
| 4 | + |
| 5 | +namespace Kiboko\Component\Runtime\Workflow; |
| 6 | + |
| 7 | +use Kiboko\Component\Runtime\Pipeline\Console as PipelineConsoleRuntime; |
| 8 | +use Kiboko\Component\Runtime\Pipeline\PipelineRuntimeInterface; |
| 9 | +use Kiboko\Component\State; |
| 10 | +use Kiboko\Contract\Pipeline\ExtractorInterface; |
| 11 | +use Kiboko\Contract\Pipeline\LoaderInterface; |
| 12 | +use Kiboko\Contract\Pipeline\PipelineInterface; |
| 13 | +use Kiboko\Contract\Pipeline\RejectionInterface; |
| 14 | +use Kiboko\Contract\Pipeline\StateInterface; |
| 15 | +use Kiboko\Contract\Pipeline\TransformerInterface; |
| 16 | +use Kiboko\Contract\Pipeline\WalkableInterface; |
| 17 | +use Symfony\Component\Console\Output\ConsoleOutput; |
| 18 | + |
| 19 | +class PipelineProxy implements PipelineRuntimeInterface |
| 20 | +{ |
| 21 | + private $factory; |
| 22 | + |
| 23 | + public function __construct( |
| 24 | + callable $factory, |
| 25 | + private readonly ConsoleOutput $output, |
| 26 | + private readonly PipelineInterface&WalkableInterface $pipeline, |
| 27 | + private readonly State\StateOutput\Workflow $state, |
| 28 | + private readonly string $filename, |
| 29 | + ) { |
| 30 | + $this->factory = $factory; |
| 31 | + } |
| 32 | + |
| 33 | + public function extract( |
| 34 | + ExtractorInterface $extractor, |
| 35 | + RejectionInterface $rejection, |
| 36 | + StateInterface $state, |
| 37 | + ): self { |
| 38 | + $this->pipeline->extract($extractor, $rejection, $state); |
| 39 | + |
| 40 | + return $this; |
| 41 | + } |
| 42 | + |
| 43 | + public function transform( |
| 44 | + TransformerInterface $transformer, |
| 45 | + RejectionInterface $rejection, |
| 46 | + StateInterface $state, |
| 47 | + ): self { |
| 48 | + $this->pipeline->transform($transformer, $rejection, $state); |
| 49 | + |
| 50 | + return $this; |
| 51 | + } |
| 52 | + |
| 53 | + public function load( |
| 54 | + LoaderInterface $loader, |
| 55 | + RejectionInterface $rejection, |
| 56 | + StateInterface $state, |
| 57 | + ): self { |
| 58 | + $this->pipeline->load($loader, $rejection, $state); |
| 59 | + |
| 60 | + return $this; |
| 61 | + } |
| 62 | + |
| 63 | + public function run(int $interval = 1000): int |
| 64 | + { |
| 65 | + $runtime = new PipelineConsoleRuntime($this->output, $this->pipeline, $this->state->withPipeline($this->filename)); |
| 66 | + |
| 67 | + $pipeline = ($this->factory)($runtime); |
| 68 | + |
| 69 | + return $pipeline->run($interval); |
| 70 | + } |
| 71 | +} |
0 commit comments