/
SamplePipeline.php
65 lines (56 loc) · 1.87 KB
/
SamplePipeline.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
<?php
declare(strict_types=1);
namespace Shampine\Tests\Sample;
use League\Pipeline\Pipeline;
use Shampine\Sequence\Pipeline\AbstractPipeline;
use Shampine\Sequence\Process\ChildPipelineProcess;
use Shampine\Sequence\Process\HydrateResponseProcess;
class SamplePipeline extends AbstractPipeline
{
/**
* @constant string
*/
public const SAMPLE_PIPELINE = 'SamplePipeline';
/**
* @constant string
*/
public const SAMPLE_CHILD_PIPELINE = 'SampleChildPipeline';
/**
* @constant string
*/
public const SAMPLE_NO_PROCESS_PIPELINE = 'SampleNoProcessPipeline';
/**
* @param SampleUseService|null $sampleUseService
*/
public function __construct(?SampleUseService $sampleUseService = null)
{
$this->pipelines = [
self::SAMPLE_PIPELINE => static function(
bool $validationFailure = false,
bool $sequenceFailure = false
) use ($sampleUseService)
{
return (new Pipeline)
->pipe(new ValidationExceptionProcess($validationFailure, $sampleUseService))
->pipe(new SequenceExceptionProcess($sequenceFailure))
->pipe(new HydrateResponseProcess(SampleResponse::class));
},
self::SAMPLE_CHILD_PIPELINE => static function()
{
return (new Pipeline)
->pipe(new ChildPipelineProcess())
->pipe(new HydrateResponseProcess(SampleResponse::class));
},
self::SAMPLE_NO_PROCESS_PIPELINE => static function() {
return (new Pipeline)
->pipe(new NoProcessExceptionProcess());
},
];
$this->excludeWhenEmpty = [
'empty_value',
];
$this->excludeWhenNull = [
'null_value',
];
}
}