1 | <?php |
||
10 | class ChainExitStrategy implements ExitStrategy |
||
11 | { |
||
12 | private $reason; |
||
13 | |||
14 | /** @var array|ExitStrategy[] */ |
||
15 | private $exitStrategies = []; |
||
16 | |||
17 | /** |
||
18 | * @param array|ExitStrategy[] $exitStrategies |
||
19 | */ |
||
20 | 4 | public function __construct(array $exitStrategies = []) |
|
21 | { |
||
22 | foreach ($exitStrategies as $exitStrategy) { |
||
23 | $this->addExitStrategy($exitStrategy); |
||
24 | 4 | } |
|
25 | } |
||
26 | |||
27 | 3 | public function addExitStrategy(ExitStrategy $exitStrategy) |
|
28 | { |
||
29 | 3 | $this->exitStrategies[] = $exitStrategy; |
|
30 | } |
||
31 | |||
32 | /** |
||
33 | * {@inheritdoc} |
||
34 | */ |
||
35 | 7 | public function shouldExit($count) |
|
36 | { |
||
37 | 7 | foreach ($this->exitStrategies as $exitStrategy) { |
|
38 | if ($exitStrategy->shouldExit($count)) { |
||
39 | $this->reason = $exitStrategy->getReason(); |
||
40 | |||
41 | 6 | return true; |
|
42 | } |
||
43 | 3 | } |
|
44 | |||
45 | 1 | return false; |
|
46 | } |
||
47 | |||
48 | /** |
||
49 | * {@inheritdoc} |
||
50 | */ |
||
51 | 6 | public function getReason() |
|
55 | } |
||
56 |