| @@ 5-29 (lines=25) @@ | ||
| 2 | ||
| 3 | namespace MGDigital\BusQue\AutoQueue; |
|
| 4 | ||
| 5 | class AndDecider implements DeciderInterface |
|
| 6 | { |
|
| 7 | ||
| 8 | /** |
|
| 9 | * @var DeciderInterface[] |
|
| 10 | */ |
|
| 11 | private $deciders = []; |
|
| 12 | ||
| 13 | public function __construct(array $deciders) |
|
| 14 | { |
|
| 15 | array_walk($deciders, function (DeciderInterface $decider) { |
|
| 16 | $this->deciders[] = $decider; |
|
| 17 | }); |
|
| 18 | } |
|
| 19 | ||
| 20 | public function shouldBeQueued($command): bool |
|
| 21 | { |
|
| 22 | foreach ($this->deciders as $decider) { |
|
| 23 | if (!$decider->shouldBeQueued($command)) { |
|
| 24 | return false; |
|
| 25 | } |
|
| 26 | } |
|
| 27 | return true; |
|
| 28 | } |
|
| 29 | } |
|
| 30 | ||
| @@ 5-29 (lines=25) @@ | ||
| 2 | ||
| 3 | namespace MGDigital\BusQue\AutoQueue; |
|
| 4 | ||
| 5 | class OrDecider implements DeciderInterface |
|
| 6 | { |
|
| 7 | ||
| 8 | /** |
|
| 9 | * @var DeciderInterface[] |
|
| 10 | */ |
|
| 11 | private $deciders = []; |
|
| 12 | ||
| 13 | public function __construct(array $deciders) |
|
| 14 | { |
|
| 15 | array_walk($deciders, function (DeciderInterface $decider) { |
|
| 16 | $this->deciders[] = $decider; |
|
| 17 | }); |
|
| 18 | } |
|
| 19 | ||
| 20 | public function shouldBeQueued($command): bool |
|
| 21 | { |
|
| 22 | foreach ($this->deciders as $decider) { |
|
| 23 | if ($decider->shouldBeQueued($command)) { |
|
| 24 | return true; |
|
| 25 | } |
|
| 26 | } |
|
| 27 | return false; |
|
| 28 | } |
|
| 29 | } |
|
| 30 | ||