1 | <?php |
||
13 | class FileActivator implements ActivatorInterface |
||
14 | { |
||
15 | /** |
||
16 | * Laravel cache instance |
||
17 | * |
||
18 | * @var CacheManager |
||
19 | */ |
||
20 | private $cache; |
||
21 | |||
22 | /** |
||
23 | * Laravel Filesystem instance |
||
24 | * |
||
25 | * @var Filesystem |
||
26 | */ |
||
27 | private $files; |
||
28 | |||
29 | /** |
||
30 | * Laravel config instance |
||
31 | * |
||
32 | * @var Config |
||
33 | */ |
||
34 | private $config; |
||
35 | |||
36 | /** |
||
37 | * @var string |
||
38 | */ |
||
39 | private $cacheKey; |
||
40 | |||
41 | /** |
||
42 | * @var string |
||
43 | */ |
||
44 | private $cacheLifetime; |
||
45 | |||
46 | /** |
||
47 | * Array of modules activation statuses |
||
48 | * |
||
49 | * @var array |
||
50 | */ |
||
51 | private $modulesStatuses; |
||
52 | |||
53 | /** |
||
54 | * File used to store activation statuses |
||
55 | * |
||
56 | * @var string |
||
57 | */ |
||
58 | private $statusesFile; |
||
59 | |||
60 | 191 | public function __construct(Container $app) |
|
70 | |||
71 | /** |
||
72 | * Get the path of the file where statuses are stored |
||
73 | * |
||
74 | * @return string |
||
75 | */ |
||
76 | 2 | public function getStatusesFilePath(): string |
|
80 | |||
81 | /** |
||
82 | * @inheritDoc |
||
83 | */ |
||
84 | 98 | public function reset(): void |
|
92 | |||
93 | /** |
||
94 | * @inheritDoc |
||
95 | */ |
||
96 | 6 | public function enable(Module $module): void |
|
100 | |||
101 | /** |
||
102 | * @inheritDoc |
||
103 | */ |
||
104 | 6 | public function disable(Module $module): void |
|
108 | |||
109 | /** |
||
110 | * @inheritDoc |
||
111 | */ |
||
112 | 16 | public function hasStatus(Module $module, bool $status): bool |
|
113 | { |
||
114 | 16 | if (!isset($this->modulesStatuses[$module->getName()])) { |
|
115 | 8 | return $status === false; |
|
116 | } |
||
117 | |||
118 | 8 | return $this->modulesStatuses[$module->getName()] === $status; |
|
119 | } |
||
120 | |||
121 | /** |
||
122 | * @inheritDoc |
||
123 | */ |
||
124 | 4 | public function setActive(Module $module, bool $active): void |
|
128 | |||
129 | /** |
||
130 | * @inheritDoc |
||
131 | */ |
||
132 | 130 | public function setActiveByName(string $name, bool $status): void |
|
138 | |||
139 | /** |
||
140 | * @inheritDoc |
||
141 | */ |
||
142 | 2 | public function delete(Module $module): void |
|
151 | |||
152 | /** |
||
153 | * Writes the activation statuses in a file, as json |
||
154 | */ |
||
155 | 130 | private function writeJson(): void |
|
159 | |||
160 | /** |
||
161 | * Reads the json file that contains the activation statuses. |
||
162 | * @return array |
||
163 | * @throws FileNotFoundException |
||
164 | */ |
||
165 | 191 | private function readJson(): array |
|
173 | |||
174 | /** |
||
175 | * Get modules statuses, either from the cache or from |
||
176 | * the json statuses file if the cache is disabled. |
||
177 | * @return array |
||
178 | * @throws FileNotFoundException |
||
179 | */ |
||
180 | 191 | private function getModulesStatuses(): array |
|
190 | |||
191 | /** |
||
192 | * Reads a config parameter under the 'activators.file' key |
||
193 | * |
||
194 | * @param string $key |
||
195 | * @param $default |
||
196 | * @return mixed |
||
197 | */ |
||
198 | 191 | private function config(string $key, $default = null) |
|
202 | |||
203 | /** |
||
204 | * Flushes the modules activation statuses cache |
||
205 | */ |
||
206 | 188 | private function flushCache() |
|
210 | } |
||
211 |