1 | <?php |
||
2 | |||
3 | namespace SRIO\ChainOfResponsibility; |
||
4 | |||
5 | class ProcessCollection |
||
6 | { |
||
7 | /** |
||
8 | * @var ChainProcessInterface[] |
||
9 | */ |
||
10 | private $processes; |
||
11 | |||
12 | /** |
||
13 | * Add a process to the collection. |
||
14 | * |
||
15 | * @param array|ChainProcessInterface $process |
||
16 | */ |
||
17 | 10 | public function add($process) |
|
18 | { |
||
19 | 10 | if (is_array($process)) { |
|
20 | 10 | foreach ($process as $p) { |
|
21 | 9 | $this->add($p); |
|
22 | 10 | } |
|
23 | 10 | } elseif (!$process instanceof ChainProcessInterface) { |
|
24 | throw new \RuntimeException(sprintf( |
||
25 | 'Expect to be instance of ChainProcessInterface or array but got %s', |
||
26 | get_class($process) |
||
27 | )); |
||
28 | } else { |
||
29 | 9 | $this->processes[] = $process; |
|
30 | } |
||
31 | 10 | } |
|
32 | |||
33 | /** |
||
34 | * @return ChainProcessInterface[] |
||
35 | */ |
||
36 | 10 | public function getProcesses() |
|
37 | { |
||
38 | 10 | return $this->processes; |
|
39 | } |
||
40 | } |
||
41 |