@@ -37,7 +37,7 @@ discard block |
||
37 | 37 | $use /= 1024; |
38 | 38 | break; |
39 | 39 | case "MBytes": |
40 | - $use /= (1024 * 1024); |
|
40 | + $use /= (1024*1024); |
|
41 | 41 | break; |
42 | 42 | case "Bytes": |
43 | 43 | default: |
@@ -61,34 +61,34 @@ discard block |
||
61 | 61 | protected function bindWarningAsExceptions() |
62 | 62 | { |
63 | 63 | Inspector::stats('[SystemTrait] Added handlers for errors'); |
64 | - if(Config::getParam('debug')) { |
|
64 | + if (Config::getParam('debug')) { |
|
65 | 65 | Logger::log('Setting error_reporting as E_ALL'); |
66 | 66 | ini_set('error_reporting', E_ALL); |
67 | 67 | ini_set('display_errors', 1); |
68 | 68 | } |
69 | 69 | //Warning & Notice handler |
70 | - set_error_handler(function ($errno, $errstr, $errfile, $errline) { |
|
70 | + set_error_handler(function($errno, $errstr, $errfile, $errline) { |
|
71 | 71 | Logger::log($errstr, LOG_CRIT, ['file' => $errfile, 'line' => $errline, 'errno' => $errno]); |
72 | 72 | return true; |
73 | 73 | }, E_ALL | E_STRICT | E_DEPRECATED | E_USER_DEPRECATED | E_ERROR | E_CORE_ERROR | E_COMPILE_ERROR); |
74 | 74 | |
75 | - register_shutdown_function(function () { |
|
75 | + register_shutdown_function(function() { |
|
76 | 76 | $error = error_get_last() or json_last_error() or preg_last_error() or \DateTime::getLastErrors(); |
77 | - if( $error !== NULL) { |
|
77 | + if ($error !== NULL) { |
|
78 | 78 | $errno = $error["type"]; |
79 | 79 | $errfile = $error["file"]; |
80 | 80 | $errline = $error["line"]; |
81 | 81 | $errstr = $error["message"]; |
82 | 82 | Logger::log($errstr, LOG_CRIT, ['file' => $errfile, 'line' => $errline, 'errno' => $errno]); |
83 | - if(null !== Config::getParam('log.slack.hook')) { |
|
83 | + if (null !== Config::getParam('log.slack.hook')) { |
|
84 | 84 | SlackHelper::getInstance()->trace($errstr, $errfile, $errline, $error); |
85 | 85 | } |
86 | 86 | } |
87 | 87 | |
88 | - if(self::getTs() > 10 && null !== Config::getParam('log.slack.hook')) { |
|
88 | + if (self::getTs() > 10 && null !== Config::getParam('log.slack.hook')) { |
|
89 | 89 | SlackHelper::getInstance()->trace('Slow service endpoint', '', '', [ |
90 | - 'time' => round(self::getTs(), 3) . ' secs', |
|
91 | - 'memory' => round(self::getMem('MBytes'), 3) . ' Mb', |
|
90 | + 'time' => round(self::getTs(), 3).' secs', |
|
91 | + 'memory' => round(self::getMem('MBytes'), 3).' Mb', |
|
92 | 92 | ]); |
93 | 93 | } |
94 | 94 | return false; |
@@ -103,7 +103,7 @@ discard block |
||
103 | 103 | Inspector::stats('[SystemTrait] Initializing stats (mem + ts)'); |
104 | 104 | if (null !== $_SERVER && array_key_exists('REQUEST_TIME_FLOAT', $_SERVER)) { |
105 | 105 | $this->ts = (float)$_SERVER['REQUEST_TIME_FLOAT']; |
106 | - } else { |
|
106 | + }else { |
|
107 | 107 | $this->ts = PSFS_START_TS; |
108 | 108 | } |
109 | 109 | $this->mem = PSFS_START_MEM; |
@@ -28,7 +28,7 @@ discard block |
||
28 | 28 | $locale = Request::header('X-API-LANG', $default); |
29 | 29 | if (empty($locale)) { |
30 | 30 | $locale = Security::getInstance()->getSessionKey(self::PSFS_SESSION_LANGUAGE_KEY); |
31 | - if(empty($locale) && array_key_exists('HTTP_ACCEPT_LANGUAGE', $_SERVER)) { |
|
31 | + if (empty($locale) && array_key_exists('HTTP_ACCEPT_LANGUAGE', $_SERVER)) { |
|
32 | 32 | $BrowserLocales = explode(",", str_replace("-", "_", $_SERVER["HTTP_ACCEPT_LANGUAGE"])); // brosers use en-US, Linux uses en_US |
33 | 33 | for ($i = 0, $ct = count($BrowserLocales); $i < $ct; $i++) { |
34 | 34 | list($BrowserLocales[$i]) = explode(";", $BrowserLocales[$i]); //trick for "en;q=0.8" |
@@ -44,8 +44,8 @@ discard block |
||
44 | 44 | // TODO check more en locales |
45 | 45 | if (strtolower($locale) === 'en') { |
46 | 46 | $locale = 'en_GB'; |
47 | - } else { |
|
48 | - $locale = $locale . '_' . strtoupper($locale); |
|
47 | + }else { |
|
48 | + $locale = $locale.'_'.strtoupper($locale); |
|
49 | 49 | } |
50 | 50 | $default_locales = explode(',', Config::getParam('i18n.locales', '')); |
51 | 51 | if (!in_array($locale, array_merge($default_locales, self::$langs))) { |
@@ -66,7 +66,7 @@ discard block |
||
66 | 66 | $translations = array(); |
67 | 67 | if (file_exists($absoluteTranslationFileName)) { |
68 | 68 | @include($absoluteTranslationFileName); |
69 | - } else { |
|
69 | + }else { |
|
70 | 70 | Cache::getInstance()->storeData($absoluteTranslationFileName, "<?php \$translations = array();\n", Cache::TEXT, TRUE); |
71 | 71 | } |
72 | 72 | |
@@ -81,13 +81,13 @@ discard block |
||
81 | 81 | public static function setLocale($default = null) |
82 | 82 | { |
83 | 83 | $locale = self::extractLocale($default); |
84 | - Inspector::stats('[i18NHelper] Set locale to project [' . $locale . ']'); |
|
84 | + Inspector::stats('[i18NHelper] Set locale to project ['.$locale.']'); |
|
85 | 85 | // Load translations |
86 | - putenv("LC_ALL=" . $locale); |
|
86 | + putenv("LC_ALL=".$locale); |
|
87 | 87 | setlocale(LC_ALL, $locale); |
88 | 88 | // Load the locale path |
89 | - $localePath = BASE_DIR . DIRECTORY_SEPARATOR . 'locale'; |
|
90 | - Logger::log('Set locale dir ' . $localePath); |
|
89 | + $localePath = BASE_DIR.DIRECTORY_SEPARATOR.'locale'; |
|
90 | + Logger::log('Set locale dir '.$localePath); |
|
91 | 91 | GeneratorHelper::createDir($localePath); |
92 | 92 | bindtextdomain('translations', $localePath); |
93 | 93 | textdomain('translations'); |
@@ -123,9 +123,9 @@ discard block |
||
123 | 123 | */ |
124 | 124 | public static function checkI18Class($namespace) { |
125 | 125 | $isI18n = false; |
126 | - if(preg_match('/I18n$/i', $namespace)) { |
|
126 | + if (preg_match('/I18n$/i', $namespace)) { |
|
127 | 127 | $parentClass = preg_replace('/I18n$/i', '', $namespace); |
128 | - if(Router::exists($parentClass)) { |
|
128 | + if (Router::exists($parentClass)) { |
|
129 | 129 | $isI18n = true; |
130 | 130 | } |
131 | 131 | } |
@@ -151,12 +151,12 @@ discard block |
||
151 | 151 | ['i', 'i', 'i', 'i', 'I', 'I', 'I', 'I'], |
152 | 152 | ['o', 'o', 'o', 'o', 'O', 'O', 'O', 'O'], |
153 | 153 | ['u', 'u', 'u', 'u', 'U', 'U', 'U', 'U'], |
154 | - ['n', 'N', 'c', 'C',], |
|
154 | + ['n', 'N', 'c', 'C', ], |
|
155 | 155 | ]; |
156 | 156 | |
157 | 157 | $text = filter_var($string, FILTER_SANITIZE_STRING, FILTER_FLAG_STRIP_LOW); |
158 | - for($i = 0, $total = count($from); $i < $total; $i++) { |
|
159 | - $text = str_replace($from[$i],$to[$i], $text); |
|
158 | + for ($i = 0, $total = count($from); $i < $total; $i++) { |
|
159 | + $text = str_replace($from[$i], $to[$i], $text); |
|
160 | 160 | } |
161 | 161 | |
162 | 162 | return $text; |
@@ -20,11 +20,11 @@ discard block |
||
20 | 20 | { |
21 | 21 | Inspector::stats('[RouterHelper] Getting class to call for executing the request action'); |
22 | 22 | Logger::log('Getting class to call for executing the request action', LOG_DEBUG, $action); |
23 | - $actionClass = class_exists($action['class']) ? $action['class'] : "\\" . $action['class']; |
|
23 | + $actionClass = class_exists($action['class']) ? $action['class'] : "\\".$action['class']; |
|
24 | 24 | $reflectionClass = new \ReflectionClass($actionClass); |
25 | - if($reflectionClass->hasMethod('getInstance')) { |
|
25 | + if ($reflectionClass->hasMethod('getInstance')) { |
|
26 | 26 | $class = $reflectionClass->getMethod('getInstance')->invoke(null, $action['method']); |
27 | - } else { |
|
27 | + }else { |
|
28 | 28 | $class = new $actionClass; |
29 | 29 | } |
30 | 30 | return $class; |
@@ -113,7 +113,7 @@ discard block |
||
113 | 113 | $expr = preg_quote($expr, '/'); |
114 | 114 | $expr = str_replace('###', '(.*)', $expr); |
115 | 115 | $expr2 = preg_replace('/\(\.\*\)$/', '', $expr); |
116 | - $matched = preg_match('/^' . $expr . '\/?$/i', $path) || preg_match('/^' . $expr2 . '?$/i', $path); |
|
116 | + $matched = preg_match('/^'.$expr.'\/?$/i', $path) || preg_match('/^'.$expr2.'?$/i', $path); |
|
117 | 117 | return $matched; |
118 | 118 | } |
119 | 119 | |
@@ -124,8 +124,8 @@ discard block |
||
124 | 124 | */ |
125 | 125 | public static function extractDomainInfo(\ReflectionClass $class, $domain) |
126 | 126 | { |
127 | - $path = dirname($class->getFileName()) . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR; |
|
128 | - $path = realpath($path) . DIRECTORY_SEPARATOR; |
|
127 | + $path = dirname($class->getFileName()).DIRECTORY_SEPARATOR.'..'.DIRECTORY_SEPARATOR; |
|
128 | + $path = realpath($path).DIRECTORY_SEPARATOR; |
|
129 | 129 | $templatesPath = 'templates'; |
130 | 130 | $publicPath = 'public'; |
131 | 131 | $modelsPath = 'models'; |
@@ -135,13 +135,13 @@ discard block |
||
135 | 135 | $modelsPath = ucfirst($modelsPath); |
136 | 136 | } |
137 | 137 | if ($class->hasConstant('TPL')) { |
138 | - $templatesPath .= DIRECTORY_SEPARATOR . $class->getConstant('TPL'); |
|
138 | + $templatesPath .= DIRECTORY_SEPARATOR.$class->getConstant('TPL'); |
|
139 | 139 | } |
140 | 140 | return [ |
141 | 141 | 'base' => $path, |
142 | - 'template' => $path . $templatesPath, |
|
143 | - 'model' => $path . $modelsPath, |
|
144 | - 'public' => $path . $publicPath, |
|
142 | + 'template' => $path.$templatesPath, |
|
143 | + 'model' => $path.$modelsPath, |
|
144 | + 'public' => $path.$publicPath, |
|
145 | 145 | ]; |
146 | 146 | } |
147 | 147 | |
@@ -165,12 +165,12 @@ discard block |
||
165 | 165 | foreach ($parameters as $param) { |
166 | 166 | if ($param->isOptional() && !is_array($param->getDefaultValue())) { |
167 | 167 | $params[$param->getName()] = $param->getDefaultValue(); |
168 | - $default = str_replace('{' . $param->getName() . '}', $param->getDefaultValue(), $regex); |
|
169 | - } elseif(!$param->isOptional()) { |
|
168 | + $default = str_replace('{'.$param->getName().'}', $param->getDefaultValue(), $regex); |
|
169 | + } elseif (!$param->isOptional()) { |
|
170 | 170 | $requirements[] = $param->getName(); |
171 | 171 | } |
172 | 172 | } |
173 | - } else { |
|
173 | + }else { |
|
174 | 174 | $default = $regex; |
175 | 175 | } |
176 | 176 | |
@@ -266,7 +266,7 @@ discard block |
||
266 | 266 | $httpMethod = self::extractReflectionHttpMethod($docComments); |
267 | 267 | $icon = self::extractDocIcon($docComments); |
268 | 268 | $label = self::extractReflectionLabel(str_replace('{__API__}', $api, $docComments)); |
269 | - $route = $httpMethod . "#|#" . $regex; |
|
269 | + $route = $httpMethod."#|#".$regex; |
|
270 | 270 | $route = preg_replace('/(\\r|\\f|\\t|\\n)/', '', $route); |
271 | 271 | $info = [ |
272 | 272 | 'method' => $method->getName(), |
@@ -83,7 +83,7 @@ discard block |
||
83 | 83 | */ |
84 | 84 | protected function init() |
85 | 85 | { |
86 | - if (file_exists(CONFIG_DIR . DIRECTORY_SEPARATOR . self::CONFIG_FILE)) { |
|
86 | + if (file_exists(CONFIG_DIR.DIRECTORY_SEPARATOR.self::CONFIG_FILE)) { |
|
87 | 87 | $this->loadConfigData(); |
88 | 88 | } |
89 | 89 | return $this; |
@@ -199,10 +199,10 @@ discard block |
||
199 | 199 | $finalData = array_filter($finalData, function($key, $value) { |
200 | 200 | return in_array($key, self::$required, true) || !empty($value); |
201 | 201 | }, ARRAY_FILTER_USE_BOTH); |
202 | - $saved = (false !== file_put_contents(CONFIG_DIR . DIRECTORY_SEPARATOR . self::CONFIG_FILE, json_encode($finalData, JSON_PRETTY_PRINT))); |
|
202 | + $saved = (false !== file_put_contents(CONFIG_DIR.DIRECTORY_SEPARATOR.self::CONFIG_FILE, json_encode($finalData, JSON_PRETTY_PRINT))); |
|
203 | 203 | self::getInstance()->loadConfigData(); |
204 | 204 | $saved = true; |
205 | - } catch (ConfigException $e) { |
|
205 | + }catch (ConfigException $e) { |
|
206 | 206 | Logger::log($e->getMessage(), LOG_ERR); |
207 | 207 | } |
208 | 208 | return $saved; |
@@ -234,7 +234,7 @@ discard block |
||
234 | 234 | */ |
235 | 235 | public function loadConfigData() |
236 | 236 | { |
237 | - $this->config = json_decode(file_get_contents(CONFIG_DIR . DIRECTORY_SEPARATOR . self::CONFIG_FILE), true) ?: []; |
|
237 | + $this->config = json_decode(file_get_contents(CONFIG_DIR.DIRECTORY_SEPARATOR.self::CONFIG_FILE), true) ?: []; |
|
238 | 238 | $this->debug = array_key_exists('debug', $this->config) ? (bool)$this->config['debug'] : FALSE; |
239 | 239 | } |
240 | 240 | |
@@ -255,8 +255,8 @@ discard block |
||
255 | 255 | */ |
256 | 256 | public static function getParam($key, $defaultValue = null, $module = null) |
257 | 257 | { |
258 | - if(null !== $module) { |
|
259 | - return self::getParam(strtolower($module) . '.' . $key, self::getParam($key, $defaultValue)); |
|
258 | + if (null !== $module) { |
|
259 | + return self::getParam(strtolower($module).'.'.$key, self::getParam($key, $defaultValue)); |
|
260 | 260 | } |
261 | 261 | $param = self::getInstance()->get($key); |
262 | 262 | return (null !== $param) ? $param : $defaultValue; |
@@ -75,11 +75,11 @@ discard block |
||
75 | 75 | */ |
76 | 76 | public function init() |
77 | 77 | { |
78 | - list($this->routing, $this->slugs) = $this->cache->getDataFromFile(CONFIG_DIR . DIRECTORY_SEPARATOR . 'urls.json', $this->cacheType, TRUE); |
|
78 | + list($this->routing, $this->slugs) = $this->cache->getDataFromFile(CONFIG_DIR.DIRECTORY_SEPARATOR.'urls.json', $this->cacheType, TRUE); |
|
79 | 79 | if (empty($this->routing) || Config::getParam('debug', true)) { |
80 | 80 | $this->debugLoad(); |
81 | - } else { |
|
82 | - $this->domains = $this->cache->getDataFromFile(CONFIG_DIR . DIRECTORY_SEPARATOR . 'domains.json', $this->cacheType, TRUE); |
|
81 | + }else { |
|
82 | + $this->domains = $this->cache->getDataFromFile(CONFIG_DIR.DIRECTORY_SEPARATOR.'domains.json', $this->cacheType, TRUE); |
|
83 | 83 | } |
84 | 84 | $this->checkExternalModules(false); |
85 | 85 | $this->setLoaded(); |
@@ -117,9 +117,9 @@ discard block |
||
117 | 117 | } |
118 | 118 | |
119 | 119 | $notFoundRoute = Config::getParam('route.404'); |
120 | - if(null !== $notFoundRoute) { |
|
120 | + if (null !== $notFoundRoute) { |
|
121 | 121 | Request::getInstance()->redirect($this->getRoute($notFoundRoute, true)); |
122 | - } else { |
|
122 | + }else { |
|
123 | 123 | return $template->render('error.html.twig', array( |
124 | 124 | 'exception' => $exception, |
125 | 125 | 'trace' => $exception->getTraceAsString(), |
@@ -170,12 +170,12 @@ discard block |
||
170 | 170 | try { |
171 | 171 | //Search action and execute |
172 | 172 | return $this->searchAction($route); |
173 | - } catch (AccessDeniedException $e) { |
|
174 | - Logger::log(t('Solicitamos credenciales de acceso a zona restringida'), LOG_WARNING, ['file' => $e->getFile() . '[' . $e->getLine() . ']']); |
|
173 | + }catch (AccessDeniedException $e) { |
|
174 | + Logger::log(t('Solicitamos credenciales de acceso a zona restringida'), LOG_WARNING, ['file' => $e->getFile().'['.$e->getLine().']']); |
|
175 | 175 | return Admin::staticAdminLogon($route); |
176 | - } catch (RouterException $r) { |
|
176 | + }catch (RouterException $r) { |
|
177 | 177 | Logger::log($r->getMessage(), LOG_WARNING); |
178 | - } catch (\Exception $e) { |
|
178 | + }catch (\Exception $e) { |
|
179 | 179 | Logger::log($e->getMessage(), LOG_ERR); |
180 | 180 | throw $e; |
181 | 181 | } |
@@ -193,7 +193,7 @@ discard block |
||
193 | 193 | */ |
194 | 194 | protected function searchAction($route) |
195 | 195 | { |
196 | - Inspector::stats('[Router] Searching action to execute: ' . $route); |
|
196 | + Inspector::stats('[Router] Searching action to execute: '.$route); |
|
197 | 197 | //Revisamos si tenemos la ruta registrada |
198 | 198 | $parts = parse_url($route); |
199 | 199 | $path = array_key_exists('path', $parts) ? $parts['path'] : $route; |
@@ -208,12 +208,12 @@ discard block |
||
208 | 208 | /** @var $class \PSFS\base\types\Controller */ |
209 | 209 | $class = RouterHelper::getClassToCall($action); |
210 | 210 | try { |
211 | - if($this->checkRequirements($action, $get)) { |
|
211 | + if ($this->checkRequirements($action, $get)) { |
|
212 | 212 | return $this->executeCachedRoute($route, $action, $class, $get); |
213 | - } else { |
|
213 | + }else { |
|
214 | 214 | throw new RouterException(t('La ruta no es válida'), 400); |
215 | 215 | } |
216 | - } catch (\Exception $e) { |
|
216 | + }catch (\Exception $e) { |
|
217 | 217 | Logger::log($e->getMessage(), LOG_ERR); |
218 | 218 | throw $e; |
219 | 219 | } |
@@ -229,15 +229,15 @@ discard block |
||
229 | 229 | */ |
230 | 230 | private function checkRequirements(array $action, $params = []) { |
231 | 231 | Inspector::stats('[Router] Checking request requirements'); |
232 | - if(!empty($params) && !empty($action['requirements'])) { |
|
232 | + if (!empty($params) && !empty($action['requirements'])) { |
|
233 | 233 | $checked = 0; |
234 | - foreach(array_keys($params) as $key) { |
|
235 | - if(in_array($key, $action['requirements'], true)) { |
|
234 | + foreach (array_keys($params) as $key) { |
|
235 | + if (in_array($key, $action['requirements'], true)) { |
|
236 | 236 | $checked++; |
237 | 237 | } |
238 | 238 | } |
239 | 239 | $valid = count($action['requirements']) === $checked; |
240 | - } else { |
|
240 | + }else { |
|
241 | 241 | $valid = true; |
242 | 242 | } |
243 | 243 | return $valid; |
@@ -287,14 +287,14 @@ discard block |
||
287 | 287 | $this->checkExternalModules(); |
288 | 288 | if (file_exists($modulesPath)) { |
289 | 289 | $modules = $this->finder->directories()->in($modulesPath)->depth(0); |
290 | - if($modules->hasResults()) { |
|
290 | + if ($modules->hasResults()) { |
|
291 | 291 | foreach ($modules->getIterator() as $modulePath) { |
292 | 292 | $module = $modulePath->getBasename(); |
293 | - $this->routing = $this->inspectDir($modulesPath . DIRECTORY_SEPARATOR . $module, $module, $this->routing); |
|
293 | + $this->routing = $this->inspectDir($modulesPath.DIRECTORY_SEPARATOR.$module, $module, $this->routing); |
|
294 | 294 | } |
295 | 295 | } |
296 | 296 | } |
297 | - $this->cache->storeData(CONFIG_DIR . DIRECTORY_SEPARATOR . 'domains.json', $this->domains, Cache::JSON, TRUE); |
|
297 | + $this->cache->storeData(CONFIG_DIR.DIRECTORY_SEPARATOR.'domains.json', $this->domains, Cache::JSON, TRUE); |
|
298 | 298 | } |
299 | 299 | |
300 | 300 | /** |
@@ -310,7 +310,7 @@ discard block |
||
310 | 310 | $home_params = NULL; |
311 | 311 | foreach ($this->routing as $pattern => $params) { |
312 | 312 | list($method, $route) = RouterHelper::extractHttpRoute($pattern); |
313 | - if (preg_match('/' . preg_quote($route, '/') . '$/i', '/' . $home)) { |
|
313 | + if (preg_match('/'.preg_quote($route, '/').'$/i', '/'.$home)) { |
|
314 | 314 | $home_params = $params; |
315 | 315 | } |
316 | 316 | unset($method); |
@@ -332,14 +332,14 @@ discard block |
||
332 | 332 | private function inspectDir($origen, $namespace = 'PSFS', $routing = []) |
333 | 333 | { |
334 | 334 | $files = $this->finder->files()->in($origen)->path('/(controller|api)/i')->depth(1)->name('*.php'); |
335 | - if($files->hasResults()) { |
|
335 | + if ($files->hasResults()) { |
|
336 | 336 | foreach ($files->getIterator() as $file) { |
337 | - if($namespace !== 'PSFS' && method_exists($file, 'getRelativePathname')) { |
|
338 | - $filename = '\\' . str_replace('/', '\\', str_replace($origen, '', $file->getRelativePathname())); |
|
339 | - } else { |
|
337 | + if ($namespace !== 'PSFS' && method_exists($file, 'getRelativePathname')) { |
|
338 | + $filename = '\\'.str_replace('/', '\\', str_replace($origen, '', $file->getRelativePathname())); |
|
339 | + }else { |
|
340 | 340 | $filename = str_replace('/', '\\', str_replace($origen, '', $file->getPathname())); |
341 | 341 | } |
342 | - $routing = $this->addRouting($namespace . str_replace('.php', '', $filename), $routing, $namespace); |
|
342 | + $routing = $this->addRouting($namespace.str_replace('.php', '', $filename), $routing, $namespace); |
|
343 | 343 | } |
344 | 344 | } |
345 | 345 | $this->finder = new Finder(); |
@@ -368,7 +368,7 @@ discard block |
||
368 | 368 | private function addRouting($namespace, &$routing, $module = 'PSFS') |
369 | 369 | { |
370 | 370 | if (self::exists($namespace)) { |
371 | - if(I18nHelper::checkI18Class($namespace)) { |
|
371 | + if (I18nHelper::checkI18Class($namespace)) { |
|
372 | 372 | return $routing; |
373 | 373 | } |
374 | 374 | $reflection = new \ReflectionClass($namespace); |
@@ -410,7 +410,7 @@ discard block |
||
410 | 410 | if (!$this->domains) { |
411 | 411 | $this->domains = []; |
412 | 412 | } |
413 | - $domain = '@' . $class->getConstant('DOMAIN') . '/'; |
|
413 | + $domain = '@'.$class->getConstant('DOMAIN').'/'; |
|
414 | 414 | if (!array_key_exists($domain, $this->domains)) { |
415 | 415 | $this->domains[$domain] = RouterHelper::extractDomainInfo($class, $domain); |
416 | 416 | } |
@@ -426,11 +426,11 @@ discard block |
||
426 | 426 | */ |
427 | 427 | public function simpatize() |
428 | 428 | { |
429 | - $translationFileName = 'translations' . DIRECTORY_SEPARATOR . 'routes_translations.php'; |
|
430 | - $absoluteTranslationFileName = CACHE_DIR . DIRECTORY_SEPARATOR . $translationFileName; |
|
429 | + $translationFileName = 'translations'.DIRECTORY_SEPARATOR.'routes_translations.php'; |
|
430 | + $absoluteTranslationFileName = CACHE_DIR.DIRECTORY_SEPARATOR.$translationFileName; |
|
431 | 431 | $this->generateSlugs($absoluteTranslationFileName); |
432 | 432 | GeneratorHelper::createDir(CONFIG_DIR); |
433 | - Cache::getInstance()->storeData(CONFIG_DIR . DIRECTORY_SEPARATOR . 'urls.json', array($this->routing, $this->slugs), Cache::JSON, TRUE); |
|
433 | + Cache::getInstance()->storeData(CONFIG_DIR.DIRECTORY_SEPARATOR.'urls.json', array($this->routing, $this->slugs), Cache::JSON, TRUE); |
|
434 | 434 | |
435 | 435 | return $this; |
436 | 436 | } |
@@ -446,18 +446,18 @@ discard block |
||
446 | 446 | public function getRoute($slug = '', $absolute = FALSE, array $params = []) |
447 | 447 | { |
448 | 448 | if ('' === $slug) { |
449 | - return $absolute ? Request::getInstance()->getRootUrl() . '/' : '/'; |
|
449 | + return $absolute ? Request::getInstance()->getRootUrl().'/' : '/'; |
|
450 | 450 | } |
451 | 451 | if (!is_array($this->slugs) || !array_key_exists($slug, $this->slugs)) { |
452 | 452 | throw new RouterException(t('No existe la ruta especificada')); |
453 | 453 | } |
454 | - $url = $absolute ? Request::getInstance()->getRootUrl() . $this->slugs[$slug] : $this->slugs[$slug]; |
|
454 | + $url = $absolute ? Request::getInstance()->getRootUrl().$this->slugs[$slug] : $this->slugs[$slug]; |
|
455 | 455 | if (!empty($params)) { |
456 | 456 | foreach ($params as $key => $value) { |
457 | - $url = str_replace('{' . $key . '}', $value, $url); |
|
457 | + $url = str_replace('{'.$key.'}', $value, $url); |
|
458 | 458 | } |
459 | 459 | } elseif (!empty($this->routing[$this->slugs[$slug]]['default'])) { |
460 | - $url = $absolute ? Request::getInstance()->getRootUrl() . $this->routing[$this->slugs[$slug]]['default'] : $this->routing[$this->slugs[$slug]]['default']; |
|
460 | + $url = $absolute ? Request::getInstance()->getRootUrl().$this->routing[$this->slugs[$slug]]['default'] : $this->routing[$this->slugs[$slug]]['default']; |
|
461 | 461 | } |
462 | 462 | |
463 | 463 | return preg_replace('/(GET|POST|PUT|DELETE|ALL)\#\|\#/', '', $url); |
@@ -476,15 +476,15 @@ discard block |
||
476 | 476 | * @param string $method |
477 | 477 | */ |
478 | 478 | private function checkPreActions($class, $method) { |
479 | - $preAction = 'pre' . ucfirst($method); |
|
480 | - if(method_exists($class, $preAction)) { |
|
479 | + $preAction = 'pre'.ucfirst($method); |
|
480 | + if (method_exists($class, $preAction)) { |
|
481 | 481 | Inspector::stats('[Router] Pre action invoked '); |
482 | 482 | try { |
483 | - if(false === call_user_func_array([$class, $preAction])) { |
|
483 | + if (false === call_user_func_array([$class, $preAction])) { |
|
484 | 484 | Logger::log(t('Pre action failed'), LOG_ERR, [error_get_last()]); |
485 | 485 | error_clear_last(); |
486 | 486 | } |
487 | - } catch (\Exception $e) { |
|
487 | + }catch (\Exception $e) { |
|
488 | 488 | Logger::log($e->getMessage(), LOG_ERR, [$class, $method]); |
489 | 489 | } |
490 | 490 | } |
@@ -501,7 +501,7 @@ discard block |
||
501 | 501 | */ |
502 | 502 | protected function executeCachedRoute($route, $action, $class, $params = NULL) |
503 | 503 | { |
504 | - Inspector::stats('[Router] Executing route ' . $route); |
|
504 | + Inspector::stats('[Router] Executing route '.$route); |
|
505 | 505 | $action['params'] = array_merge($action['params'], $params, Request::getInstance()->getQueryParams()); |
506 | 506 | Security::getInstance()->setSessionKey(Cache::CACHE_SESSION_VAR, $action); |
507 | 507 | $cache = Cache::needCache(); |
@@ -509,15 +509,15 @@ discard block |
||
509 | 509 | $return = null; |
510 | 510 | if (FALSE !== $cache && $action['http'] === 'GET' && Config::getParam('debug') === FALSE) { |
511 | 511 | list($path, $cacheDataName) = $this->cache->getRequestCacheHash(); |
512 | - $cachedData = $this->cache->readFromCache('json' . DIRECTORY_SEPARATOR . $path . $cacheDataName, $cache); |
|
512 | + $cachedData = $this->cache->readFromCache('json'.DIRECTORY_SEPARATOR.$path.$cacheDataName, $cache); |
|
513 | 513 | if (NULL !== $cachedData) { |
514 | - $headers = $this->cache->readFromCache('json' . DIRECTORY_SEPARATOR . $path . $cacheDataName . '.headers', $cache, null, Cache::JSON); |
|
514 | + $headers = $this->cache->readFromCache('json'.DIRECTORY_SEPARATOR.$path.$cacheDataName.'.headers', $cache, null, Cache::JSON); |
|
515 | 515 | Template::getInstance()->renderCache($cachedData, $headers); |
516 | 516 | $execute = FALSE; |
517 | 517 | } |
518 | 518 | } |
519 | 519 | if ($execute) { |
520 | - Inspector::stats('[Router] Start executing action ' . $route); |
|
520 | + Inspector::stats('[Router] Start executing action '.$route); |
|
521 | 521 | $this->checkPreActions($class, $action['method']); |
522 | 522 | $return = call_user_func_array([$class, $action['method']], $params); |
523 | 523 | if (false === $return) { |
@@ -556,11 +556,11 @@ discard block |
||
556 | 556 | private function loadExternalAutoloader($hydrateRoute, SplFileInfo $modulePath, $externalModulePath) |
557 | 557 | { |
558 | 558 | $extModule = $modulePath->getBasename(); |
559 | - $moduleAutoloader = realpath($externalModulePath . DIRECTORY_SEPARATOR . $extModule . DIRECTORY_SEPARATOR . 'autoload.php'); |
|
560 | - if(file_exists($moduleAutoloader)) { |
|
559 | + $moduleAutoloader = realpath($externalModulePath.DIRECTORY_SEPARATOR.$extModule.DIRECTORY_SEPARATOR.'autoload.php'); |
|
560 | + if (file_exists($moduleAutoloader)) { |
|
561 | 561 | include_once $moduleAutoloader; |
562 | 562 | if ($hydrateRoute) { |
563 | - $this->routing = $this->inspectDir($externalModulePath . DIRECTORY_SEPARATOR . $extModule, '\\' . $extModule, $this->routing); |
|
563 | + $this->routing = $this->inspectDir($externalModulePath.DIRECTORY_SEPARATOR.$extModule, '\\'.$extModule, $this->routing); |
|
564 | 564 | } |
565 | 565 | } |
566 | 566 | } |
@@ -574,16 +574,16 @@ discard block |
||
574 | 574 | { |
575 | 575 | try { |
576 | 576 | $module = preg_replace('/(\\\|\/)/', DIRECTORY_SEPARATOR, $module); |
577 | - $externalModulePath = VENDOR_DIR . DIRECTORY_SEPARATOR . $module . DIRECTORY_SEPARATOR . 'src'; |
|
578 | - if(file_exists($externalModulePath)) { |
|
577 | + $externalModulePath = VENDOR_DIR.DIRECTORY_SEPARATOR.$module.DIRECTORY_SEPARATOR.'src'; |
|
578 | + if (file_exists($externalModulePath)) { |
|
579 | 579 | $externalModule = $this->finder->directories()->in($externalModulePath)->depth(0); |
580 | - if($externalModule->hasResults()) { |
|
580 | + if ($externalModule->hasResults()) { |
|
581 | 581 | foreach ($externalModule->getIterator() as $modulePath) { |
582 | 582 | $this->loadExternalAutoloader($hydrateRoute, $modulePath, $externalModulePath); |
583 | 583 | } |
584 | 584 | } |
585 | 585 | } |
586 | - } catch (\Exception $e) { |
|
586 | + }catch (\Exception $e) { |
|
587 | 587 | Logger::log($e->getMessage(), LOG_WARNING); |
588 | 588 | $module = null; |
589 | 589 | } |
@@ -55,7 +55,7 @@ discard block |
||
55 | 55 | { |
56 | 56 | GeneratorHelper::createDir(dirname($path)); |
57 | 57 | if (false === FileHelper::writeFile($path, $data)) { |
58 | - throw new ConfigException(t('No se tienen los permisos suficientes para escribir en el fichero ') . $path); |
|
58 | + throw new ConfigException(t('No se tienen los permisos suficientes para escribir en el fichero ').$path); |
|
59 | 59 | } |
60 | 60 | } |
61 | 61 | |
@@ -69,7 +69,7 @@ discard block |
||
69 | 69 | { |
70 | 70 | Inspector::stats('[Cache] Gathering data from cache'); |
71 | 71 | $data = null; |
72 | - $absolutePath = $absolute ? $path : CACHE_DIR . DIRECTORY_SEPARATOR . $path; |
|
72 | + $absolutePath = $absolute ? $path : CACHE_DIR.DIRECTORY_SEPARATOR.$path; |
|
73 | 73 | if (file_exists($absolutePath)) { |
74 | 74 | $data = FileHelper::readFile($absolutePath); |
75 | 75 | } |
@@ -85,7 +85,7 @@ discard block |
||
85 | 85 | private function hasExpiredCache($path, $expires = 300, $absolute = false) |
86 | 86 | { |
87 | 87 | Inspector::stats('[Cache] Checking expiration'); |
88 | - $absolutePath = ($absolute) ? $path : CACHE_DIR . DIRECTORY_SEPARATOR . $path; |
|
88 | + $absolutePath = ($absolute) ? $path : CACHE_DIR.DIRECTORY_SEPARATOR.$path; |
|
89 | 89 | $lasModificationDate = filemtime($absolutePath); |
90 | 90 | return ($lasModificationDate + $expires <= time()); |
91 | 91 | } |
@@ -152,7 +152,7 @@ discard block |
||
152 | 152 | { |
153 | 153 | Inspector::stats('[Cache] Store data in cache'); |
154 | 154 | $data = self::transformData($data, $transform); |
155 | - $absolutePath = $absolute ? $path : CACHE_DIR . DIRECTORY_SEPARATOR . $path; |
|
155 | + $absolutePath = $absolute ? $path : CACHE_DIR.DIRECTORY_SEPARATOR.$path; |
|
156 | 156 | $this->saveTextToFile($data, $absolutePath); |
157 | 157 | } |
158 | 158 | |
@@ -168,12 +168,12 @@ discard block |
||
168 | 168 | public function readFromCache($path, $expires = 300, $function = null, $transform = Cache::TEXT) |
169 | 169 | { |
170 | 170 | $data = null; |
171 | - Inspector::stats('[Cache] Reading data from cache: ' . json_encode(['path' => $path])); |
|
172 | - if (file_exists(CACHE_DIR . DIRECTORY_SEPARATOR . $path)) { |
|
171 | + Inspector::stats('[Cache] Reading data from cache: '.json_encode(['path' => $path])); |
|
172 | + if (file_exists(CACHE_DIR.DIRECTORY_SEPARATOR.$path)) { |
|
173 | 173 | if (is_callable($function) && $this->hasExpiredCache($path, $expires)) { |
174 | 174 | $data = $function(); |
175 | 175 | $this->storeData($path, $data, $transform, false, $expires); |
176 | - } else { |
|
176 | + }else { |
|
177 | 177 | $data = $this->getDataFromFile($path, $transform); |
178 | 178 | } |
179 | 179 | } |
@@ -219,20 +219,20 @@ discard block |
||
219 | 219 | $query[Api::HEADER_API_LANG] = Request::header(Api::HEADER_API_LANG, 'es'); |
220 | 220 | $filename = FileHelper::generateHashFilename($action['http'], $action['slug'], $query); |
221 | 221 | $hashPath = FileHelper::generateCachePath($action, $query); |
222 | - Inspector::stats('[Cache] Cache file calculated: ' . json_encode(['file' => $filename, 'hash' => $hashPath])); |
|
222 | + Inspector::stats('[Cache] Cache file calculated: '.json_encode(['file' => $filename, 'hash' => $hashPath])); |
|
223 | 223 | Logger::log('Cache file calculated', LOG_DEBUG, ['file' => $filename, 'hash' => $hashPath]); |
224 | 224 | } |
225 | 225 | return [$hashPath, $filename]; |
226 | 226 | } |
227 | 227 | |
228 | 228 | public function flushCache() { |
229 | - if(Config::getParam('cache.data.enable', false)) { |
|
229 | + if (Config::getParam('cache.data.enable', false)) { |
|
230 | 230 | Inspector::stats('[Cache] Flushing cache'); |
231 | 231 | $action = Security::getInstance()->getSessionKey(self::CACHE_SESSION_VAR); |
232 | - if(is_array($action)) { |
|
233 | - $hashPath = FileHelper::generateCachePath($action, $action['params']) . '..' . DIRECTORY_SEPARATOR . ' .. ' . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR; |
|
234 | - if(!file_exists($hashPath)) { |
|
235 | - $hashPath = CACHE_DIR . DIRECTORY_SEPARATOR . $hashPath; |
|
232 | + if (is_array($action)) { |
|
233 | + $hashPath = FileHelper::generateCachePath($action, $action['params']).'..'.DIRECTORY_SEPARATOR.' .. '.DIRECTORY_SEPARATOR.'..'.DIRECTORY_SEPARATOR; |
|
234 | + if (!file_exists($hashPath)) { |
|
235 | + $hashPath = CACHE_DIR.DIRECTORY_SEPARATOR.$hashPath; |
|
236 | 236 | } |
237 | 237 | FileHelper::deleteDir($hashPath); |
238 | 238 | } |
@@ -62,7 +62,7 @@ discard block |
||
62 | 62 | { |
63 | 63 | if (preg_match('/^asc$/i', $direction)) { |
64 | 64 | return self::ASC; |
65 | - } else { |
|
65 | + }else { |
|
66 | 66 | return self::DESC; |
67 | 67 | } |
68 | 68 | } |
@@ -81,7 +81,7 @@ discard block |
||
81 | 81 | */ |
82 | 82 | public function fromArray(array $object = array()) |
83 | 83 | { |
84 | - foreach($object as $field => $order) { |
|
84 | + foreach ($object as $field => $order) { |
|
85 | 85 | $this->addOrder($field, $order); |
86 | 86 | } |
87 | 87 | } |
@@ -19,7 +19,7 @@ discard block |
||
19 | 19 | public function __construct($hydrate = true) |
20 | 20 | { |
21 | 21 | parent::__construct(); |
22 | - if($hydrate) { |
|
22 | + if ($hydrate) { |
|
23 | 23 | $this->fromArray(Request::getInstance()->getData()); |
24 | 24 | } |
25 | 25 | } |
@@ -47,22 +47,22 @@ discard block |
||
47 | 47 | /** @var \ReflectionProperty $property */ |
48 | 48 | foreach ($properties as $property) { |
49 | 49 | $value = $property->getValue($this); |
50 | - if(is_object($value) && method_exists($value, 'toArray')) { |
|
50 | + if (is_object($value) && method_exists($value, 'toArray')) { |
|
51 | 51 | $dto[$property->getName()] = $value->toArray(); |
52 | - } elseif(is_array($value)) { |
|
53 | - foreach($value as &$arrValue) { |
|
54 | - if($arrValue instanceof Dto) { |
|
52 | + } elseif (is_array($value)) { |
|
53 | + foreach ($value as &$arrValue) { |
|
54 | + if ($arrValue instanceof Dto) { |
|
55 | 55 | $arrValue = $arrValue->toArray(); |
56 | 56 | } |
57 | 57 | } |
58 | 58 | $dto[$property->getName()] = $value; |
59 | - } else { |
|
59 | + }else { |
|
60 | 60 | $dto[$property->getName()] = $property->getValue($this); |
61 | 61 | } |
62 | 62 | } |
63 | 63 | } |
64 | - } catch (\Exception $e) { |
|
65 | - Logger::log(get_class($this) . ': ' . $e->getMessage(), LOG_ERR); |
|
64 | + }catch (\Exception $e) { |
|
65 | + Logger::log(get_class($this).': '.$e->getMessage(), LOG_ERR); |
|
66 | 66 | } |
67 | 67 | return $dto; |
68 | 68 | } |
@@ -85,26 +85,26 @@ discard block |
||
85 | 85 | protected function parseDtoField(array $properties, $key, $value = null) { |
86 | 86 | list($type, $isArray) = $this->extractTypes($properties, $key); |
87 | 87 | $reflector = (class_exists($type)) ? new \ReflectionClass($type) : null; |
88 | - if(null !== $reflector && $reflector->isSubclassOf(Dto::class)) { |
|
89 | - if(null !== $value && is_array($value)) { |
|
90 | - if(!array_key_exists($type, $this->__cache)) { |
|
88 | + if (null !== $reflector && $reflector->isSubclassOf(Dto::class)) { |
|
89 | + if (null !== $value && is_array($value)) { |
|
90 | + if (!array_key_exists($type, $this->__cache)) { |
|
91 | 91 | $this->__cache[$type] = new $type(false); |
92 | 92 | } |
93 | - if($isArray) { |
|
93 | + if ($isArray) { |
|
94 | 94 | $this->$key = []; |
95 | - foreach($value as $data) { |
|
96 | - if(null !== $data && is_array($data)) { |
|
95 | + foreach ($value as $data) { |
|
96 | + if (null !== $data && is_array($data)) { |
|
97 | 97 | $dto = clone $this->__cache[$type]; |
98 | 98 | $dto->fromArray($data); |
99 | 99 | array_push($this->$key, $dto); |
100 | 100 | } |
101 | 101 | } |
102 | - } else { |
|
102 | + }else { |
|
103 | 103 | $this->$key = clone $this->__cache[$type]; |
104 | 104 | $this->$key->fromArray($value); |
105 | 105 | } |
106 | 106 | } |
107 | - } else { |
|
107 | + }else { |
|
108 | 108 | $this->castValue($key, $value, $type); |
109 | 109 | } |
110 | 110 | } |