@@ -99,7 +99,7 @@ |
||
99 | 99 | $this->importConfig(); |
100 | 100 | $this->initModule($this->getOption('module')); |
101 | 101 | $this->initType($this->getOption('type')); |
102 | - }catch (Exception $e){ |
|
102 | + } catch (Exception $e){ |
|
103 | 103 | $this->error($e->getMessage()); |
104 | 104 | return; |
105 | 105 | } |
@@ -30,214 +30,214 @@ |
||
30 | 30 | class ResourceCacheClearCommand extends QtCommand |
31 | 31 | { |
32 | 32 | |
33 | - /** |
|
34 | - * Command name |
|
35 | - * @var string |
|
36 | - */ |
|
37 | - protected $name = 'cache:clear'; |
|
38 | - |
|
39 | - /** |
|
40 | - * Command description |
|
41 | - * @var string |
|
42 | - */ |
|
43 | - protected $description = 'Clears resource cache'; |
|
44 | - |
|
45 | - /** |
|
46 | - * Command help text |
|
47 | - * @var string |
|
48 | - */ |
|
49 | - protected $help = 'The command will clear the resource cache'; |
|
50 | - |
|
51 | - /** |
|
52 | - * Command options |
|
53 | - * @var array |
|
54 | - */ |
|
55 | - protected $options = [ |
|
56 | - ['all', 'all', 'none', ''], |
|
57 | - ['type', 't', 'required', ''], |
|
58 | - ['module', 'm', 'required', ''] |
|
59 | - ]; |
|
60 | - |
|
61 | - /** |
|
62 | - * @var array |
|
63 | - */ |
|
64 | - protected $types = ['views', 'asserts']; |
|
65 | - |
|
66 | - /** |
|
67 | - * @var array |
|
68 | - */ |
|
69 | - protected $modules; |
|
70 | - |
|
71 | - /** |
|
72 | - * @var string|null |
|
73 | - */ |
|
74 | - protected $type = null; |
|
75 | - |
|
76 | - /** |
|
77 | - * @var string|null |
|
78 | - */ |
|
79 | - protected $module = null; |
|
80 | - |
|
81 | - /** |
|
82 | - * @var string |
|
83 | - */ |
|
84 | - protected $cacheDir; |
|
85 | - |
|
86 | - /** |
|
87 | - * @var object |
|
88 | - */ |
|
89 | - protected $fs; |
|
90 | - |
|
91 | - /** |
|
92 | - * @return void |
|
93 | - * @throws DiException |
|
94 | - * @throws ReflectionException |
|
95 | - */ |
|
96 | - public function exec() |
|
97 | - { |
|
98 | - try { |
|
99 | - $this->importConfig(); |
|
100 | - $this->initModule($this->getOption('module')); |
|
101 | - $this->initType($this->getOption('type')); |
|
102 | - }catch (Exception $e){ |
|
103 | - $this->error($e->getMessage()); |
|
104 | - return; |
|
105 | - } |
|
106 | - |
|
107 | - $this->fs = Di::get(FileSystem::class); |
|
108 | - |
|
109 | - if (!$this->fs->isDirectory($this->cacheDir)) { |
|
110 | - $this->error('Cache directory does not exist or is not accessible.'); |
|
111 | - return; |
|
112 | - } |
|
113 | - |
|
114 | - if ($this->module || $this->type) { |
|
115 | - $this->clearResourceModuleAndType($this->module, $this->type); |
|
116 | - } elseif (!empty($this->getOption('all'))) { |
|
117 | - $this->removeFilesFromDirectory($this->cacheDir); |
|
118 | - } else { |
|
119 | - $this->error('Please specify at least one of the following options: --all, --module=moduleName or --type=typeName!'); |
|
120 | - return; |
|
121 | - } |
|
122 | - |
|
123 | - $this->info('Resource cache cleared successfully.'); |
|
124 | - } |
|
125 | - |
|
126 | - /** |
|
127 | - * @return void |
|
128 | - */ |
|
129 | - private function importModules() |
|
130 | - { |
|
131 | - try { |
|
132 | - if (!config()->has('modules')) { |
|
133 | - config()->import(new Setup('config', 'modules')); |
|
134 | - } |
|
135 | - |
|
136 | - if (config()->has('modules') && is_array(config()->get('modules.modules'))){ |
|
137 | - $this->modules = array_keys(array_change_key_case(config()->get('modules.modules'))); |
|
138 | - } |
|
139 | - } catch (ConfigException|DiException|ReflectionException $e) { |
|
140 | - $this->error($e->getMessage()); |
|
141 | - return; |
|
142 | - } |
|
143 | - } |
|
144 | - |
|
145 | - /** |
|
146 | - * @return void |
|
147 | - * @throws ConfigException |
|
148 | - * @throws DiException |
|
149 | - * @throws ReflectionException |
|
150 | - */ |
|
151 | - private function importConfig(): void |
|
152 | - { |
|
153 | - if (!config()->has('view_cache')) { |
|
154 | - config()->import(new Setup('config', 'view_cache')); |
|
155 | - } |
|
156 | - |
|
157 | - $this->cacheDir = base_dir() . DS . config()->get('view_cache.cache_dir', 'cache'); |
|
158 | - } |
|
159 | - |
|
160 | - /** |
|
161 | - * @param string|null $moduleOption |
|
162 | - * @return void |
|
163 | - * @throws Exception |
|
164 | - */ |
|
165 | - private function initModule(?string $moduleOption): void |
|
166 | - { |
|
167 | - if (!empty($moduleOption)) { |
|
168 | - $this->importModules(); |
|
169 | - $module = strtolower($moduleOption); |
|
170 | - |
|
171 | - if (in_array($module, $this->modules)) { |
|
172 | - $this->module = $module; |
|
173 | - } else { |
|
174 | - throw new Exception('Module {'. $module .'} does not exist.'); |
|
175 | - } |
|
176 | - } |
|
177 | - } |
|
178 | - |
|
179 | - /** |
|
180 | - * @param string|null $typeOption |
|
181 | - * @return void |
|
182 | - * @throws Exception |
|
183 | - */ |
|
184 | - private function initType(?string $typeOption): void |
|
185 | - { |
|
186 | - if (!empty($typeOption)) { |
|
187 | - $type = strtolower($typeOption); |
|
188 | - |
|
189 | - if (in_array($type, $this->types)) { |
|
190 | - $this->type = $type; |
|
191 | - } else { |
|
192 | - throw new Exception('Cache type {'. $type .'} is invalid.'); |
|
193 | - } |
|
194 | - } |
|
195 | - } |
|
196 | - |
|
197 | - /** |
|
198 | - * @param string|null $moduleName |
|
199 | - * @param string|null $type |
|
200 | - * @return void |
|
201 | - */ |
|
202 | - private function clearResourceModuleAndType(?string $moduleName = null, ?string $type = null): void |
|
203 | - { |
|
204 | - $dir = $this->cacheDir; |
|
205 | - |
|
206 | - if ($type) { |
|
207 | - $dir = $dir . DS . strtolower($type); |
|
208 | - } |
|
209 | - |
|
210 | - if ($moduleName) { |
|
211 | - if (!$type) { |
|
212 | - $dir = $dir . DS . '*'; |
|
213 | - } |
|
214 | - |
|
215 | - $dir = $dir . DS . strtolower($moduleName); |
|
216 | - } |
|
217 | - |
|
218 | - $this->removeFilesFromDirectory($dir); |
|
219 | - } |
|
220 | - |
|
221 | - /** |
|
222 | - * @param string $dir |
|
223 | - * @return void |
|
224 | - */ |
|
225 | - private function removeFilesFromDirectory(string $dir): void |
|
226 | - { |
|
227 | - $entries = $this->fs->glob($dir . DS . '*'); |
|
228 | - |
|
229 | - foreach ($entries as $entry) { |
|
230 | - if ($this->fs->isDirectory($entry)) { |
|
231 | - $this->removeFilesFromDirectory($entry); |
|
232 | - |
|
233 | - if ($this->fs->fileName($entry) !== config()->get('view_cache.cache_dir', 'cache') && |
|
234 | - count($this->fs->glob($entry . DS . '*')) === 0 |
|
235 | - ) { |
|
236 | - $this->fs->removeDirectory($entry); |
|
237 | - } |
|
238 | - } else { |
|
239 | - $this->fs->remove($entry); |
|
240 | - } |
|
241 | - } |
|
242 | - } |
|
33 | + /** |
|
34 | + * Command name |
|
35 | + * @var string |
|
36 | + */ |
|
37 | + protected $name = 'cache:clear'; |
|
38 | + |
|
39 | + /** |
|
40 | + * Command description |
|
41 | + * @var string |
|
42 | + */ |
|
43 | + protected $description = 'Clears resource cache'; |
|
44 | + |
|
45 | + /** |
|
46 | + * Command help text |
|
47 | + * @var string |
|
48 | + */ |
|
49 | + protected $help = 'The command will clear the resource cache'; |
|
50 | + |
|
51 | + /** |
|
52 | + * Command options |
|
53 | + * @var array |
|
54 | + */ |
|
55 | + protected $options = [ |
|
56 | + ['all', 'all', 'none', ''], |
|
57 | + ['type', 't', 'required', ''], |
|
58 | + ['module', 'm', 'required', ''] |
|
59 | + ]; |
|
60 | + |
|
61 | + /** |
|
62 | + * @var array |
|
63 | + */ |
|
64 | + protected $types = ['views', 'asserts']; |
|
65 | + |
|
66 | + /** |
|
67 | + * @var array |
|
68 | + */ |
|
69 | + protected $modules; |
|
70 | + |
|
71 | + /** |
|
72 | + * @var string|null |
|
73 | + */ |
|
74 | + protected $type = null; |
|
75 | + |
|
76 | + /** |
|
77 | + * @var string|null |
|
78 | + */ |
|
79 | + protected $module = null; |
|
80 | + |
|
81 | + /** |
|
82 | + * @var string |
|
83 | + */ |
|
84 | + protected $cacheDir; |
|
85 | + |
|
86 | + /** |
|
87 | + * @var object |
|
88 | + */ |
|
89 | + protected $fs; |
|
90 | + |
|
91 | + /** |
|
92 | + * @return void |
|
93 | + * @throws DiException |
|
94 | + * @throws ReflectionException |
|
95 | + */ |
|
96 | + public function exec() |
|
97 | + { |
|
98 | + try { |
|
99 | + $this->importConfig(); |
|
100 | + $this->initModule($this->getOption('module')); |
|
101 | + $this->initType($this->getOption('type')); |
|
102 | + }catch (Exception $e){ |
|
103 | + $this->error($e->getMessage()); |
|
104 | + return; |
|
105 | + } |
|
106 | + |
|
107 | + $this->fs = Di::get(FileSystem::class); |
|
108 | + |
|
109 | + if (!$this->fs->isDirectory($this->cacheDir)) { |
|
110 | + $this->error('Cache directory does not exist or is not accessible.'); |
|
111 | + return; |
|
112 | + } |
|
113 | + |
|
114 | + if ($this->module || $this->type) { |
|
115 | + $this->clearResourceModuleAndType($this->module, $this->type); |
|
116 | + } elseif (!empty($this->getOption('all'))) { |
|
117 | + $this->removeFilesFromDirectory($this->cacheDir); |
|
118 | + } else { |
|
119 | + $this->error('Please specify at least one of the following options: --all, --module=moduleName or --type=typeName!'); |
|
120 | + return; |
|
121 | + } |
|
122 | + |
|
123 | + $this->info('Resource cache cleared successfully.'); |
|
124 | + } |
|
125 | + |
|
126 | + /** |
|
127 | + * @return void |
|
128 | + */ |
|
129 | + private function importModules() |
|
130 | + { |
|
131 | + try { |
|
132 | + if (!config()->has('modules')) { |
|
133 | + config()->import(new Setup('config', 'modules')); |
|
134 | + } |
|
135 | + |
|
136 | + if (config()->has('modules') && is_array(config()->get('modules.modules'))){ |
|
137 | + $this->modules = array_keys(array_change_key_case(config()->get('modules.modules'))); |
|
138 | + } |
|
139 | + } catch (ConfigException|DiException|ReflectionException $e) { |
|
140 | + $this->error($e->getMessage()); |
|
141 | + return; |
|
142 | + } |
|
143 | + } |
|
144 | + |
|
145 | + /** |
|
146 | + * @return void |
|
147 | + * @throws ConfigException |
|
148 | + * @throws DiException |
|
149 | + * @throws ReflectionException |
|
150 | + */ |
|
151 | + private function importConfig(): void |
|
152 | + { |
|
153 | + if (!config()->has('view_cache')) { |
|
154 | + config()->import(new Setup('config', 'view_cache')); |
|
155 | + } |
|
156 | + |
|
157 | + $this->cacheDir = base_dir() . DS . config()->get('view_cache.cache_dir', 'cache'); |
|
158 | + } |
|
159 | + |
|
160 | + /** |
|
161 | + * @param string|null $moduleOption |
|
162 | + * @return void |
|
163 | + * @throws Exception |
|
164 | + */ |
|
165 | + private function initModule(?string $moduleOption): void |
|
166 | + { |
|
167 | + if (!empty($moduleOption)) { |
|
168 | + $this->importModules(); |
|
169 | + $module = strtolower($moduleOption); |
|
170 | + |
|
171 | + if (in_array($module, $this->modules)) { |
|
172 | + $this->module = $module; |
|
173 | + } else { |
|
174 | + throw new Exception('Module {'. $module .'} does not exist.'); |
|
175 | + } |
|
176 | + } |
|
177 | + } |
|
178 | + |
|
179 | + /** |
|
180 | + * @param string|null $typeOption |
|
181 | + * @return void |
|
182 | + * @throws Exception |
|
183 | + */ |
|
184 | + private function initType(?string $typeOption): void |
|
185 | + { |
|
186 | + if (!empty($typeOption)) { |
|
187 | + $type = strtolower($typeOption); |
|
188 | + |
|
189 | + if (in_array($type, $this->types)) { |
|
190 | + $this->type = $type; |
|
191 | + } else { |
|
192 | + throw new Exception('Cache type {'. $type .'} is invalid.'); |
|
193 | + } |
|
194 | + } |
|
195 | + } |
|
196 | + |
|
197 | + /** |
|
198 | + * @param string|null $moduleName |
|
199 | + * @param string|null $type |
|
200 | + * @return void |
|
201 | + */ |
|
202 | + private function clearResourceModuleAndType(?string $moduleName = null, ?string $type = null): void |
|
203 | + { |
|
204 | + $dir = $this->cacheDir; |
|
205 | + |
|
206 | + if ($type) { |
|
207 | + $dir = $dir . DS . strtolower($type); |
|
208 | + } |
|
209 | + |
|
210 | + if ($moduleName) { |
|
211 | + if (!$type) { |
|
212 | + $dir = $dir . DS . '*'; |
|
213 | + } |
|
214 | + |
|
215 | + $dir = $dir . DS . strtolower($moduleName); |
|
216 | + } |
|
217 | + |
|
218 | + $this->removeFilesFromDirectory($dir); |
|
219 | + } |
|
220 | + |
|
221 | + /** |
|
222 | + * @param string $dir |
|
223 | + * @return void |
|
224 | + */ |
|
225 | + private function removeFilesFromDirectory(string $dir): void |
|
226 | + { |
|
227 | + $entries = $this->fs->glob($dir . DS . '*'); |
|
228 | + |
|
229 | + foreach ($entries as $entry) { |
|
230 | + if ($this->fs->isDirectory($entry)) { |
|
231 | + $this->removeFilesFromDirectory($entry); |
|
232 | + |
|
233 | + if ($this->fs->fileName($entry) !== config()->get('view_cache.cache_dir', 'cache') && |
|
234 | + count($this->fs->glob($entry . DS . '*')) === 0 |
|
235 | + ) { |
|
236 | + $this->fs->removeDirectory($entry); |
|
237 | + } |
|
238 | + } else { |
|
239 | + $this->fs->remove($entry); |
|
240 | + } |
|
241 | + } |
|
242 | + } |
|
243 | 243 | } |
@@ -99,7 +99,7 @@ discard block |
||
99 | 99 | $this->importConfig(); |
100 | 100 | $this->initModule($this->getOption('module')); |
101 | 101 | $this->initType($this->getOption('type')); |
102 | - }catch (Exception $e){ |
|
102 | + } catch (Exception $e) { |
|
103 | 103 | $this->error($e->getMessage()); |
104 | 104 | return; |
105 | 105 | } |
@@ -133,10 +133,10 @@ discard block |
||
133 | 133 | config()->import(new Setup('config', 'modules')); |
134 | 134 | } |
135 | 135 | |
136 | - if (config()->has('modules') && is_array(config()->get('modules.modules'))){ |
|
136 | + if (config()->has('modules') && is_array(config()->get('modules.modules'))) { |
|
137 | 137 | $this->modules = array_keys(array_change_key_case(config()->get('modules.modules'))); |
138 | 138 | } |
139 | - } catch (ConfigException|DiException|ReflectionException $e) { |
|
139 | + } catch (ConfigException | DiException | ReflectionException $e) { |
|
140 | 140 | $this->error($e->getMessage()); |
141 | 141 | return; |
142 | 142 | } |
@@ -171,7 +171,7 @@ discard block |
||
171 | 171 | if (in_array($module, $this->modules)) { |
172 | 172 | $this->module = $module; |
173 | 173 | } else { |
174 | - throw new Exception('Module {'. $module .'} does not exist.'); |
|
174 | + throw new Exception('Module {' . $module . '} does not exist.'); |
|
175 | 175 | } |
176 | 176 | } |
177 | 177 | } |
@@ -189,7 +189,7 @@ discard block |
||
189 | 189 | if (in_array($type, $this->types)) { |
190 | 190 | $this->type = $type; |
191 | 191 | } else { |
192 | - throw new Exception('Cache type {'. $type .'} is invalid.'); |
|
192 | + throw new Exception('Cache type {' . $type . '} is invalid.'); |
|
193 | 193 | } |
194 | 194 | } |
195 | 195 | } |
@@ -130,7 +130,7 @@ |
||
130 | 130 | */ |
131 | 131 | function route_cache_settings(): ?array |
132 | 132 | { |
133 | - return RouteController::getCurrentRoute()['cache_settings'] ?? null; |
|
133 | + return RouteController::getCurrentRoute()['cache_settings'] ?? null; |
|
134 | 134 | } |
135 | 135 | |
136 | 136 | /** |
@@ -134,7 +134,7 @@ |
||
134 | 134 | public function user(): ?User |
135 | 135 | { |
136 | 136 | try { |
137 | - $accessToken = base64_decode((string)Request::getAuthorizationBearer()); |
|
137 | + $accessToken = base64_decode((string) Request::getAuthorizationBearer()); |
|
138 | 138 | return (new User())->setData($this->jwt->retrieve($accessToken)->fetchData()); |
139 | 139 | } catch (Exception $e) { |
140 | 140 | if (Request::hasHeader($this->keyFields[self::REFRESH_TOKEN_KEY])) { |
@@ -80,7 +80,7 @@ |
||
80 | 80 | if ($authAdapter == 'api') { |
81 | 81 | $jwt = (new JWToken()) |
82 | 82 | ->setLeeway(1) |
83 | - ->setClaims((array)config()->get('auth.claims')); |
|
83 | + ->setClaims((array) config()->get('auth.claims')); |
|
84 | 84 | } |
85 | 85 | |
86 | 86 | $authAdapterClassName = __NAMESPACE__ . '\\Adapters\\' . ucfirst($authAdapter) . 'Adapter'; |
@@ -182,7 +182,7 @@ |
||
182 | 182 | return []; |
183 | 183 | } |
184 | 184 | |
185 | - return (array)require_once $userDependencies; |
|
185 | + return (array) require_once $userDependencies; |
|
186 | 186 | } |
187 | 187 | |
188 | 188 | /** |
@@ -40,7 +40,7 @@ |
||
40 | 40 | */ |
41 | 41 | public static function getHandler(): Logger |
42 | 42 | { |
43 | - if(is_debug_mode()) { |
|
43 | + if (is_debug_mode()) { |
|
44 | 44 | return LoggerFactory::createLogger(); |
45 | 45 | } |
46 | 46 |
@@ -45,7 +45,7 @@ |
||
45 | 45 | return []; |
46 | 46 | } |
47 | 47 | |
48 | - return array_reduce(array_keys($data), function ($headers, $key) use ($data) { |
|
48 | + return array_reduce(array_keys($data), function($headers, $key) use ($data) { |
|
49 | 49 | if (strpos($key, 'HTTP_') === 0) { |
50 | 50 | $formattedKey = strtolower(str_replace('_', '-', substr($key, 5))); |
51 | 51 | $headers[$formattedKey] = $data[$key]; |
@@ -98,7 +98,7 @@ |
||
98 | 98 | ]; |
99 | 99 | |
100 | 100 | if (isset($this->moduleOptions['cacheable'])) { |
101 | - $this->currentRoute['cache_settings']['shouldCache'] = (bool)$this->moduleOptions['cacheable']; |
|
101 | + $this->currentRoute['cache_settings']['shouldCache'] = (bool) $this->moduleOptions['cacheable']; |
|
102 | 102 | } |
103 | 103 | |
104 | 104 | if (is_callable($params[0])) { |
@@ -29,11 +29,11 @@ |
||
29 | 29 | */ |
30 | 30 | public function get(string $field, ?string $value): ?User; |
31 | 31 | |
32 | - /** |
|
33 | - * Add |
|
34 | - * @param array $data |
|
35 | - * @return User |
|
36 | - */ |
|
32 | + /** |
|
33 | + * Add |
|
34 | + * @param array $data |
|
35 | + * @return User |
|
36 | + */ |
|
37 | 37 | public function add(array $data): User; |
38 | 38 | |
39 | 39 | /** |