1: | <?php declare(strict_types=1); |
2: | |
3: | namespace Salient\Contract\Core\Pipeline; |
4: | |
5: | use Closure; |
6: | |
7: | /** |
8: | * @api |
9: | * |
10: | * @template TInput |
11: | * @template TOutput |
12: | * @template TArgument |
13: | * |
14: | * @extends PayloadPipelineInterface<TInput,TOutput,TArgument> |
15: | */ |
16: | interface StreamPipelineInterface extends PayloadPipelineInterface |
17: | { |
18: | /** |
19: | * Pass results to a closure in batches |
20: | * |
21: | * This method can only be called once per pipeline, and only if |
22: | * {@see BasePipelineInterface::then()} is not also called. |
23: | * |
24: | * Values returned by the closure are returned to the caller via a |
25: | * forward-only iterator. |
26: | * |
27: | * @param (Closure(array<TInput> $results, static $pipeline, TArgument $arg): iterable<TOutput>|Closure(array<TOutput> $results, static $pipeline, TArgument $arg): iterable<TOutput>) $closure |
28: | * @return static |
29: | */ |
30: | public function collectThen(Closure $closure); |
31: | |
32: | /** |
33: | * Pass results to a closure in batches if collectThen() hasn't already been |
34: | * called |
35: | * |
36: | * @param (Closure(array<TInput> $results, static $pipeline, TArgument $arg): iterable<TOutput>|Closure(array<TOutput> $results, static $pipeline, TArgument $arg): iterable<TOutput>) $closure |
37: | * @return static |
38: | */ |
39: | public function collectThenIf(Closure $closure); |
40: | |
41: | /** |
42: | * Apply a filter to each result |
43: | * |
44: | * This method can only be called once per pipeline. |
45: | * |
46: | * If `$filter` returns `false`, `$result` is returned to the caller, |
47: | * otherwise it is discarded. |
48: | * |
49: | * @param Closure(TOutput|null $result, static $pipeline, TArgument $arg): bool $filter |
50: | * @return static |
51: | */ |
52: | public function unless(Closure $filter); |
53: | |
54: | /** |
55: | * Apply a filter to each result if unless() hasn't already been called |
56: | * |
57: | * @param Closure(TOutput|null $result, static $pipeline, TArgument $arg): bool $filter |
58: | * @return static |
59: | */ |
60: | public function unlessIf(Closure $filter); |
61: | |
62: | /** |
63: | * Run the pipeline with each of the payload's values and return the results |
64: | * via a forward-only iterator |
65: | * |
66: | * @return iterable<TOutput> |
67: | */ |
68: | public function start(): iterable; |
69: | |
70: | /** |
71: | * Run the pipeline and pass each result to another pipeline |
72: | * |
73: | * @template TNextOutput |
74: | * |
75: | * @param PipelineInterface<TOutput,TNextOutput,TArgument> $next |
76: | * @return StreamPipelineInterface<TOutput,TNextOutput,TArgument> |
77: | */ |
78: | public function startInto(PipelineInterface $next); |
79: | } |
80: |