@@ -25,10 +25,10 @@ discard block |
||
| 25 | 25 | */ |
| 26 | 26 | public function json($response, $statusCode = 200) |
| 27 | 27 | { |
| 28 | - if(Config::getParam('profiling.enable')) { |
|
| 29 | - if(is_array($response)) { |
|
| 28 | + if (Config::getParam('profiling.enable')) { |
|
| 29 | + if (is_array($response)) { |
|
| 30 | 30 | $response['profiling'] = Inspector::getStats(); |
| 31 | - } elseif($response instanceof JsonResponse) { |
|
| 31 | + } elseif ($response instanceof JsonResponse) { |
|
| 32 | 32 | $response = ProfilingJsonResponse::createFromPrevious($response, Inspector::getStats(Config::getParam('log.level'))); |
| 33 | 33 | } |
| 34 | 34 | } |
@@ -36,17 +36,17 @@ discard block |
||
| 36 | 36 | $this->decodeJsonResponse($response); |
| 37 | 37 | |
| 38 | 38 | $mask = JSON_UNESCAPED_LINE_TERMINATORS | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE | JSON_BIGINT_AS_STRING; |
| 39 | - if(Config::getParam('output.json.strict_numbers')) { |
|
| 39 | + if (Config::getParam('output.json.strict_numbers')) { |
|
| 40 | 40 | $mask = JSON_UNESCAPED_LINE_TERMINATORS | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE | JSON_BIGINT_AS_STRING | JSON_NUMERIC_CHECK; |
| 41 | 41 | } |
| 42 | 42 | |
| 43 | 43 | $data = json_encode($response, $mask); |
| 44 | - if(json_last_error() !== JSON_ERROR_NONE) { |
|
| 44 | + if (json_last_error() !== JSON_ERROR_NONE) { |
|
| 45 | 45 | Logger::log(json_last_error_msg(), LOG_CRIT); |
| 46 | 46 | } |
| 47 | 47 | |
| 48 | - if(Config::getParam('angular.protection', false)) { |
|
| 49 | - $data = ")]}',\n" . $data; |
|
| 48 | + if (Config::getParam('angular.protection', false)) { |
|
| 49 | + $data = ")]}',\n".$data; |
|
| 50 | 50 | } |
| 51 | 51 | $this->setStatus($statusCode); |
| 52 | 52 | ResponseHelper::setDebugHeaders([]); |
@@ -32,7 +32,7 @@ discard block |
||
| 32 | 32 | */ |
| 33 | 33 | public static function stats($name = null, $scope = self::SCOPE_PROFILE) { |
| 34 | 34 | self::$debug[] = self::collect($name); |
| 35 | - if($scope === self::SCOPE_PROFILE) { |
|
| 35 | + if ($scope === self::SCOPE_PROFILE) { |
|
| 36 | 36 | self::$profiling[] = self::collect($name); |
| 37 | 37 | } |
| 38 | 38 | } |
@@ -47,7 +47,7 @@ discard block |
||
| 47 | 47 | protected static function calculateStats(array $stats, $timestamp, $mem = 0, $files = 0) { |
| 48 | 48 | return [ |
| 49 | 49 | 'ts' => round($stats['ts'] - $timestamp, 4), |
| 50 | - 'mem' => round(($stats['mem'] - $mem) / 1024 / 1024, 4), |
|
| 50 | + 'mem' => round(($stats['mem'] - $mem)/1024/1024, 4), |
|
| 51 | 51 | 'files' => $stats['files'] - $files, |
| 52 | 52 | 'name' => $stats['name'], |
| 53 | 53 | ]; |
@@ -63,7 +63,7 @@ discard block |
||
| 63 | 63 | $mem = defined('PSFS_START_MEM') ? PSFS_START_MEM : 0; |
| 64 | 64 | $files = 0; |
| 65 | 65 | $scopeSelected = $scope === self::SCOPE_DEBUG ? self::$debug : self::$profiling; |
| 66 | - foreach($scopeSelected as &$value) { |
|
| 66 | + foreach ($scopeSelected as &$value) { |
|
| 67 | 67 | $value = self::calculateStats($value, $timestamp, $mem, $files); |
| 68 | 68 | } |
| 69 | 69 | $scopeSelected[] = self::calculateStats(self::collect('Profiling collect ends'), $timestamp, $mem, $files); |
@@ -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 . ']', Inspector::SCOPE_DEBUG); |
|
| 84 | + Inspector::stats('[i18NHelper] Set locale to project ['.$locale.']', Inspector::SCOPE_DEBUG); |
|
| 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', Inspector::SCOPE_DEBUG); |
| 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,7 +124,7 @@ discard block |
||
| 124 | 124 | */ |
| 125 | 125 | public static function extractDomainInfo(\ReflectionClass $class, $domain) |
| 126 | 126 | { |
| 127 | - $path = dirname($class->getFileName()) . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR; |
|
| 127 | + $path = dirname($class->getFileName()).DIRECTORY_SEPARATOR.'..'.DIRECTORY_SEPARATOR; |
|
| 128 | 128 | $templatesPath = 'templates'; |
| 129 | 129 | $publicPath = 'public'; |
| 130 | 130 | $modelsPath = 'models'; |
@@ -134,13 +134,13 @@ discard block |
||
| 134 | 134 | $modelsPath = ucfirst($modelsPath); |
| 135 | 135 | } |
| 136 | 136 | if ($class->hasConstant('TPL')) { |
| 137 | - $templatesPath .= DIRECTORY_SEPARATOR . $class->getConstant('TPL'); |
|
| 137 | + $templatesPath .= DIRECTORY_SEPARATOR.$class->getConstant('TPL'); |
|
| 138 | 138 | } |
| 139 | 139 | return [ |
| 140 | 140 | 'base' => $path, |
| 141 | - 'template' => $path . $templatesPath, |
|
| 142 | - 'model' => $path . $modelsPath, |
|
| 143 | - 'public' => $path . $publicPath, |
|
| 141 | + 'template' => $path.$templatesPath, |
|
| 142 | + 'model' => $path.$modelsPath, |
|
| 143 | + 'public' => $path.$publicPath, |
|
| 144 | 144 | ]; |
| 145 | 145 | } |
| 146 | 146 | |
@@ -164,12 +164,12 @@ discard block |
||
| 164 | 164 | foreach ($parameters as $param) { |
| 165 | 165 | if ($param->isOptional() && !is_array($param->getDefaultValue())) { |
| 166 | 166 | $params[$param->getName()] = $param->getDefaultValue(); |
| 167 | - $default = str_replace('{' . $param->getName() . '}', $param->getDefaultValue(), $regex); |
|
| 168 | - } elseif(!$param->isOptional()) { |
|
| 167 | + $default = str_replace('{'.$param->getName().'}', $param->getDefaultValue(), $regex); |
|
| 168 | + } elseif (!$param->isOptional()) { |
|
| 169 | 169 | $requirements[] = $param->getName(); |
| 170 | 170 | } |
| 171 | 171 | } |
| 172 | - } else { |
|
| 172 | + }else { |
|
| 173 | 173 | $default = $regex; |
| 174 | 174 | } |
| 175 | 175 | |
@@ -265,7 +265,7 @@ discard block |
||
| 265 | 265 | $httpMethod = self::extractReflectionHttpMethod($docComments); |
| 266 | 266 | $icon = self::extractDocIcon($docComments); |
| 267 | 267 | $label = self::extractReflectionLabel(str_replace('{__API__}', $api, $docComments)); |
| 268 | - $route = $httpMethod . "#|#" . $regex; |
|
| 268 | + $route = $httpMethod."#|#".$regex; |
|
| 269 | 269 | $route = preg_replace('/(\\r|\\f|\\t|\\n)/', '', $route); |
| 270 | 270 | $info = [ |
| 271 | 271 | 'method' => $method->getName(), |
@@ -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', Inspector::SCOPE_DEBUG); |
| 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', Inspector::SCOPE_DEBUG); |
| 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', Inspector::SCOPE_DEBUG); |
| 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]), Inspector::SCOPE_DEBUG); |
|
| 172 | - if (file_exists(CACHE_DIR . DIRECTORY_SEPARATOR . $path)) { |
|
| 171 | + Inspector::stats('[Cache] Reading data from cache: '.json_encode(['path' => $path]), Inspector::SCOPE_DEBUG); |
|
| 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]), Inspector::SCOPE_DEBUG); |
|
| 222 | + Inspector::stats('[Cache] Cache file calculated: '.json_encode(['file' => $filename, 'hash' => $hashPath]), Inspector::SCOPE_DEBUG); |
|
| 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', Inspector::SCOPE_DEBUG); |
| 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 | } |
@@ -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, Inspector::SCOPE_DEBUG); |
|
| 196 | + Inspector::stats('[Router] Searching action to execute: '.$route, Inspector::SCOPE_DEBUG); |
|
| 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', Inspector::SCOPE_DEBUG); |
| 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', Inspector::SCOPE_DEBUG); |
| 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, Inspector::SCOPE_DEBUG); |
|
| 504 | + Inspector::stats('[Router] Executing route '.$route, Inspector::SCOPE_DEBUG); |
|
| 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, Inspector::SCOPE_DEBUG); |
|
| 520 | + Inspector::stats('[Router] Start executing action '.$route, Inspector::SCOPE_DEBUG); |
|
| 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 | } |
@@ -16,8 +16,8 @@ discard block |
||
| 16 | 16 | |
| 17 | 17 | |
| 18 | 18 | if (!defined('LOG_DIR')) { |
| 19 | - GeneratorHelper::createDir(BASE_DIR . DIRECTORY_SEPARATOR . 'logs'); |
|
| 20 | - define('LOG_DIR', BASE_DIR . DIRECTORY_SEPARATOR . 'logs'); |
|
| 19 | + GeneratorHelper::createDir(BASE_DIR.DIRECTORY_SEPARATOR.'logs'); |
|
| 20 | + define('LOG_DIR', BASE_DIR.DIRECTORY_SEPARATOR.'logs'); |
|
| 21 | 21 | } |
| 22 | 22 | |
| 23 | 23 | /** |
@@ -54,7 +54,7 @@ discard block |
||
| 54 | 54 | { |
| 55 | 55 | $args = func_get_args(); |
| 56 | 56 | list($logger, $debug, $path) = $this->setup($args); |
| 57 | - $this->stream = fopen($path . DIRECTORY_SEPARATOR . date('Ymd') . '.log', 'a+'); |
|
| 57 | + $this->stream = fopen($path.DIRECTORY_SEPARATOR.date('Ymd').'.log', 'a+'); |
|
| 58 | 58 | $this->addPushLogger($logger, $debug); |
| 59 | 59 | $this->logLevel = Config::getParam('log.level', 'NOTICE'); |
| 60 | 60 | } |
@@ -136,7 +136,7 @@ discard block |
||
| 136 | 136 | private function createLoggerPath() |
| 137 | 137 | { |
| 138 | 138 | $logger = $this->setLoggerName(); |
| 139 | - $path = LOG_DIR . DIRECTORY_SEPARATOR . $logger . DIRECTORY_SEPARATOR . date('Y') . DIRECTORY_SEPARATOR . date('m'); |
|
| 139 | + $path = LOG_DIR.DIRECTORY_SEPARATOR.$logger.DIRECTORY_SEPARATOR.date('Y').DIRECTORY_SEPARATOR.date('m'); |
|
| 140 | 140 | GeneratorHelper::createDir($path); |
| 141 | 141 | |
| 142 | 142 | return $path; |
@@ -158,7 +158,7 @@ discard block |
||
| 158 | 158 | * @return bool |
| 159 | 159 | */ |
| 160 | 160 | private function checkLogLevel($level = \Monolog\Logger::NOTICE) { |
| 161 | - switch($this->logLevel) { |
|
| 161 | + switch ($this->logLevel) { |
|
| 162 | 162 | case 'DEBUG': $logPass = Monolog::DEBUG; break; |
| 163 | 163 | case 'INFO': $logPass = Monolog::INFO; break; |
| 164 | 164 | default: |
@@ -178,10 +178,10 @@ discard block |
||
| 178 | 178 | */ |
| 179 | 179 | public static function log($msg, $type = LOG_DEBUG, array $context = null, $force = false) |
| 180 | 180 | { |
| 181 | - if(null === $context) { |
|
| 181 | + if (null === $context) { |
|
| 182 | 182 | $context = []; |
| 183 | 183 | } |
| 184 | - if(Config::getParam('profiling.enable') && 'DEBUG' === Config::getParam('log.level', 'NOTICE')) { |
|
| 184 | + if (Config::getParam('profiling.enable') && 'DEBUG' === Config::getParam('log.level', 'NOTICE')) { |
|
| 185 | 185 | Inspector::stats($msg, Inspector::SCOPE_DEBUG); |
| 186 | 186 | } |
| 187 | 187 | switch ($type) { |
@@ -192,7 +192,7 @@ discard block |
||
| 192 | 192 | self::getInstance()->addLog($msg, \Monolog\Logger::WARNING, $context, $force); |
| 193 | 193 | break; |
| 194 | 194 | case LOG_CRIT: |
| 195 | - if(Config::getParam('log.slack.hook')) { |
|
| 195 | + if (Config::getParam('log.slack.hook')) { |
|
| 196 | 196 | SlackHelper::getInstance()->trace($msg, '', '', $context, $force); |
| 197 | 197 | } |
| 198 | 198 | self::getInstance()->addLog($msg, \Monolog\Logger::CRITICAL, $context, $force); |
@@ -235,7 +235,7 @@ discard block |
||
| 235 | 235 | { |
| 236 | 236 | $context['uri'] = null !== $_SERVER && array_key_exists('REQUEST_URI', $_SERVER) ? $_SERVER['REQUEST_URI'] : 'Unknow'; |
| 237 | 237 | $context['method'] = null !== $_SERVER && array_key_exists('REQUEST_METHOD', $_SERVER) ? $_SERVER['REQUEST_METHOD'] : 'Unknow'; |
| 238 | - if(null !== $_SERVER && array_key_exists('HTTP_X_PSFS_UID', $_SERVER)) { |
|
| 238 | + if (null !== $_SERVER && array_key_exists('HTTP_X_PSFS_UID', $_SERVER)) { |
|
| 239 | 239 | $context['uid'] = $_SERVER['HTTP_X_PSFS_UID']; |
| 240 | 240 | } |
| 241 | 241 | return $context; |
@@ -85,7 +85,7 @@ discard block |
||
| 85 | 85 | */ |
| 86 | 86 | protected function init() |
| 87 | 87 | { |
| 88 | - if (file_exists(CONFIG_DIR . DIRECTORY_SEPARATOR . self::CONFIG_FILE)) { |
|
| 88 | + if (file_exists(CONFIG_DIR.DIRECTORY_SEPARATOR.self::CONFIG_FILE)) { |
|
| 89 | 89 | $this->loadConfigData(); |
| 90 | 90 | } |
| 91 | 91 | return $this; |
@@ -201,10 +201,10 @@ discard block |
||
| 201 | 201 | $finalData = array_filter($finalData, function($key, $value) { |
| 202 | 202 | return in_array($key, self::$required, true) || !empty($value); |
| 203 | 203 | }, ARRAY_FILTER_USE_BOTH); |
| 204 | - $saved = (false !== file_put_contents(CONFIG_DIR . DIRECTORY_SEPARATOR . self::CONFIG_FILE, json_encode($finalData, JSON_PRETTY_PRINT))); |
|
| 204 | + $saved = (false !== file_put_contents(CONFIG_DIR.DIRECTORY_SEPARATOR.self::CONFIG_FILE, json_encode($finalData, JSON_PRETTY_PRINT))); |
|
| 205 | 205 | self::getInstance()->loadConfigData(); |
| 206 | 206 | $saved = true; |
| 207 | - } catch (ConfigException $e) { |
|
| 207 | + }catch (ConfigException $e) { |
|
| 208 | 208 | Logger::log($e->getMessage(), LOG_ERR); |
| 209 | 209 | } |
| 210 | 210 | return $saved; |
@@ -236,9 +236,9 @@ discard block |
||
| 236 | 236 | */ |
| 237 | 237 | public function loadConfigData() |
| 238 | 238 | { |
| 239 | - $this->config = json_decode(file_get_contents(CONFIG_DIR . DIRECTORY_SEPARATOR . self::CONFIG_FILE), true) ?: []; |
|
| 239 | + $this->config = json_decode(file_get_contents(CONFIG_DIR.DIRECTORY_SEPARATOR.self::CONFIG_FILE), true) ?: []; |
|
| 240 | 240 | $this->debug = array_key_exists('debug', $this->config) ? (bool)$this->config['debug'] : FALSE; |
| 241 | - if(array_key_exists('cache.var', $this->config)) { |
|
| 241 | + if (array_key_exists('cache.var', $this->config)) { |
|
| 242 | 242 | Security::getInstance()->setSessionKey('config.cache.var', $this->config['cache.var']); |
| 243 | 243 | } |
| 244 | 244 | } |
@@ -260,8 +260,8 @@ discard block |
||
| 260 | 260 | */ |
| 261 | 261 | public static function getParam($key, $defaultValue = null, $module = null) |
| 262 | 262 | { |
| 263 | - if(null !== $module) { |
|
| 264 | - return self::getParam(strtolower($module) . '.' . $key, self::getParam($key, $defaultValue)); |
|
| 263 | + if (null !== $module) { |
|
| 264 | + return self::getParam(strtolower($module).'.'.$key, self::getParam($key, $defaultValue)); |
|
| 265 | 265 | } |
| 266 | 266 | $param = self::getInstance()->get($key); |
| 267 | 267 | return (null !== $param) ? $param : $defaultValue; |
@@ -50,34 +50,34 @@ discard block |
||
| 50 | 50 | $session = Security::getInstance(); |
| 51 | 51 | self::$locale = I18nHelper::extractLocale($session->getSessionKey(I18nHelper::PSFS_SESSION_LANGUAGE_KEY)); |
| 52 | 52 | $version = $session->getSessionKey(self::LOCALE_CACHED_VERSION); |
| 53 | - $configVersion = self::$locale . '_' . Config::getParam('cache.var', 'v1'); |
|
| 53 | + $configVersion = self::$locale.'_'.Config::getParam('cache.var', 'v1'); |
|
| 54 | 54 | if ($forceReload) { |
| 55 | 55 | self::dropInstance(); |
| 56 | 56 | $version = null; |
| 57 | 57 | self::$translations = []; |
| 58 | 58 | } |
| 59 | - if(count(self::$translations) === 0) { |
|
| 59 | + if (count(self::$translations) === 0) { |
|
| 60 | 60 | self::$generate = (boolean)Config::getParam('i18n.autogenerate', false); |
| 61 | - if(null !== $version && $version === $configVersion) { |
|
| 61 | + if (null !== $version && $version === $configVersion) { |
|
| 62 | 62 | self::$translations = $session->getSessionKey(self::LOCALE_CACHED_TAG); |
| 63 | - } else { |
|
| 63 | + }else { |
|
| 64 | 64 | if (!$useBase) { |
| 65 | 65 | $customKey = $customKey ?: $session->getSessionKey(self::CUSTOM_LOCALE_SESSION_KEY); |
| 66 | 66 | } |
| 67 | 67 | // Gather always the base translations |
| 68 | 68 | $standardTranslations = []; |
| 69 | - self::$filename = implode(DIRECTORY_SEPARATOR, [LOCALE_DIR, 'custom', self::$locale . '.json']); |
|
| 70 | - if(file_exists(self::$filename)) { |
|
| 69 | + self::$filename = implode(DIRECTORY_SEPARATOR, [LOCALE_DIR, 'custom', self::$locale.'.json']); |
|
| 70 | + if (file_exists(self::$filename)) { |
|
| 71 | 71 | $standardTranslations = json_decode(file_get_contents(self::$filename), true); |
| 72 | 72 | } |
| 73 | 73 | // If the project has custom translations, gather them |
| 74 | 74 | if (null !== $customKey) { |
| 75 | - Logger::log('[' . self::class . '] Custom key detected: ' . $customKey, LOG_INFO); |
|
| 76 | - self::$filename = implode(DIRECTORY_SEPARATOR, [LOCALE_DIR, 'custom', $customKey, self::$locale . '.json']); |
|
| 75 | + Logger::log('['.self::class.'] Custom key detected: '.$customKey, LOG_INFO); |
|
| 76 | + self::$filename = implode(DIRECTORY_SEPARATOR, [LOCALE_DIR, 'custom', $customKey, self::$locale.'.json']); |
|
| 77 | 77 | } |
| 78 | 78 | // Finally we merge base and custom translations to complete all the i18n set |
| 79 | 79 | if (file_exists(self::$filename)) { |
| 80 | - Logger::log('[' . self::class . '] Custom locale detected: ' . $customKey . ' [' . self::$locale . ']', LOG_INFO); |
|
| 80 | + Logger::log('['.self::class.'] Custom locale detected: '.$customKey.' ['.self::$locale.']', LOG_INFO); |
|
| 81 | 81 | self::$translations = array_merge($standardTranslations, json_decode(file_get_contents(self::$filename), true)); |
| 82 | 82 | $session->setSessionKey(self::LOCALE_CACHED_TAG, self::$translations); |
| 83 | 83 | $session->setSessionKey(self::LOCALE_CACHED_VERSION, $configVersion); |
@@ -102,7 +102,7 @@ discard block |
||
| 102 | 102 | public function getFilters() |
| 103 | 103 | { |
| 104 | 104 | return array( |
| 105 | - new TwigFilter('trans', function ($message) { |
|
| 105 | + new TwigFilter('trans', function($message) { |
|
| 106 | 106 | return self::_($message); |
| 107 | 107 | }), |
| 108 | 108 | ); |
@@ -127,7 +127,7 @@ discard block |
||
| 127 | 127 | self::checkLoad($customKey, $forceReload); |
| 128 | 128 | if (is_array(self::$translations) && array_key_exists($message, self::$translations)) { |
| 129 | 129 | $translation = self::$translations[$message]; |
| 130 | - } else { |
|
| 130 | + }else { |
|
| 131 | 131 | $translation = gettext($message); |
| 132 | 132 | } |
| 133 | 133 | if (self::$generate) { |