@@ 5-56 (lines=52) @@ | ||
2 | ||
3 | namespace Rudolf\Component\Modules; |
|
4 | ||
5 | class Collection |
|
6 | { |
|
7 | /** |
|
8 | * @var Module[] |
|
9 | */ |
|
10 | private $collection; |
|
11 | ||
12 | /** |
|
13 | * Add module to collection. |
|
14 | * |
|
15 | * @param string $name Module name |
|
16 | * @param Module $module Module object |
|
17 | */ |
|
18 | public function add($name, Module $module) |
|
19 | { |
|
20 | $this->collection[$name] = $module; |
|
21 | } |
|
22 | ||
23 | /** |
|
24 | * Get all modules. |
|
25 | * |
|
26 | * @return Module[] |
|
27 | */ |
|
28 | public function getAll() |
|
29 | { |
|
30 | return $this->collection; |
|
31 | } |
|
32 | ||
33 | /** |
|
34 | * Get active modules. |
|
35 | * |
|
36 | * @return Module[] |
|
37 | */ |
|
38 | public function getActive() |
|
39 | { |
|
40 | if (empty($this->collection)) { |
|
41 | return []; |
|
42 | } |
|
43 | ||
44 | foreach ($this->collection as $key => $value) { |
|
45 | if ($value->getStatus()) { |
|
46 | $collection[] = $value; |
|
47 | } |
|
48 | } |
|
49 | ||
50 | if (empty($collection)) { |
|
51 | return []; |
|
52 | } |
|
53 | ||
54 | return $collection; |
|
55 | } |
|
56 | } |
|
57 |
@@ 5-56 (lines=52) @@ | ||
2 | ||
3 | namespace Rudolf\Component\Plugins; |
|
4 | ||
5 | class Collection |
|
6 | { |
|
7 | /** |
|
8 | * @var array |
|
9 | */ |
|
10 | private $collection = []; |
|
11 | ||
12 | /** |
|
13 | * Add plugin to collection. |
|
14 | * |
|
15 | * @param string $name Plugin name |
|
16 | * @param Plugin $plugin Plugin object |
|
17 | */ |
|
18 | public function add($name, Plugin $plugin) |
|
19 | { |
|
20 | $this->collection[$name] = $plugin; |
|
21 | } |
|
22 | ||
23 | /** |
|
24 | * Get all plugins. |
|
25 | * |
|
26 | * @return Plugin[] |
|
27 | */ |
|
28 | public function getAll() |
|
29 | { |
|
30 | return $this->collection; |
|
31 | } |
|
32 | ||
33 | /** |
|
34 | * Get active plugins. |
|
35 | * |
|
36 | * @return Plugin[] |
|
37 | */ |
|
38 | public function getActive() |
|
39 | { |
|
40 | if (empty($this->collection)) { |
|
41 | return []; |
|
42 | } |
|
43 | ||
44 | foreach ($this->collection as $key => $value) { |
|
45 | if ($value->getStatus()) { |
|
46 | $collection[] = $value; |
|
47 | } |
|
48 | } |
|
49 | ||
50 | if (empty($collection)) { |
|
51 | return []; |
|
52 | } |
|
53 | ||
54 | return $collection; |
|
55 | } |
|
56 | } |
|
57 |