Total Complexity | 12 |
Total Lines | 75 |
Duplicated Lines | 0 % |
Coverage | 40% |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
9 | class ModulesManager |
||
10 | { |
||
11 | |||
12 | /** |
||
13 | * @var ModulesCollection |
||
14 | */ |
||
15 | protected $modules = null; |
||
16 | |||
17 | |||
18 | /** |
||
19 | * @param $name |
||
20 | */ |
||
21 | public function addModule($name) |
||
22 | { |
||
23 | if (!$this->getModules()->offsetExists($name)) { |
||
24 | $this->getModules()->set($name, $name); |
||
25 | } |
||
26 | } |
||
27 | |||
28 | /** |
||
29 | * @param $name |
||
30 | * |
||
31 | * @return string |
||
32 | */ |
||
33 | public function getViewPath($name) |
||
34 | { |
||
35 | return $this->getModuleDirectory($name) . DIRECTORY_SEPARATOR . 'views' . DIRECTORY_SEPARATOR; |
||
36 | } |
||
37 | |||
38 | /** |
||
39 | * @param $name |
||
40 | * |
||
41 | * @return string |
||
42 | */ |
||
43 | public function getModuleDirectory($name) |
||
44 | { |
||
45 | return $this->getModulesBaseDirectory() . $name; |
||
46 | } |
||
47 | |||
48 | /** |
||
49 | * @return string |
||
50 | */ |
||
51 | public function getModulesBaseDirectory() |
||
52 | { |
||
53 | return defined('MODULES_PATH') ? |
||
54 | MODULES_PATH |
||
|
|||
55 | : app('path') . DIRECTORY_SEPARATOR . 'modules' . DIRECTORY_SEPARATOR; |
||
56 | } |
||
57 | |||
58 | /** |
||
59 | * @return ModulesCollection |
||
60 | */ |
||
61 | 1 | public function getModules(): ModulesCollection |
|
62 | { |
||
63 | 1 | if ($this->modules === null) { |
|
64 | 1 | $this->modules = new ModulesCollection(); |
|
65 | 1 | $this->loadFromConfig(); |
|
66 | } |
||
67 | 1 | return $this->modules; |
|
68 | } |
||
69 | |||
70 | /** |
||
71 | * @param ModulesCollection $sections |
||
72 | */ |
||
73 | public function setModules(ModulesCollection $sections): void |
||
74 | { |
||
75 | $this->modules = $sections; |
||
76 | } |
||
77 | |||
78 | 1 | protected function loadFromConfig() |
|
84 | } |
||
85 | } |
||
86 | 1 | } |
|
87 | } |
||
88 |