1 | <?php |
||
26 | class Pipeline extends AbstractObject implements PipelineInterface |
||
27 | { |
||
28 | /** |
||
29 | * @var StageInterface[]|callable[] |
||
30 | */ |
||
31 | protected $stages = []; |
||
32 | |||
33 | /** |
||
34 | * @var ProcessorInterface|null |
||
35 | */ |
||
36 | protected $processor = Processor::class; |
||
37 | |||
38 | /** |
||
39 | * @inheritdoc |
||
40 | */ |
||
41 | public function __construct($config = []) |
||
46 | |||
47 | /** |
||
48 | * @return callable[]|StageInterface[]|mixed|null |
||
49 | */ |
||
50 | protected function getStages() |
||
58 | |||
59 | /** |
||
60 | * @param $stage |
||
61 | * @return callable |
||
62 | * @throws InvalidArgumentException |
||
63 | */ |
||
64 | protected function resolveStage($stage): callable |
||
82 | |||
83 | /** |
||
84 | * @return ProcessorInterface |
||
85 | * @throws InvalidArgumentException |
||
86 | */ |
||
87 | public function getProcessor(): ProcessorInterface |
||
95 | |||
96 | /** |
||
97 | * @param $processor |
||
98 | * @return $this |
||
99 | */ |
||
100 | public function setProcessor($processor) |
||
105 | |||
106 | /** |
||
107 | * @param $processor |
||
108 | * @return ProcessorInterface |
||
109 | * @throws InvalidArgumentException |
||
110 | */ |
||
111 | protected function resolveProcessor($processor): ProcessorInterface |
||
132 | |||
133 | /** |
||
134 | * @inheritdoc |
||
135 | */ |
||
136 | public function pipe(callable $stage) |
||
143 | |||
144 | /** |
||
145 | * @param mixed $payload |
||
146 | * @param array $extra |
||
147 | * @return mixed |
||
148 | * @throws InvalidArgumentException |
||
149 | */ |
||
150 | public function process($payload, $extra = []) |
||
151 | { |
||
152 | if (!is_array($extra)) { |
||
153 | $extra = ['source' => $extra]; |
||
154 | } |
||
155 | |||
156 | return $this->getProcessor()->process($this->getStages(), $payload, $extra); |
||
157 | } |
||
158 | |||
159 | /** |
||
160 | * @inheritdoc |
||
161 | */ |
||
162 | public function __invoke($payload, $extra = []) |
||
166 | } |
||
167 |