@@ -188,7 +188,7 @@ |
||
188 | 188 | } |
189 | 189 | |
190 | 190 | /** |
191 | - * @return integer|boolean |
|
191 | + * @return integer |
|
192 | 192 | */ |
193 | 193 | public static function needCache() |
194 | 194 | { |
@@ -54,7 +54,7 @@ discard block |
||
54 | 54 | { |
55 | 55 | GeneratorHelper::createDir(dirname($path)); |
56 | 56 | if (false === FileHelper::writeFile($path, $data)) { |
57 | - throw new ConfigException(_('No se tienen los permisos suficientes para escribir en el fichero ') . $path); |
|
57 | + throw new ConfigException(_('No se tienen los permisos suficientes para escribir en el fichero ').$path); |
|
58 | 58 | } |
59 | 59 | } |
60 | 60 | |
@@ -68,7 +68,7 @@ discard block |
||
68 | 68 | { |
69 | 69 | Logger::log('Gathering data from cache', LOG_DEBUG, ['path' => $path]); |
70 | 70 | $data = null; |
71 | - $absolutePath = $absolute ? $path : CACHE_DIR . DIRECTORY_SEPARATOR . $path; |
|
71 | + $absolutePath = $absolute ? $path : CACHE_DIR.DIRECTORY_SEPARATOR.$path; |
|
72 | 72 | if (file_exists($absolutePath)) { |
73 | 73 | $data = FileHelper::readFile($absolutePath); |
74 | 74 | } |
@@ -84,7 +84,7 @@ discard block |
||
84 | 84 | private function hasExpiredCache($path, $expires = 300, $absolute = false) |
85 | 85 | { |
86 | 86 | Logger::log('Checking expiration', LOG_DEBUG, ['path' => $path]); |
87 | - $absolutePath = ($absolute) ? $path : CACHE_DIR . DIRECTORY_SEPARATOR . $path; |
|
87 | + $absolutePath = ($absolute) ? $path : CACHE_DIR.DIRECTORY_SEPARATOR.$path; |
|
88 | 88 | $lasModificationDate = filemtime($absolutePath); |
89 | 89 | return ($lasModificationDate + $expires <= time()); |
90 | 90 | } |
@@ -151,7 +151,7 @@ discard block |
||
151 | 151 | { |
152 | 152 | Logger::log('Store data in cache', LOG_DEBUG, ['path' => $path]); |
153 | 153 | $data = self::transformData($data, $transform); |
154 | - $absolutePath = $absolute ? $path : CACHE_DIR . DIRECTORY_SEPARATOR . $path; |
|
154 | + $absolutePath = $absolute ? $path : CACHE_DIR.DIRECTORY_SEPARATOR.$path; |
|
155 | 155 | $this->saveTextToFile($data, $absolutePath); |
156 | 156 | } |
157 | 157 | |
@@ -168,11 +168,11 @@ discard block |
||
168 | 168 | { |
169 | 169 | $data = null; |
170 | 170 | Logger::log('Reading data from cache', LOG_DEBUG, ['path' => $path]); |
171 | - if (file_exists(CACHE_DIR . DIRECTORY_SEPARATOR . $path)) { |
|
171 | + if (file_exists(CACHE_DIR.DIRECTORY_SEPARATOR.$path)) { |
|
172 | 172 | if (is_callable($function) && $this->hasExpiredCache($path, $expires)) { |
173 | 173 | $data = $function(); |
174 | 174 | $this->storeData($path, $data, $transform, false, $expires); |
175 | - } else { |
|
175 | + }else { |
|
176 | 176 | $data = $this->getDataFromFile($path, $transform); |
177 | 177 | } |
178 | 178 | } |
@@ -224,13 +224,13 @@ discard block |
||
224 | 224 | } |
225 | 225 | |
226 | 226 | public function flushCache() { |
227 | - if(Config::getParam('cache.data.enable', false)) { |
|
227 | + if (Config::getParam('cache.data.enable', false)) { |
|
228 | 228 | Logger::log('Flushing cache', LOG_DEBUG); |
229 | 229 | $action = Security::getInstance()->getSessionKey(self::CACHE_SESSION_VAR); |
230 | - if(is_array($action)) { |
|
231 | - $hashPath = FileHelper::generateCachePath($action, $action['params']) . '..' . DIRECTORY_SEPARATOR . ' .. ' . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR; |
|
232 | - if(!file_exists($hashPath)) { |
|
233 | - $hashPath = CACHE_DIR . DIRECTORY_SEPARATOR . $hashPath; |
|
230 | + if (is_array($action)) { |
|
231 | + $hashPath = FileHelper::generateCachePath($action, $action['params']).'..'.DIRECTORY_SEPARATOR.' .. '.DIRECTORY_SEPARATOR.'..'.DIRECTORY_SEPARATOR; |
|
232 | + if (!file_exists($hashPath)) { |
|
233 | + $hashPath = CACHE_DIR.DIRECTORY_SEPARATOR.$hashPath; |
|
234 | 234 | } |
235 | 235 | FileHelper::deleteDir($hashPath); |
236 | 236 | } |
@@ -85,7 +85,7 @@ discard block |
||
85 | 85 | * @param string $msg |
86 | 86 | * @param array $context |
87 | 87 | * |
88 | - * @return bool |
|
88 | + * @return boolean|null |
|
89 | 89 | */ |
90 | 90 | public function debugLog($msg = '', array $context = []) |
91 | 91 | { |
@@ -93,7 +93,7 @@ discard block |
||
93 | 93 | } |
94 | 94 | |
95 | 95 | /** |
96 | - * @param $msg |
|
96 | + * @param string $msg |
|
97 | 97 | * @param array $context |
98 | 98 | * |
99 | 99 | * @return bool |
@@ -104,7 +104,7 @@ discard block |
||
104 | 104 | } |
105 | 105 | |
106 | 106 | /** |
107 | - * @param $msg |
|
107 | + * @param string $msg |
|
108 | 108 | * @param array $context |
109 | 109 | * @return bool |
110 | 110 | */ |
@@ -15,8 +15,8 @@ discard block |
||
15 | 15 | |
16 | 16 | |
17 | 17 | if (!defined('LOG_DIR')) { |
18 | - GeneratorHelper::createDir(BASE_DIR . DIRECTORY_SEPARATOR . 'logs'); |
|
19 | - define('LOG_DIR', BASE_DIR . DIRECTORY_SEPARATOR . 'logs'); |
|
18 | + GeneratorHelper::createDir(BASE_DIR.DIRECTORY_SEPARATOR.'logs'); |
|
19 | + define('LOG_DIR', BASE_DIR.DIRECTORY_SEPARATOR.'logs'); |
|
20 | 20 | } |
21 | 21 | |
22 | 22 | /** |
@@ -50,7 +50,7 @@ discard block |
||
50 | 50 | $config = Config::getInstance(); |
51 | 51 | $args = func_get_args(); |
52 | 52 | list($logger, $debug, $path) = $this->setup($config, $args); |
53 | - $this->stream = fopen($path . DIRECTORY_SEPARATOR . date('Ymd') . '.log', 'a+'); |
|
53 | + $this->stream = fopen($path.DIRECTORY_SEPARATOR.date('Ymd').'.log', 'a+'); |
|
54 | 54 | $this->addPushLogger($logger, $debug, $config); |
55 | 55 | $this->log_level = Config::getParam('log.level', 'info'); |
56 | 56 | } |
@@ -191,7 +191,7 @@ discard block |
||
191 | 191 | private function createLoggerPath(Config $config) |
192 | 192 | { |
193 | 193 | $logger = $this->setLoggerName($config); |
194 | - $path = LOG_DIR . DIRECTORY_SEPARATOR . $logger . DIRECTORY_SEPARATOR . date('Y') . DIRECTORY_SEPARATOR . date('m'); |
|
194 | + $path = LOG_DIR.DIRECTORY_SEPARATOR.$logger.DIRECTORY_SEPARATOR.date('Y').DIRECTORY_SEPARATOR.date('m'); |
|
195 | 195 | GeneratorHelper::createDir($path); |
196 | 196 | |
197 | 197 | return $path; |
@@ -204,7 +204,7 @@ discard block |
||
204 | 204 | */ |
205 | 205 | public static function log($msg, $type = LOG_DEBUG, array $context = []) |
206 | 206 | { |
207 | - if(Config::getParam('profiling.enable')) { |
|
207 | + if (Config::getParam('profiling.enable')) { |
|
208 | 208 | Inspector::stats($msg); |
209 | 209 | } |
210 | 210 | switch ($type) { |
@@ -179,7 +179,7 @@ discard block |
||
179 | 179 | } |
180 | 180 | |
181 | 181 | /** |
182 | - * @param $route |
|
182 | + * @param string|null $route |
|
183 | 183 | * @throws AccessDeniedException |
184 | 184 | * @throws AdminCredentialsException |
185 | 185 | * @throws RouterException |
@@ -535,7 +535,7 @@ discard block |
||
535 | 535 | /** |
536 | 536 | * @param bool $hydrateRoute |
537 | 537 | * @param $modulePath |
538 | - * @param $externalModulePath |
|
538 | + * @param string $externalModulePath |
|
539 | 539 | */ |
540 | 540 | private function loadExternalAutoloader($hydrateRoute, SplFileInfo $modulePath, $externalModulePath) |
541 | 541 | { |
@@ -550,7 +550,7 @@ discard block |
||
550 | 550 | } |
551 | 551 | |
552 | 552 | /** |
553 | - * @param $hydrateRoute |
|
553 | + * @param boolean $hydrateRoute |
|
554 | 554 | * @param $module |
555 | 555 | * @return mixed |
556 | 556 | */ |
@@ -71,11 +71,11 @@ discard block |
||
71 | 71 | */ |
72 | 72 | public function init() |
73 | 73 | { |
74 | - list($this->routing, $this->slugs) = $this->cache->getDataFromFile(CONFIG_DIR . DIRECTORY_SEPARATOR . "urls.json", $this->cacheType, TRUE); |
|
74 | + list($this->routing, $this->slugs) = $this->cache->getDataFromFile(CONFIG_DIR.DIRECTORY_SEPARATOR."urls.json", $this->cacheType, TRUE); |
|
75 | 75 | if (empty($this->routing) || Config::getInstance()->getDebugMode()) { |
76 | 76 | $this->debugLoad(); |
77 | - } else { |
|
78 | - $this->domains = $this->cache->getDataFromFile(CONFIG_DIR . DIRECTORY_SEPARATOR . "domains.json", $this->cacheType, TRUE); |
|
77 | + }else { |
|
78 | + $this->domains = $this->cache->getDataFromFile(CONFIG_DIR.DIRECTORY_SEPARATOR."domains.json", $this->cacheType, TRUE); |
|
79 | 79 | } |
80 | 80 | $this->checkExternalModules(false); |
81 | 81 | $this->setLoaded(); |
@@ -112,9 +112,9 @@ discard block |
||
112 | 112 | } |
113 | 113 | |
114 | 114 | $not_found_route = Config::getParam('route.404'); |
115 | - if(null !== $not_found_route) { |
|
115 | + if (null !== $not_found_route) { |
|
116 | 116 | Request::getInstance()->redirect($this->getRoute($not_found_route, true)); |
117 | - } else { |
|
117 | + }else { |
|
118 | 118 | return $template->render('error.html.twig', array( |
119 | 119 | 'exception' => $e, |
120 | 120 | 'trace' => $e->getTraceAsString(), |
@@ -165,12 +165,12 @@ discard block |
||
165 | 165 | try { |
166 | 166 | //Search action and execute |
167 | 167 | $this->searchAction($route); |
168 | - } catch (AccessDeniedException $e) { |
|
169 | - Logger::log(_('Solicitamos credenciales de acceso a zona restringida'), LOG_WARNING, ['file' => $e->getFile() . '[' . $e->getLine() . ']']); |
|
168 | + }catch (AccessDeniedException $e) { |
|
169 | + Logger::log(_('Solicitamos credenciales de acceso a zona restringida'), LOG_WARNING, ['file' => $e->getFile().'['.$e->getLine().']']); |
|
170 | 170 | return Admin::staticAdminLogon($route); |
171 | - } catch (RouterException $r) { |
|
171 | + }catch (RouterException $r) { |
|
172 | 172 | Logger::log($r->getMessage(), LOG_WARNING); |
173 | - } catch (\Exception $e) { |
|
173 | + }catch (\Exception $e) { |
|
174 | 174 | Logger::log($e->getMessage(), LOG_ERR); |
175 | 175 | throw $e; |
176 | 176 | } |
@@ -187,7 +187,7 @@ discard block |
||
187 | 187 | */ |
188 | 188 | protected function searchAction($route) |
189 | 189 | { |
190 | - Logger::log('Searching action to execute: ' . $route, LOG_INFO); |
|
190 | + Logger::log('Searching action to execute: '.$route, LOG_INFO); |
|
191 | 191 | //Revisamos si tenemos la ruta registrada |
192 | 192 | $parts = parse_url($route); |
193 | 193 | $path = array_key_exists('path', $parts) ? $parts['path'] : $route; |
@@ -202,12 +202,12 @@ discard block |
||
202 | 202 | /** @var $class \PSFS\base\types\Controller */ |
203 | 203 | $class = RouterHelper::getClassToCall($action); |
204 | 204 | try { |
205 | - if($this->checkRequirements($action, $get)) { |
|
205 | + if ($this->checkRequirements($action, $get)) { |
|
206 | 206 | $this->executeCachedRoute($route, $action, $class, $get); |
207 | - } else { |
|
207 | + }else { |
|
208 | 208 | throw new RouterException(_('La ruta no es válida'), 400); |
209 | 209 | } |
210 | - } catch (\Exception $e) { |
|
210 | + }catch (\Exception $e) { |
|
211 | 211 | Logger::log($e->getMessage(), LOG_ERR); |
212 | 212 | throw $e; |
213 | 213 | } |
@@ -222,15 +222,15 @@ discard block |
||
222 | 222 | * @return bool |
223 | 223 | */ |
224 | 224 | private function checkRequirements(array $action, $params = []) { |
225 | - if(!empty($params) && !empty($action['requirements'])) { |
|
225 | + if (!empty($params) && !empty($action['requirements'])) { |
|
226 | 226 | $checked = 0; |
227 | - foreach(array_keys($params) as $key) { |
|
228 | - if(in_array($key, $action['requirements'], true)) { |
|
227 | + foreach (array_keys($params) as $key) { |
|
228 | + if (in_array($key, $action['requirements'], true)) { |
|
229 | 229 | $checked++; |
230 | 230 | } |
231 | 231 | } |
232 | 232 | $valid = count($action['requirements']) === $checked; |
233 | - } else { |
|
233 | + }else { |
|
234 | 234 | $valid = true; |
235 | 235 | } |
236 | 236 | return $valid; |
@@ -280,14 +280,14 @@ discard block |
||
280 | 280 | $this->checkExternalModules(); |
281 | 281 | if (file_exists($modulesPath)) { |
282 | 282 | $modules = $this->finder->directories()->in($modulesPath)->depth(0); |
283 | - if(is_iterable($modules)) { |
|
283 | + if (is_iterable($modules)) { |
|
284 | 284 | foreach ($modules as $modulePath) { |
285 | 285 | $module = $modulePath->getBasename(); |
286 | - $this->routing = $this->inspectDir($modulesPath . DIRECTORY_SEPARATOR . $module, $module, $this->routing); |
|
286 | + $this->routing = $this->inspectDir($modulesPath.DIRECTORY_SEPARATOR.$module, $module, $this->routing); |
|
287 | 287 | } |
288 | 288 | } |
289 | 289 | } |
290 | - $this->cache->storeData(CONFIG_DIR . DIRECTORY_SEPARATOR . 'domains.json', $this->domains, Cache::JSON, TRUE); |
|
290 | + $this->cache->storeData(CONFIG_DIR.DIRECTORY_SEPARATOR.'domains.json', $this->domains, Cache::JSON, TRUE); |
|
291 | 291 | } |
292 | 292 | |
293 | 293 | /** |
@@ -303,7 +303,7 @@ discard block |
||
303 | 303 | $home_params = NULL; |
304 | 304 | foreach ($this->routing as $pattern => $params) { |
305 | 305 | list($method, $route) = RouterHelper::extractHttpRoute($pattern); |
306 | - if (preg_match('/' . preg_quote($route, '/') . '$/i', '/' . $home)) { |
|
306 | + if (preg_match('/'.preg_quote($route, '/').'$/i', '/'.$home)) { |
|
307 | 307 | $home_params = $params; |
308 | 308 | } |
309 | 309 | } |
@@ -324,10 +324,10 @@ discard block |
||
324 | 324 | private function inspectDir($origen, $namespace = 'PSFS', $routing = []) |
325 | 325 | { |
326 | 326 | $files = $this->finder->files()->in($origen)->path('/(controller|api)/i')->depth(1)->name('*.php'); |
327 | - if(is_iterable($files)) { |
|
327 | + if (is_iterable($files)) { |
|
328 | 328 | foreach ($files as $file) { |
329 | 329 | $filename = str_replace('/', '\\', str_replace($origen, '', $file->getPathname())); |
330 | - $routing = $this->addRouting($namespace . str_replace('.php', '', $filename), $routing, $namespace); |
|
330 | + $routing = $this->addRouting($namespace.str_replace('.php', '', $filename), $routing, $namespace); |
|
331 | 331 | } |
332 | 332 | } |
333 | 333 | $this->finder = new Finder(); |
@@ -356,7 +356,7 @@ discard block |
||
356 | 356 | private function addRouting($namespace, &$routing, $module = 'PSFS') |
357 | 357 | { |
358 | 358 | if (self::exists($namespace)) { |
359 | - if(I18nHelper::checkI18Class($namespace)) { |
|
359 | + if (I18nHelper::checkI18Class($namespace)) { |
|
360 | 360 | return $routing; |
361 | 361 | } |
362 | 362 | $reflection = new \ReflectionClass($namespace); |
@@ -398,7 +398,7 @@ discard block |
||
398 | 398 | if (!$this->domains) { |
399 | 399 | $this->domains = []; |
400 | 400 | } |
401 | - $domain = '@' . $class->getConstant('DOMAIN') . '/'; |
|
401 | + $domain = '@'.$class->getConstant('DOMAIN').'/'; |
|
402 | 402 | if (!array_key_exists($domain, $this->domains)) { |
403 | 403 | $this->domains[$domain] = RouterHelper::extractDomainInfo($class, $domain); |
404 | 404 | } |
@@ -414,11 +414,11 @@ discard block |
||
414 | 414 | */ |
415 | 415 | public function simpatize() |
416 | 416 | { |
417 | - $translationFileName = 'translations' . DIRECTORY_SEPARATOR . 'routes_translations.php'; |
|
418 | - $absoluteTranslationFileName = CACHE_DIR . DIRECTORY_SEPARATOR . $translationFileName; |
|
417 | + $translationFileName = 'translations'.DIRECTORY_SEPARATOR.'routes_translations.php'; |
|
418 | + $absoluteTranslationFileName = CACHE_DIR.DIRECTORY_SEPARATOR.$translationFileName; |
|
419 | 419 | $this->generateSlugs($absoluteTranslationFileName); |
420 | 420 | GeneratorHelper::createDir(CONFIG_DIR); |
421 | - Cache::getInstance()->storeData(CONFIG_DIR . DIRECTORY_SEPARATOR . 'urls.json', array($this->routing, $this->slugs), Cache::JSON, TRUE); |
|
421 | + Cache::getInstance()->storeData(CONFIG_DIR.DIRECTORY_SEPARATOR.'urls.json', array($this->routing, $this->slugs), Cache::JSON, TRUE); |
|
422 | 422 | |
423 | 423 | return $this; |
424 | 424 | } |
@@ -434,18 +434,18 @@ discard block |
||
434 | 434 | public function getRoute($slug = '', $absolute = FALSE, array $params = []) |
435 | 435 | { |
436 | 436 | if ('' === $slug) { |
437 | - return $absolute ? Request::getInstance()->getRootUrl() . '/' : '/'; |
|
437 | + return $absolute ? Request::getInstance()->getRootUrl().'/' : '/'; |
|
438 | 438 | } |
439 | 439 | if (!is_array($this->slugs) || !array_key_exists($slug, $this->slugs)) { |
440 | 440 | throw new RouterException(_('No existe la ruta especificada')); |
441 | 441 | } |
442 | - $url = $absolute ? Request::getInstance()->getRootUrl() . $this->slugs[$slug] : $this->slugs[$slug]; |
|
442 | + $url = $absolute ? Request::getInstance()->getRootUrl().$this->slugs[$slug] : $this->slugs[$slug]; |
|
443 | 443 | if (!empty($params)) { |
444 | 444 | foreach ($params as $key => $value) { |
445 | - $url = str_replace('{' . $key . '}', $value, $url); |
|
445 | + $url = str_replace('{'.$key.'}', $value, $url); |
|
446 | 446 | } |
447 | 447 | } elseif (!empty($this->routing[$this->slugs[$slug]]['default'])) { |
448 | - $url = $absolute ? Request::getInstance()->getRootUrl() . $this->routing[$this->slugs[$slug]]['default'] : $this->routing[$this->slugs[$slug]]['default']; |
|
448 | + $url = $absolute ? Request::getInstance()->getRootUrl().$this->routing[$this->slugs[$slug]]['default'] : $this->routing[$this->slugs[$slug]]['default']; |
|
449 | 449 | } |
450 | 450 | |
451 | 451 | return preg_replace('/(GET|POST|PUT|DELETE|ALL)\#\|\#/', '', $url); |
@@ -487,17 +487,17 @@ discard block |
||
487 | 487 | */ |
488 | 488 | protected function executeCachedRoute($route, $action, $class, $params = NULL) |
489 | 489 | { |
490 | - Logger::log('Executing route ' . $route, LOG_INFO); |
|
490 | + Logger::log('Executing route '.$route, LOG_INFO); |
|
491 | 491 | $action['params'] = array_merge($action['params'], $params, Request::getInstance()->getQueryParams()); |
492 | 492 | Security::getInstance()->setSessionKey(Cache::CACHE_SESSION_VAR, $action); |
493 | 493 | $cache = Cache::needCache(); |
494 | 494 | $execute = TRUE; |
495 | 495 | if (FALSE !== $cache && $action['http'] === 'GET' && Config::getParam('debug') === FALSE) { |
496 | 496 | list($path, $cacheDataName) = $this->cache->getRequestCacheHash(); |
497 | - $cachedData = $this->cache->readFromCache('json' . DIRECTORY_SEPARATOR . $path . $cacheDataName, |
|
497 | + $cachedData = $this->cache->readFromCache('json'.DIRECTORY_SEPARATOR.$path.$cacheDataName, |
|
498 | 498 | $cache); |
499 | 499 | if (NULL !== $cachedData) { |
500 | - $headers = $this->cache->readFromCache('json' . DIRECTORY_SEPARATOR . $path . $cacheDataName . '.headers', |
|
500 | + $headers = $this->cache->readFromCache('json'.DIRECTORY_SEPARATOR.$path.$cacheDataName.'.headers', |
|
501 | 501 | $cache, null, Cache::JSON); |
502 | 502 | Template::getInstance()->renderCache($cachedData, $headers); |
503 | 503 | $execute = FALSE; |
@@ -540,11 +540,11 @@ discard block |
||
540 | 540 | private function loadExternalAutoloader($hydrateRoute, SplFileInfo $modulePath, $externalModulePath) |
541 | 541 | { |
542 | 542 | $extModule = $modulePath->getBasename(); |
543 | - $moduleAutoloader = realpath($externalModulePath . DIRECTORY_SEPARATOR . $extModule . DIRECTORY_SEPARATOR . 'autoload.php'); |
|
544 | - if(file_exists($moduleAutoloader)) { |
|
543 | + $moduleAutoloader = realpath($externalModulePath.DIRECTORY_SEPARATOR.$extModule.DIRECTORY_SEPARATOR.'autoload.php'); |
|
544 | + if (file_exists($moduleAutoloader)) { |
|
545 | 545 | include_once $moduleAutoloader; |
546 | 546 | if ($hydrateRoute) { |
547 | - $this->routing = $this->inspectDir($externalModulePath . DIRECTORY_SEPARATOR . $extModule, '\\' . $extModule, $this->routing); |
|
547 | + $this->routing = $this->inspectDir($externalModulePath.DIRECTORY_SEPARATOR.$extModule, '\\'.$extModule, $this->routing); |
|
548 | 548 | } |
549 | 549 | } |
550 | 550 | } |
@@ -558,14 +558,14 @@ discard block |
||
558 | 558 | { |
559 | 559 | try { |
560 | 560 | $module = preg_replace('/(\\\|\/)/', DIRECTORY_SEPARATOR, $module); |
561 | - $externalModulePath = VENDOR_DIR . DIRECTORY_SEPARATOR . $module . DIRECTORY_SEPARATOR . 'src'; |
|
561 | + $externalModulePath = VENDOR_DIR.DIRECTORY_SEPARATOR.$module.DIRECTORY_SEPARATOR.'src'; |
|
562 | 562 | $externalModule = $this->finder->directories()->in($externalModulePath)->depth(0); |
563 | - if(is_iterable($externalModule)) { |
|
563 | + if (is_iterable($externalModule)) { |
|
564 | 564 | foreach ($externalModule as $modulePath) { |
565 | 565 | $this->loadExternalAutoloader($hydrateRoute, $modulePath, $externalModulePath); |
566 | 566 | } |
567 | 567 | } |
568 | - } catch (\Exception $e) { |
|
568 | + }catch (\Exception $e) { |
|
569 | 569 | Logger::log($e->getMessage(), LOG_WARNING); |
570 | 570 | $module = null; |
571 | 571 | } |
@@ -9,7 +9,7 @@ discard block |
||
9 | 9 | */ |
10 | 10 | class FileHelper { |
11 | 11 | /** |
12 | - * @param mixed $data |
|
12 | + * @param string $data |
|
13 | 13 | * @param string $path |
14 | 14 | * @return int |
15 | 15 | */ |
@@ -52,7 +52,7 @@ discard block |
||
52 | 52 | } |
53 | 53 | |
54 | 54 | /** |
55 | - * @param $path |
|
55 | + * @param string $path |
|
56 | 56 | * @throws IOException |
57 | 57 | */ |
58 | 58 | public static function deleteDir($path) { |
@@ -23,7 +23,7 @@ discard block |
||
23 | 23 | */ |
24 | 24 | public static function readFile($path) { |
25 | 25 | $data = false; |
26 | - if(file_exists($path)) { |
|
26 | + if (file_exists($path)) { |
|
27 | 27 | $data = @file_get_contents($path); |
28 | 28 | } |
29 | 29 | return $data; |
@@ -36,7 +36,7 @@ discard block |
||
36 | 36 | * @return string |
37 | 37 | */ |
38 | 38 | public static function generateHashFilename($verb, $slug, array $query = []) { |
39 | - return sha1(strtolower($verb) . ' ' . $slug . ' ' . strtolower(http_build_query($query))); |
|
39 | + return sha1(strtolower($verb).' '.$slug.' '.strtolower(http_build_query($query))); |
|
40 | 40 | } |
41 | 41 | |
42 | 42 | /** |
@@ -47,8 +47,8 @@ discard block |
||
47 | 47 | public static function generateCachePath(array $action, array $query = []) { |
48 | 48 | $class = GeneratorHelper::extractClassFromNamespace($action['class']); |
49 | 49 | $filename = self::generateHashFilename($action['http'], $action['slug'], $query); |
50 | - $subPath = substr($filename, 0, 2) . DIRECTORY_SEPARATOR . substr($filename, 2, 2); |
|
51 | - return $action['module'] . DIRECTORY_SEPARATOR . $class . DIRECTORY_SEPARATOR . $action['method'] . DIRECTORY_SEPARATOR . $subPath . DIRECTORY_SEPARATOR; |
|
50 | + $subPath = substr($filename, 0, 2).DIRECTORY_SEPARATOR.substr($filename, 2, 2); |
|
51 | + return $action['module'].DIRECTORY_SEPARATOR.$class.DIRECTORY_SEPARATOR.$action['method'].DIRECTORY_SEPARATOR.$subPath.DIRECTORY_SEPARATOR; |
|
52 | 52 | } |
53 | 53 | |
54 | 54 | /** |
@@ -27,10 +27,10 @@ discard block |
||
27 | 27 | $isRequired = self::checkIsRequired($property->getDocComment()); |
28 | 28 | $label = self::getLabel($property->getDocComment()); |
29 | 29 | $isArray = (bool)preg_match('/\[\]$/', $instanceType); |
30 | - if($isArray) { |
|
30 | + if ($isArray) { |
|
31 | 31 | $instanceType = str_replace('[]', '', $instanceType); |
32 | 32 | } |
33 | - if($instanceType === '\\DateTime' || !Router::exists($instanceType)) { |
|
33 | + if ($instanceType === '\\DateTime' || !Router::exists($instanceType)) { |
|
34 | 34 | list($type, $format) = DocumentorHelper::translateSwaggerFormats($instanceType); |
35 | 35 | $variables[$property->getName()] = [ |
36 | 36 | 'type' => $type, |
@@ -38,7 +38,7 @@ discard block |
||
38 | 38 | 'required' => $isRequired, |
39 | 39 | 'description' => $label, |
40 | 40 | ]; |
41 | - } else { |
|
41 | + }else { |
|
42 | 42 | $instance = new \ReflectionClass($instanceType); |
43 | 43 | $variables[$property->getName()] = [ |
44 | 44 | 'is_array' => $isArray, |
@@ -124,7 +124,7 @@ discard block |
||
124 | 124 | // Extract description |
125 | 125 | $label = null; |
126 | 126 | preg_match('/@label\ (.*)\n/i', $doc, $matches); |
127 | - if(count($matches)) { |
|
127 | + if (count($matches)) { |
|
128 | 128 | $label = _($matches[1]); |
129 | 129 | } |
130 | 130 | return $label; |
@@ -137,7 +137,7 @@ discard block |
||
137 | 137 | public static function getDefaultValue($doc) { |
138 | 138 | $default = null; |
139 | 139 | preg_match('/@default\ (.*)\n/i', $doc, $matches); |
140 | - if(count($matches)) { |
|
140 | + if (count($matches)) { |
|
141 | 141 | $default = $matches[1]; |
142 | 142 | } |
143 | 143 | return $default; |
@@ -152,13 +152,13 @@ discard block |
||
152 | 152 | */ |
153 | 153 | public static function constructInyectableInstance($variable, $singleton, $classNameSpace, $calledClass) |
154 | 154 | { |
155 | - Logger::log('Create inyectable instance for ' . $classNameSpace); |
|
155 | + Logger::log('Create inyectable instance for '.$classNameSpace); |
|
156 | 156 | $reflector = new \ReflectionClass($calledClass); |
157 | 157 | $property = $reflector->getProperty($variable); |
158 | 158 | $varInstanceType = (null === $classNameSpace) ? InjectorHelper::extractVarType($property->getDocComment()) : $classNameSpace; |
159 | 159 | if (true === $singleton && method_exists($varInstanceType, 'getInstance')) { |
160 | 160 | $instance = $varInstanceType::getInstance(); |
161 | - } else { |
|
161 | + }else { |
|
162 | 162 | $instance = new $varInstanceType(); |
163 | 163 | } |
164 | 164 | return $instance; |
@@ -172,7 +172,7 @@ discard block |
||
172 | 172 | public static function getClassProperties($class) |
173 | 173 | { |
174 | 174 | $properties = []; |
175 | - Logger::log('Extracting annotations properties from class ' . $class); |
|
175 | + Logger::log('Extracting annotations properties from class '.$class); |
|
176 | 176 | $selfReflector = new \ReflectionClass($class); |
177 | 177 | if (false !== $selfReflector->getParentClass()) { |
178 | 178 | $properties = self::getClassProperties($selfReflector->getParentClass()->getName()); |
@@ -74,7 +74,7 @@ discard block |
||
74 | 74 | */ |
75 | 75 | protected function init() |
76 | 76 | { |
77 | - if (file_exists(CONFIG_DIR . DIRECTORY_SEPARATOR . self::CONFIG_FILE)) { |
|
77 | + if (file_exists(CONFIG_DIR.DIRECTORY_SEPARATOR.self::CONFIG_FILE)) { |
|
78 | 78 | $this->loadConfigData(); |
79 | 79 | } |
80 | 80 | return $this; |
@@ -190,10 +190,10 @@ discard block |
||
190 | 190 | $final_data = array_filter($final_data, function($key, $value) { |
191 | 191 | return in_array($key, self::$required, true) || !empty($value); |
192 | 192 | }, ARRAY_FILTER_USE_BOTH); |
193 | - $saved = (false !== file_put_contents(CONFIG_DIR . DIRECTORY_SEPARATOR . self::CONFIG_FILE, json_encode($final_data, JSON_PRETTY_PRINT))); |
|
193 | + $saved = (false !== file_put_contents(CONFIG_DIR.DIRECTORY_SEPARATOR.self::CONFIG_FILE, json_encode($final_data, JSON_PRETTY_PRINT))); |
|
194 | 194 | self::getInstance()->loadConfigData(); |
195 | 195 | $saved = true; |
196 | - } catch (ConfigException $e) { |
|
196 | + }catch (ConfigException $e) { |
|
197 | 197 | Logger::log($e->getMessage(), LOG_ERR); |
198 | 198 | } |
199 | 199 | return $saved; |
@@ -225,7 +225,7 @@ discard block |
||
225 | 225 | */ |
226 | 226 | public function loadConfigData() |
227 | 227 | { |
228 | - $this->config = json_decode(file_get_contents(CONFIG_DIR . DIRECTORY_SEPARATOR . self::CONFIG_FILE), true) ?: []; |
|
228 | + $this->config = json_decode(file_get_contents(CONFIG_DIR.DIRECTORY_SEPARATOR.self::CONFIG_FILE), true) ?: []; |
|
229 | 229 | $this->debug = array_key_exists('debug', $this->config) ? (bool)$this->config['debug'] : FALSE; |
230 | 230 | } |
231 | 231 | |
@@ -246,8 +246,8 @@ discard block |
||
246 | 246 | */ |
247 | 247 | public static function getParam($key, $defaultValue = null, $module = null) |
248 | 248 | { |
249 | - if(null !== $module) { |
|
250 | - return self::getParam(strtolower($module) . '.' . $key, self::getParam($key, $defaultValue)); |
|
249 | + if (null !== $module) { |
|
250 | + return self::getParam(strtolower($module).'.'.$key, self::getParam($key, $defaultValue)); |
|
251 | 251 | } |
252 | 252 | $param = self::getInstance()->get($key); |
253 | 253 | return (null !== $param) ? $param : $defaultValue; |
@@ -22,7 +22,7 @@ discard block |
||
22 | 22 | */ |
23 | 23 | public function __construct() |
24 | 24 | { |
25 | - Logger::log(get_class($this) . ' constructor invoked'); |
|
25 | + Logger::log(get_class($this).' constructor invoked'); |
|
26 | 26 | $this->init(); |
27 | 27 | } |
28 | 28 | |
@@ -80,14 +80,14 @@ discard block |
||
80 | 80 | $calledClass = static::class; |
81 | 81 | try { |
82 | 82 | $instance = InjectorHelper::constructInyectableInstance($variable, $singleton, $classNameSpace, $calledClass); |
83 | - $setter = 'set' . ucfirst($variable); |
|
83 | + $setter = 'set'.ucfirst($variable); |
|
84 | 84 | if (method_exists($calledClass, $setter)) { |
85 | 85 | $this->$setter($instance); |
86 | - } else { |
|
86 | + }else { |
|
87 | 87 | $this->$variable = $instance; |
88 | 88 | } |
89 | - } catch (\Exception $e) { |
|
90 | - Logger::log($e->getMessage() . ': ' . $e->getFile() . ' [' . $e->getLine() . ']', LOG_ERR); |
|
89 | + }catch (\Exception $e) { |
|
90 | + Logger::log($e->getMessage().': '.$e->getFile().' ['.$e->getLine().']', LOG_ERR); |
|
91 | 91 | throw $e; |
92 | 92 | } |
93 | 93 | return $this; |
@@ -102,7 +102,7 @@ discard block |
||
102 | 102 | { |
103 | 103 | if (!$this->isLoaded()) { |
104 | 104 | $filename = sha1(get_class($this)); |
105 | - $cacheFilename = 'reflections' . DIRECTORY_SEPARATOR . substr($filename, 0, 2) . DIRECTORY_SEPARATOR . substr($filename, 2, 2) . DIRECTORY_SEPARATOR . $filename . ".json"; |
|
105 | + $cacheFilename = 'reflections'.DIRECTORY_SEPARATOR.substr($filename, 0, 2).DIRECTORY_SEPARATOR.substr($filename, 2, 2).DIRECTORY_SEPARATOR.$filename.".json"; |
|
106 | 106 | /** @var \PSFS\base\Cache $cacheService */ |
107 | 107 | $cacheService = Cache::getInstance(); |
108 | 108 | /** @var \PSFS\base\config\Config $configService */ |
@@ -120,8 +120,8 @@ discard block |
||
120 | 120 | } |
121 | 121 | } |
122 | 122 | $this->setLoaded(); |
123 | - } else { |
|
124 | - Logger::log(get_class($this) . ' already loaded', LOG_INFO); |
|
123 | + }else { |
|
124 | + Logger::log(get_class($this).' already loaded', LOG_INFO); |
|
125 | 125 | } |
126 | 126 | } |
127 | 127 | } |
@@ -73,7 +73,7 @@ discard block |
||
73 | 73 | session_start(); |
74 | 74 | } |
75 | 75 | // Fix for phpunits |
76 | - if(!isset($_SESSION)) { |
|
76 | + if (!isset($_SESSION)) { |
|
77 | 77 | $_SESSION = []; |
78 | 78 | } |
79 | 79 | } |
@@ -127,11 +127,11 @@ discard block |
||
127 | 127 | public static function save($user) |
128 | 128 | { |
129 | 129 | $saved = true; |
130 | - $admins = Cache::getInstance()->getDataFromFile(CONFIG_DIR . DIRECTORY_SEPARATOR . 'admins.json', Cache::JSONGZ, true) ?: []; |
|
131 | - $admins[$user['username']]['hash'] = sha1($user['username'] . $user['password']); |
|
130 | + $admins = Cache::getInstance()->getDataFromFile(CONFIG_DIR.DIRECTORY_SEPARATOR.'admins.json', Cache::JSONGZ, true) ?: []; |
|
131 | + $admins[$user['username']]['hash'] = sha1($user['username'].$user['password']); |
|
132 | 132 | $admins[$user['username']]['profile'] = $user['profile']; |
133 | 133 | |
134 | - Cache::getInstance()->storeData(CONFIG_DIR . DIRECTORY_SEPARATOR . 'admins.json', $admins, Cache::JSONGZ, true); |
|
134 | + Cache::getInstance()->storeData(CONFIG_DIR.DIRECTORY_SEPARATOR.'admins.json', $admins, Cache::JSONGZ, true); |
|
135 | 135 | return $saved; |
136 | 136 | } |
137 | 137 | |
@@ -174,7 +174,7 @@ discard block |
||
174 | 174 | */ |
175 | 175 | public function getAdmins() |
176 | 176 | { |
177 | - return Cache::getInstance()->getDataFromFile(CONFIG_DIR . DIRECTORY_SEPARATOR . 'admins.json', Cache::JSONGZ, true); |
|
177 | + return Cache::getInstance()->getDataFromFile(CONFIG_DIR.DIRECTORY_SEPARATOR.'admins.json', Cache::JSONGZ, true); |
|
178 | 178 | } |
179 | 179 | |
180 | 180 | /** |
@@ -199,9 +199,9 @@ discard block |
||
199 | 199 | } |
200 | 200 | if (!empty($user) && !empty($admins[$user])) { |
201 | 201 | $auth = $admins[$user]['hash']; |
202 | - $this->authorized = ($auth === sha1($user . $pass)); |
|
202 | + $this->authorized = ($auth === sha1($user.$pass)); |
|
203 | 203 | if ($this->authorized) { |
204 | - $this->updateAdmin($user , $admins[$user]['profile']); |
|
204 | + $this->updateAdmin($user, $admins[$user]['profile']); |
|
205 | 205 | ResponseHelper::setCookieHeaders([ |
206 | 206 | [ |
207 | 207 | 'name' => $this->getHash(), |
@@ -212,7 +212,7 @@ discard block |
||
212 | 212 | ]); |
213 | 213 | $this->setSessionKey(self::LOGGED_USER_TOKEN, base64_encode("{$user}:{$pass}")); |
214 | 214 | } |
215 | - } else { |
|
215 | + }else { |
|
216 | 216 | $this->admin = null; |
217 | 217 | $this->setSessionKey(self::ADMIN_ID_TOKEN, null); |
218 | 218 | } |