1: <?php declare(strict_types=1);
2:
3: namespace Salient\Contract\Core\Pipeline;
4:
5: use Salient\Contract\Core\Chainable;
6: use Salient\Contract\Core\Immutable;
7: use Salient\Contract\HasConformity;
8: use Closure;
9:
10: /**
11: * @api
12: *
13: * @template TInput
14: * @template TOutput
15: * @template TArgument
16: */
17: interface BasePipelineInterface extends Chainable, Immutable, HasConformity
18: {
19: /**
20: * Apply a closure to each payload before it is sent
21: *
22: * This method can only be called once per pipeline.
23: *
24: * @param Closure(TInput $payload, static $pipeline, TArgument $arg): (TInput|TOutput) $closure
25: * @return static
26: */
27: public function after(Closure $closure);
28:
29: /**
30: * Apply a closure to each payload before it is sent if after() hasn't
31: * already been called
32: *
33: * @param Closure(TInput $payload, static $pipeline, TArgument $arg): (TInput|TOutput) $closure
34: * @return static
35: */
36: public function afterIf(Closure $closure);
37:
38: /**
39: * Add a pipe to the pipeline
40: *
41: * A pipe should do something with the `$payload` it receives before taking
42: * one of the following actions:
43: *
44: * - return the value of `$next($payload)`
45: * - return a value that will be discarded by
46: * {@see StreamPipelineInterface::unless()}, bypassing any remaining pipes
47: * and {@see BasePipelineInterface::then()}, if applicable
48: * - throw an exception
49: *
50: * @param (Closure(TInput $payload, Closure $next, static $pipeline, TArgument $arg): (TInput|TOutput))|(Closure(TOutput $payload, Closure $next, static $pipeline, TArgument $arg): TOutput) $pipe
51: * @return static
52: */
53: public function through(Closure $pipe);
54:
55: /**
56: * Add a simple closure to the pipeline
57: *
58: * @param (Closure(TInput $payload, static $pipeline, TArgument $arg): (TInput|TOutput))|(Closure(TOutput $payload, static $pipeline, TArgument $arg): TOutput) $closure
59: * @return static
60: */
61: public function throughClosure(Closure $closure);
62:
63: /**
64: * Add an array key mapper to the pipeline
65: *
66: * @param array<array-key,array-key|array-key[]> $keyMap An array that maps
67: * input keys to one or more output keys.
68: * @param int-mask-of<ArrayMapperInterface::REMOVE_NULL|ArrayMapperInterface::ADD_UNMAPPED|ArrayMapperInterface::ADD_MISSING|ArrayMapperInterface::REQUIRE_MAPPED> $flags
69: * @return static
70: */
71: public function throughKeyMap(array $keyMap, int $flags = ArrayMapperInterface::ADD_UNMAPPED);
72:
73: /**
74: * Apply a closure to each result
75: *
76: * This method can only be called once per pipeline, and only if
77: * {@see StreamPipelineInterface::collectThen()} is not also called.
78: *
79: * @param (Closure(TInput $result, static $pipeline, TArgument $arg): TOutput)|(Closure(TOutput $result, static $pipeline, TArgument $arg): TOutput) $closure
80: * @return static
81: */
82: public function then(Closure $closure);
83:
84: /**
85: * Apply a closure to each result if then() hasn't already been called
86: *
87: * @param (Closure(TInput $result, static $pipeline, TArgument $arg): TOutput)|(Closure(TOutput $result, static $pipeline, TArgument $arg): TOutput) $closure
88: * @return static
89: */
90: public function thenIf(Closure $closure);
91:
92: /**
93: * Pass each result to a closure
94: *
95: * Results not discarded by {@see StreamPipelineInterface::unless()} are
96: * passed to the closure before leaving the pipeline. The closure's return
97: * value is ignored.
98: *
99: * @param Closure(TOutput $result, static $pipeline, TArgument $arg): mixed $closure
100: * @return static
101: */
102: public function cc(Closure $closure);
103: }
104: