@@ -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 | $defaultLocales = explode(',', Config::getParam('i18n.locales', '')); |
| 51 | 51 | if (!in_array($locale, array_merge($defaultLocales, self::$langs))) { |
@@ -64,7 +64,7 @@ discard block |
||
| 64 | 64 | $translations = array(); |
| 65 | 65 | if (file_exists($absoluteFileName)) { |
| 66 | 66 | @include($absoluteFileName); |
| 67 | - } else { |
|
| 67 | + }else { |
|
| 68 | 68 | Cache::getInstance()->storeData($absoluteFileName, "<?php \$translations = array();\n", Cache::TEXT, TRUE); |
| 69 | 69 | } |
| 70 | 70 | |
@@ -81,19 +81,19 @@ discard block |
||
| 81 | 81 | public static function setLocale(string $default = null, string $customKey = null, bool $force = false): void |
| 82 | 82 | { |
| 83 | 83 | $locale = $force ? $default : 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'); |
| 94 | 94 | bind_textdomain_codeset('translations', 'UTF-8'); |
| 95 | 95 | Security::getInstance()->setSessionKey(I18nHelper::PSFS_SESSION_LANGUAGE_KEY, substr($locale, 0, 2)); |
| 96 | - if($force) t('', $customKey, true); |
|
| 96 | + if ($force) t('', $customKey, true); |
|
| 97 | 97 | } |
| 98 | 98 | |
| 99 | 99 | /** |
@@ -153,7 +153,7 @@ discard block |
||
| 153 | 153 | ['i', 'i', 'i', 'i', 'I', 'I', 'I', 'I'], |
| 154 | 154 | ['o', 'o', 'o', 'o', 'O', 'O', 'O', 'O'], |
| 155 | 155 | ['u', 'u', 'u', 'u', 'U', 'U', 'U', 'U'], |
| 156 | - ['n', 'N', 'c', 'C',], |
|
| 156 | + ['n', 'N', 'c', 'C', ], |
|
| 157 | 157 | ]; |
| 158 | 158 | |
| 159 | 159 | $text = htmlspecialchars($string); |
@@ -173,24 +173,24 @@ discard block |
||
| 173 | 173 | */ |
| 174 | 174 | public static function findTranslations(string $path, string $locale): array |
| 175 | 175 | { |
| 176 | - $localePath = realpath(BASE_DIR . DIRECTORY_SEPARATOR . 'locale'); |
|
| 177 | - $localePath .= DIRECTORY_SEPARATOR . $locale . DIRECTORY_SEPARATOR . 'LC_MESSAGES' . DIRECTORY_SEPARATOR; |
|
| 176 | + $localePath = realpath(BASE_DIR.DIRECTORY_SEPARATOR.'locale'); |
|
| 177 | + $localePath .= DIRECTORY_SEPARATOR.$locale.DIRECTORY_SEPARATOR.'LC_MESSAGES'.DIRECTORY_SEPARATOR; |
|
| 178 | 178 | |
| 179 | 179 | $translations = array(); |
| 180 | 180 | if (file_exists($path)) { |
| 181 | 181 | $directory = dir($path); |
| 182 | 182 | while (false !== ($fileName = $directory->read())) { |
| 183 | 183 | GeneratorHelper::createDir($localePath); |
| 184 | - if (!file_exists($localePath . 'translations.po')) { |
|
| 185 | - file_put_contents($localePath . 'translations.po', ''); |
|
| 184 | + if (!file_exists($localePath.'translations.po')) { |
|
| 185 | + file_put_contents($localePath.'translations.po', ''); |
|
| 186 | 186 | } |
| 187 | - $inspectPath = realpath($path . DIRECTORY_SEPARATOR . $fileName); |
|
| 188 | - $cmdPhp = "export PATH=\$PATH:/opt/local/bin; xgettext " . |
|
| 189 | - $inspectPath . DIRECTORY_SEPARATOR . |
|
| 187 | + $inspectPath = realpath($path.DIRECTORY_SEPARATOR.$fileName); |
|
| 188 | + $cmdPhp = "export PATH=\$PATH:/opt/local/bin; xgettext ". |
|
| 189 | + $inspectPath.DIRECTORY_SEPARATOR. |
|
| 190 | 190 | "*.php --from-code=UTF-8 -j -L PHP --debug --force-po -o {$localePath}translations.po"; |
| 191 | - if (is_dir($path . DIRECTORY_SEPARATOR . $fileName) && preg_match('/^\./', $fileName) == 0) { |
|
| 192 | - $res = t('Revisando directorio: ') . $inspectPath; |
|
| 193 | - $res .= t('Comando ejecutado: ') . $cmdPhp; |
|
| 191 | + if (is_dir($path.DIRECTORY_SEPARATOR.$fileName) && preg_match('/^\./', $fileName) == 0) { |
|
| 192 | + $res = t('Revisando directorio: ').$inspectPath; |
|
| 193 | + $res .= t('Comando ejecutado: ').$cmdPhp; |
|
| 194 | 194 | $res .= shell_exec($cmdPhp); |
| 195 | 195 | usleep(10); |
| 196 | 196 | $translations[] = $res; |
@@ -93,7 +93,9 @@ |
||
| 93 | 93 | textdomain('translations'); |
| 94 | 94 | bind_textdomain_codeset('translations', 'UTF-8'); |
| 95 | 95 | Security::getInstance()->setSessionKey(I18nHelper::PSFS_SESSION_LANGUAGE_KEY, substr($locale, 0, 2)); |
| 96 | - if($force) t('', $customKey, true); |
|
| 96 | + if($force) { |
|
| 97 | + t('', $customKey, true); |
|
| 98 | + } |
|
| 97 | 99 | } |
| 98 | 100 | |
| 99 | 101 | /** |
@@ -48,7 +48,7 @@ discard block |
||
| 48 | 48 | { |
| 49 | 49 | // Gather always the base translations |
| 50 | 50 | $standardTranslations = []; |
| 51 | - self::$filename = implode(DIRECTORY_SEPARATOR, [LOCALE_DIR, 'custom', self::$locale . '.json']); |
|
| 51 | + self::$filename = implode(DIRECTORY_SEPARATOR, [LOCALE_DIR, 'custom', self::$locale.'.json']); |
|
| 52 | 52 | if (file_exists(self::$filename)) { |
| 53 | 53 | $standardTranslations = json_decode(file_get_contents(self::$filename), true); |
| 54 | 54 | } |
@@ -67,32 +67,32 @@ discard block |
||
| 67 | 67 | $session_locale = $session->getSessionKey(I18nHelper::PSFS_SESSION_LANGUAGE_KEY); |
| 68 | 68 | self::$locale = $forceReload ? $session_locale : I18nHelper::extractLocale($session_locale); |
| 69 | 69 | $version = $session->getSessionKey(self::LOCALE_CACHED_VERSION); |
| 70 | - $configVersion = self::$locale . '_' . Config::getParam('cache.var', 'v1'); |
|
| 70 | + $configVersion = self::$locale.'_'.Config::getParam('cache.var', 'v1'); |
|
| 71 | 71 | if ($forceReload) { |
| 72 | 72 | Inspector::stats('[translationsCheckLoad] Force translations reload', Inspector::SCOPE_DEBUG); |
| 73 | 73 | self::dropInstance(); |
| 74 | 74 | $version = null; |
| 75 | 75 | self::$translations = []; |
| 76 | 76 | } |
| 77 | - if(count(self::$translations) === 0) { |
|
| 77 | + if (count(self::$translations) === 0) { |
|
| 78 | 78 | Inspector::stats('[translationsCheckLoad] Extracting translations', Inspector::SCOPE_DEBUG); |
| 79 | 79 | self::$generate = (boolean)Config::getParam('i18n.autogenerate', false); |
| 80 | - if(null !== $version && $version === $configVersion) { |
|
| 80 | + if (null !== $version && $version === $configVersion) { |
|
| 81 | 81 | Inspector::stats('[translationsCheckLoad] Translations loaded from session', Inspector::SCOPE_DEBUG); |
| 82 | 82 | self::$translations = $session->getSessionKey(self::LOCALE_CACHED_TAG); |
| 83 | - } else { |
|
| 83 | + }else { |
|
| 84 | 84 | if (!$useBase) { |
| 85 | 85 | $customKey = $customKey ?: $session->getSessionKey(self::CUSTOM_LOCALE_SESSION_KEY); |
| 86 | 86 | } |
| 87 | 87 | $standardTranslations = self::extractBaseTranslations(); |
| 88 | 88 | // If the project has custom translations, gather them |
| 89 | 89 | if (null !== $customKey) { |
| 90 | - Logger::log('[' . self::class . '] Custom key detected: ' . $customKey, LOG_INFO); |
|
| 91 | - self::$filename = implode(DIRECTORY_SEPARATOR, [LOCALE_DIR, 'custom', $customKey, self::$locale . '.json']); |
|
| 90 | + Logger::log('['.self::class.'] Custom key detected: '.$customKey, LOG_INFO); |
|
| 91 | + self::$filename = implode(DIRECTORY_SEPARATOR, [LOCALE_DIR, 'custom', $customKey, self::$locale.'.json']); |
|
| 92 | 92 | } |
| 93 | 93 | // Finally we merge base and custom translations to complete all the i18n set |
| 94 | 94 | if (file_exists(self::$filename)) { |
| 95 | - Logger::log('[' . self::class . '] Custom locale detected: ' . $customKey . ' [' . self::$locale . ']', LOG_INFO); |
|
| 95 | + Logger::log('['.self::class.'] Custom locale detected: '.$customKey.' ['.self::$locale.']', LOG_INFO); |
|
| 96 | 96 | self::$translations = array_merge($standardTranslations, json_decode(file_get_contents(self::$filename), true)); |
| 97 | 97 | $session->setSessionKey(self::LOCALE_CACHED_TAG, self::$translations); |
| 98 | 98 | $session->setSessionKey(self::LOCALE_CACHED_VERSION, $configVersion); |
@@ -118,7 +118,7 @@ discard block |
||
| 118 | 118 | public function getFilters() |
| 119 | 119 | { |
| 120 | 120 | return array( |
| 121 | - new TwigFilter('trans', function ($message) { |
|
| 121 | + new TwigFilter('trans', function($message) { |
|
| 122 | 122 | return self::_($message); |
| 123 | 123 | }), |
| 124 | 124 | ); |
@@ -140,12 +140,12 @@ discard block |
||
| 140 | 140 | */ |
| 141 | 141 | public static function _($message, $customKey = null, $forceReload = false) |
| 142 | 142 | { |
| 143 | - if(0 === count(self::$translations) || $forceReload) { |
|
| 143 | + if (0 === count(self::$translations) || $forceReload) { |
|
| 144 | 144 | self::translationsCheckLoad($customKey, $forceReload); |
| 145 | 145 | } |
| 146 | 146 | if (is_array(self::$translations) && array_key_exists($message, self::$translations)) { |
| 147 | 147 | $translation = self::$translations[$message]; |
| 148 | - } else { |
|
| 148 | + }else { |
|
| 149 | 149 | $translation = gettext($message); |
| 150 | 150 | } |
| 151 | 151 | if (self::$generate) { |
@@ -37,7 +37,7 @@ discard block |
||
| 37 | 37 | foreach ($domains as $domain => $routes) { |
| 38 | 38 | $pDomain = str_replace('@', '', $domain); |
| 39 | 39 | $pDomain = str_replace('/', '', $pDomain); |
| 40 | - $response[] = strtolower($pDomain) . '.api.secret'; |
|
| 40 | + $response[] = strtolower($pDomain).'.api.secret'; |
|
| 41 | 41 | } |
| 42 | 42 | return $this->json($response); |
| 43 | 43 | } |
@@ -53,7 +53,7 @@ discard block |
||
| 53 | 53 | */ |
| 54 | 54 | public function config() |
| 55 | 55 | { |
| 56 | - Logger::log("Config loaded executed by " . $this->getRequest()->getRequestUri()); |
|
| 56 | + Logger::log("Config loaded executed by ".$this->getRequest()->getRequestUri()); |
|
| 57 | 57 | if (defined('PSFS_UNIT_TESTING_EXECUTION')) { |
| 58 | 58 | throw new ConfigException('CONFIG'); |
| 59 | 59 | } |
@@ -92,7 +92,7 @@ discard block |
||
| 92 | 92 | } |
| 93 | 93 | Security::getInstance()->setFlash("callback_message", t("Configuración actualizada correctamente")); |
| 94 | 94 | Security::getInstance()->setFlash("callback_route", $this->getRoute("admin-config", true)); |
| 95 | - } else { |
|
| 95 | + }else { |
|
| 96 | 96 | throw new HttpException(t('Error al guardar la configuración, prueba a cambiar los permisos'), 403); |
| 97 | 97 | } |
| 98 | 98 | } |
@@ -24,10 +24,10 @@ discard block |
||
| 24 | 24 | $objects = scandir($dir); |
| 25 | 25 | foreach ($objects as $object) { |
| 26 | 26 | if ($object != "." && $object != "..") { |
| 27 | - if (filetype($dir . "/" . $object) == "dir") { |
|
| 28 | - self::deleteDir($dir . "/" . $object); |
|
| 29 | - } else { |
|
| 30 | - unlink($dir . "/" . $object); |
|
| 27 | + if (filetype($dir."/".$object) == "dir") { |
|
| 28 | + self::deleteDir($dir."/".$object); |
|
| 29 | + }else { |
|
| 30 | + unlink($dir."/".$object); |
|
| 31 | 31 | } |
| 32 | 32 | } |
| 33 | 33 | } |
@@ -43,10 +43,10 @@ discard block |
||
| 43 | 43 | { |
| 44 | 44 | $rootDirs = array("css", "js", "media", "font"); |
| 45 | 45 | foreach ($rootDirs as $dir) { |
| 46 | - if (file_exists(WEB_DIR . DIRECTORY_SEPARATOR . $dir)) { |
|
| 46 | + if (file_exists(WEB_DIR.DIRECTORY_SEPARATOR.$dir)) { |
|
| 47 | 47 | try { |
| 48 | - self::deleteDir(WEB_DIR . DIRECTORY_SEPARATOR . $dir); |
|
| 49 | - } catch (\Exception $e) { |
|
| 48 | + self::deleteDir(WEB_DIR.DIRECTORY_SEPARATOR.$dir); |
|
| 49 | + }catch (\Exception $e) { |
|
| 50 | 50 | syslog(LOG_INFO, $e->getMessage()); |
| 51 | 51 | } |
| 52 | 52 | } |
@@ -63,12 +63,12 @@ discard block |
||
| 63 | 63 | if (!empty($dir)) { |
| 64 | 64 | try { |
| 65 | 65 | if (!is_dir($dir) && @mkdir($dir, 0775, true) === false) { |
| 66 | - throw new \Exception(t('Can\'t create directory ') . $dir); |
|
| 66 | + throw new \Exception(t('Can\'t create directory ').$dir); |
|
| 67 | 67 | } |
| 68 | - } catch (\Exception $e) { |
|
| 68 | + }catch (\Exception $e) { |
|
| 69 | 69 | syslog(LOG_WARNING, $e->getMessage()); |
| 70 | 70 | if (!file_exists(dirname($dir))) { |
| 71 | - throw new GeneratorException($e->getMessage() . $dir); |
|
| 71 | + throw new GeneratorException($e->getMessage().$dir); |
|
| 72 | 72 | } |
| 73 | 73 | } |
| 74 | 74 | } |
@@ -80,7 +80,7 @@ discard block |
||
| 80 | 80 | */ |
| 81 | 81 | public static function getTemplatePath() |
| 82 | 82 | { |
| 83 | - $path = __DIR__ . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'templates' . DIRECTORY_SEPARATOR; |
|
| 83 | + $path = __DIR__.DIRECTORY_SEPARATOR.'..'.DIRECTORY_SEPARATOR.'..'.DIRECTORY_SEPARATOR.'..'.DIRECTORY_SEPARATOR.'templates'.DIRECTORY_SEPARATOR; |
|
| 84 | 84 | return realpath($path); |
| 85 | 85 | } |
| 86 | 86 | |
@@ -109,7 +109,7 @@ discard block |
||
| 109 | 109 | } elseif (!$reflector->isAbstract()) { |
| 110 | 110 | throw new GeneratorException(t('La clase definida debe ser abstracta'), 501); |
| 111 | 111 | } |
| 112 | - } else { |
|
| 112 | + }else { |
|
| 113 | 113 | throw new GeneratorException(t('La clase definida para extender la API no existe'), 501); |
| 114 | 114 | } |
| 115 | 115 | } |
@@ -131,7 +131,7 @@ discard block |
||
| 131 | 131 | GeneratorHelper::createDir($path); |
| 132 | 132 | $paths = array("js", "css", "img", "media", "font"); |
| 133 | 133 | foreach ($paths as $htmlPath) { |
| 134 | - GeneratorHelper::createDir($path . DIRECTORY_SEPARATOR . $htmlPath); |
|
| 134 | + GeneratorHelper::createDir($path.DIRECTORY_SEPARATOR.$htmlPath); |
|
| 135 | 135 | } |
| 136 | 136 | |
| 137 | 137 | // Generates the root needed files |
@@ -141,31 +141,31 @@ discard block |
||
| 141 | 141 | 'crossdomain' => 'crossdomain.xml', |
| 142 | 142 | 'humans' => 'humans.txt', |
| 143 | 143 | 'robots' => 'robots.txt', |
| 144 | - 'docker' => '..' . DIRECTORY_SEPARATOR . 'docker-compose.yml', |
|
| 144 | + 'docker' => '..'.DIRECTORY_SEPARATOR.'docker-compose.yml', |
|
| 145 | 145 | ]; |
| 146 | 146 | $verificable = ['humans', 'robots', 'docker']; |
| 147 | 147 | $output->writeln('Start creating html files'); |
| 148 | 148 | foreach ($files as $template => $filename) { |
| 149 | - if (in_array($template, $verificable) && file_exists($path . DIRECTORY_SEPARATOR . $filename)) { |
|
| 150 | - $output->writeln($filename . ' already exists'); |
|
| 149 | + if (in_array($template, $verificable) && file_exists($path.DIRECTORY_SEPARATOR.$filename)) { |
|
| 150 | + $output->writeln($filename.' already exists'); |
|
| 151 | 151 | continue; |
| 152 | 152 | } |
| 153 | - $text = Template::getInstance()->dump("generator/html/" . $template . '.html.twig'); |
|
| 154 | - if (false === file_put_contents($path . DIRECTORY_SEPARATOR . $filename, $text)) { |
|
| 153 | + $text = Template::getInstance()->dump("generator/html/".$template.'.html.twig'); |
|
| 154 | + if (false === file_put_contents($path.DIRECTORY_SEPARATOR.$filename, $text)) { |
|
| 155 | 155 | if (!$quiet) { |
| 156 | - $output->writeln('Can\t create the file ' . $filename); |
|
| 156 | + $output->writeln('Can\t create the file '.$filename); |
|
| 157 | 157 | } |
| 158 | - } else { |
|
| 158 | + }else { |
|
| 159 | 159 | if (!$quiet) { |
| 160 | - $output->writeln($filename . ' created successfully'); |
|
| 160 | + $output->writeln($filename.' created successfully'); |
|
| 161 | 161 | } |
| 162 | 162 | } |
| 163 | 163 | } |
| 164 | 164 | |
| 165 | 165 | //Export base locale translations |
| 166 | - if (!file_exists(BASE_DIR . DIRECTORY_SEPARATOR . 'locale')) { |
|
| 167 | - GeneratorHelper::createDir(BASE_DIR . DIRECTORY_SEPARATOR . 'locale'); |
|
| 168 | - self::copyr(SOURCE_DIR . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'locale', BASE_DIR . DIRECTORY_SEPARATOR . 'locale'); |
|
| 166 | + if (!file_exists(BASE_DIR.DIRECTORY_SEPARATOR.'locale')) { |
|
| 167 | + GeneratorHelper::createDir(BASE_DIR.DIRECTORY_SEPARATOR.'locale'); |
|
| 168 | + self::copyr(SOURCE_DIR.DIRECTORY_SEPARATOR.'..'.DIRECTORY_SEPARATOR.'locale', BASE_DIR.DIRECTORY_SEPARATOR.'locale'); |
|
| 169 | 169 | } |
| 170 | 170 | } |
| 171 | 171 | |
@@ -181,12 +181,12 @@ discard block |
||
| 181 | 181 | { |
| 182 | 182 | if (file_exists($filenamePath)) { |
| 183 | 183 | $destfolder = basename($filenamePath); |
| 184 | - if (!file_exists(WEB_DIR . $dest . DIRECTORY_SEPARATOR . $destfolder) || $debug || $force) { |
|
| 184 | + if (!file_exists(WEB_DIR.$dest.DIRECTORY_SEPARATOR.$destfolder) || $debug || $force) { |
|
| 185 | 185 | if (is_dir($filenamePath)) { |
| 186 | - self::copyr($filenamePath, WEB_DIR . $dest . DIRECTORY_SEPARATOR . $destfolder); |
|
| 187 | - } else { |
|
| 188 | - if (@copy($filenamePath, WEB_DIR . $dest . DIRECTORY_SEPARATOR . $destfolder) === FALSE) { |
|
| 189 | - throw new ConfigException("Can't copy " . $filenamePath . " to " . WEB_DIR . $dest . DIRECTORY_SEPARATOR . $destfolder); |
|
| 186 | + self::copyr($filenamePath, WEB_DIR.$dest.DIRECTORY_SEPARATOR.$destfolder); |
|
| 187 | + }else { |
|
| 188 | + if (@copy($filenamePath, WEB_DIR.$dest.DIRECTORY_SEPARATOR.$destfolder) === FALSE) { |
|
| 189 | + throw new ConfigException("Can't copy ".$filenamePath." to ".WEB_DIR.$dest.DIRECTORY_SEPARATOR.$destfolder); |
|
| 190 | 190 | } |
| 191 | 191 | } |
| 192 | 192 | } |
@@ -204,10 +204,10 @@ discard block |
||
| 204 | 204 | self::createDir($dst); |
| 205 | 205 | while (false !== ($file = readdir($dir))) { |
| 206 | 206 | if (($file != '.') && ($file != '..')) { |
| 207 | - if (is_dir($src . '/' . $file)) { |
|
| 208 | - self::copyr($src . '/' . $file, $dst . '/' . $file); |
|
| 209 | - } elseif (@copy($src . '/' . $file, $dst . '/' . $file) === false) { |
|
| 210 | - throw new ConfigException("Can't copy " . $src . " to " . $dst); |
|
| 207 | + if (is_dir($src.'/'.$file)) { |
|
| 208 | + self::copyr($src.'/'.$file, $dst.'/'.$file); |
|
| 209 | + } elseif (@copy($src.'/'.$file, $dst.'/'.$file) === false) { |
|
| 210 | + throw new ConfigException("Can't copy ".$src." to ".$dst); |
|
| 211 | 211 | } |
| 212 | 212 | } |
| 213 | 213 | } |
@@ -21,10 +21,10 @@ |
||
| 21 | 21 | $now = new \DateTime(); |
| 22 | 22 | $now->setTimezone(new \DateTimeZone(Config::getParam('project.timezone', 'Europe/Madrid'))); |
| 23 | 23 | $config = Config::getInstance()->dumpConfig(); |
| 24 | - if (file_exists(CACHE_DIR . DIRECTORY_SEPARATOR . $config[self::CACHE_VAR_TAG] . '.file.cache')) { |
|
| 25 | - unlink(CACHE_DIR . DIRECTORY_SEPARATOR . $config[self::CACHE_VAR_TAG] . '.file.cache'); |
|
| 24 | + if (file_exists(CACHE_DIR.DIRECTORY_SEPARATOR.$config[self::CACHE_VAR_TAG].'.file.cache')) { |
|
| 25 | + unlink(CACHE_DIR.DIRECTORY_SEPARATOR.$config[self::CACHE_VAR_TAG].'.file.cache'); |
|
| 26 | 26 | } |
| 27 | - $config[self::CACHE_VAR_TAG] = 'v' . $now->format('Ymd.His'); |
|
| 27 | + $config[self::CACHE_VAR_TAG] = 'v'.$now->format('Ymd.His'); |
|
| 28 | 28 | Config::save($config); |
| 29 | 29 | return $config[self::CACHE_VAR_TAG]; |
| 30 | 30 | } |
@@ -96,7 +96,7 @@ discard block |
||
| 96 | 96 | */ |
| 97 | 97 | protected function init() |
| 98 | 98 | { |
| 99 | - if (file_exists(CONFIG_DIR . DIRECTORY_SEPARATOR . self::CONFIG_FILE)) { |
|
| 99 | + if (file_exists(CONFIG_DIR.DIRECTORY_SEPARATOR.self::CONFIG_FILE)) { |
|
| 100 | 100 | $this->loadConfigData(); |
| 101 | 101 | } |
| 102 | 102 | return $this; |
@@ -211,13 +211,13 @@ discard block |
||
| 211 | 211 | $finalData = self::saveExtraParams($data); |
| 212 | 212 | $saved = false; |
| 213 | 213 | try { |
| 214 | - $finalData = array_filter($finalData, function ($key, $value) { |
|
| 214 | + $finalData = array_filter($finalData, function($key, $value) { |
|
| 215 | 215 | return in_array($key, self::$required, true) || !empty($value); |
| 216 | 216 | }, ARRAY_FILTER_USE_BOTH); |
| 217 | - $saved = (false !== file_put_contents(CONFIG_DIR . DIRECTORY_SEPARATOR . self::CONFIG_FILE, json_encode($finalData, JSON_PRETTY_PRINT))); |
|
| 217 | + $saved = (false !== file_put_contents(CONFIG_DIR.DIRECTORY_SEPARATOR.self::CONFIG_FILE, json_encode($finalData, JSON_PRETTY_PRINT))); |
|
| 218 | 218 | self::getInstance()->loadConfigData(); |
| 219 | 219 | $saved = true; |
| 220 | - } catch (ConfigException $e) { |
|
| 220 | + }catch (ConfigException $e) { |
|
| 221 | 221 | Logger::log($e->getMessage(), LOG_ERR); |
| 222 | 222 | } |
| 223 | 223 | return $saved; |
@@ -249,7 +249,7 @@ discard block |
||
| 249 | 249 | */ |
| 250 | 250 | public function loadConfigData() |
| 251 | 251 | { |
| 252 | - $this->config = json_decode(file_get_contents(CONFIG_DIR . DIRECTORY_SEPARATOR . self::CONFIG_FILE), true) ?: []; |
|
| 252 | + $this->config = json_decode(file_get_contents(CONFIG_DIR.DIRECTORY_SEPARATOR.self::CONFIG_FILE), true) ?: []; |
|
| 253 | 253 | $this->debug = array_key_exists('debug', $this->config) ? (bool)$this->config['debug'] : FALSE; |
| 254 | 254 | if (array_key_exists('cache.var', $this->config)) { |
| 255 | 255 | Security::getInstance()->setSessionKey('config.cache.var', $this->config['cache.var']); |
@@ -274,7 +274,7 @@ discard block |
||
| 274 | 274 | public static function getParam($key, $defaultValue = null, $module = null) |
| 275 | 275 | { |
| 276 | 276 | if (null !== $module) { |
| 277 | - return self::getParam(strtolower($module) . '.' . $key, self::getParam($key, $defaultValue)); |
|
| 277 | + return self::getParam(strtolower($module).'.'.$key, self::getParam($key, $defaultValue)); |
|
| 278 | 278 | } |
| 279 | 279 | $param = self::getInstance()->get($key); |
| 280 | 280 | return (null !== $param) ? $param : $defaultValue; |
@@ -291,8 +291,8 @@ discard block |
||
| 291 | 291 | $configs = ['domains.json', 'urls.json']; |
| 292 | 292 | $done = true; |
| 293 | 293 | foreach ($configs as $configFile) { |
| 294 | - if (file_exists(CONFIG_DIR . DIRECTORY_SEPARATOR . $configFile)) { |
|
| 295 | - if (!unlink(CONFIG_DIR . DIRECTORY_SEPARATOR . $configFile)) { |
|
| 294 | + if (file_exists(CONFIG_DIR.DIRECTORY_SEPARATOR.$configFile)) { |
|
| 295 | + if (!unlink(CONFIG_DIR.DIRECTORY_SEPARATOR.$configFile)) { |
|
| 296 | 296 | $done = false; |
| 297 | 297 | } |
| 298 | 298 | } |
@@ -44,13 +44,13 @@ discard block |
||
| 44 | 44 | |
| 45 | 45 | $filePath = ''; |
| 46 | 46 | if (!file_exists($filePath)) { |
| 47 | - $filePath = BASE_DIR . $string; |
|
| 47 | + $filePath = BASE_DIR.$string; |
|
| 48 | 48 | } |
| 49 | 49 | $filenamePath = AssetsHelper::findDomainPath($string, $filePath); |
| 50 | 50 | |
| 51 | 51 | $filePath = self::processAsset($string, $name, $return, $filenamePath); |
| 52 | 52 | $basePath = Config::getParam('resources.cdn.url', Request::getInstance()->getRootUrl()); |
| 53 | - $returnPath = empty($name) ? $basePath . '/' . $filePath : $name; |
|
| 53 | + $returnPath = empty($name) ? $basePath.'/'.$filePath : $name; |
|
| 54 | 54 | return $return ? $returnPath : ''; |
| 55 | 55 | } |
| 56 | 56 | |
@@ -67,7 +67,7 @@ discard block |
||
| 67 | 67 | $router = Router::getInstance(); |
| 68 | 68 | try { |
| 69 | 69 | return $router->getRoute($path, $absolute, $params); |
| 70 | - } catch (\Exception $e) { |
|
| 70 | + }catch (\Exception $e) { |
|
| 71 | 71 | return $router->getRoute('', $absolute, $params); |
| 72 | 72 | } |
| 73 | 73 | } |
@@ -161,12 +161,12 @@ discard block |
||
| 161 | 161 | $domains = Template::getDomains(true); |
| 162 | 162 | $filenamePath = self::extractPathname($path, $domains); |
| 163 | 163 | // Check if resources has been copied to public folders |
| 164 | - if(!$debug) { |
|
| 165 | - $cacheFilename = Config::getParam('cache.var', '__initial__') . '.file.cache'; |
|
| 164 | + if (!$debug) { |
|
| 165 | + $cacheFilename = Config::getParam('cache.var', '__initial__').'.file.cache'; |
|
| 166 | 166 | $cachedFiles = Cache::getInstance()->readFromCache($cacheFilename, |
| 167 | 167 | 1, fn() => [], Cache::JSON, true) ?: []; |
| 168 | 168 | // Force the resource copy |
| 169 | - if(!in_array($filenamePath, $cachedFiles) || $force) { |
|
| 169 | + if (!in_array($filenamePath, $cachedFiles) || $force) { |
|
| 170 | 170 | $force = true; |
| 171 | 171 | $cachedFiles[] = $filenamePath; |
| 172 | 172 | Cache::getInstance()->storeData($cacheFilename, $cachedFiles, Cache::JSON); |
@@ -226,9 +226,9 @@ discard block |
||
| 226 | 226 | { |
| 227 | 227 | $data = file_get_contents($filenamePath); |
| 228 | 228 | if (!empty($name)) { |
| 229 | - file_put_contents(WEB_DIR . DIRECTORY_SEPARATOR . $name, $data); |
|
| 230 | - } else { |
|
| 231 | - file_put_contents($base . $filePath, $data); |
|
| 229 | + file_put_contents(WEB_DIR.DIRECTORY_SEPARATOR.$name, $data); |
|
| 230 | + }else { |
|
| 231 | + file_put_contents($base.$filePath, $data); |
|
| 232 | 232 | } |
| 233 | 233 | } |
| 234 | 234 | |
@@ -247,9 +247,9 @@ discard block |
||
| 247 | 247 | if (file_exists($filenamePath)) { |
| 248 | 248 | list($base, $htmlBase, $filePath) = AssetsHelper::calculateAssetPath($string, $name, $return, $filenamePath); |
| 249 | 249 | //Creamos el directorio si no existe |
| 250 | - GeneratorHelper::createDir($base . $htmlBase); |
|
| 250 | + GeneratorHelper::createDir($base.$htmlBase); |
|
| 251 | 251 | //Si se ha modificado |
| 252 | - if (!file_exists($base . $filePath) || filemtime($base . $filePath) < filemtime($filenamePath)) { |
|
| 252 | + if (!file_exists($base.$filePath) || filemtime($base.$filePath) < filemtime($filenamePath)) { |
|
| 253 | 253 | if ($htmlBase === 'css') { |
| 254 | 254 | self::processCssLines($filenamePath); |
| 255 | 255 | } |
@@ -56,7 +56,7 @@ discard block |
||
| 56 | 56 | { |
| 57 | 57 | GeneratorHelper::createDir(dirname($path)); |
| 58 | 58 | if (false === FileHelper::writeFile($path, $data)) { |
| 59 | - throw new ConfigException(t('No se tienen los permisos suficientes para escribir en el fichero ') . $path); |
|
| 59 | + throw new ConfigException(t('No se tienen los permisos suficientes para escribir en el fichero ').$path); |
|
| 60 | 60 | } |
| 61 | 61 | } |
| 62 | 62 | |
@@ -70,7 +70,7 @@ discard block |
||
| 70 | 70 | { |
| 71 | 71 | Inspector::stats('[Cache] Gathering data from cache', Inspector::SCOPE_DEBUG); |
| 72 | 72 | $data = null; |
| 73 | - $absolutePath = $absolute ? $path : CACHE_DIR . DIRECTORY_SEPARATOR . $path; |
|
| 73 | + $absolutePath = $absolute ? $path : CACHE_DIR.DIRECTORY_SEPARATOR.$path; |
|
| 74 | 74 | if (file_exists($absolutePath)) { |
| 75 | 75 | $data = FileHelper::readFile($absolutePath); |
| 76 | 76 | } |
@@ -86,7 +86,7 @@ discard block |
||
| 86 | 86 | private function hasExpiredCache($path, $expires = 300, $absolute = false) |
| 87 | 87 | { |
| 88 | 88 | Inspector::stats('[Cache] Checking expiration', Inspector::SCOPE_DEBUG); |
| 89 | - $absolutePath = ($absolute) ? $path : CACHE_DIR . DIRECTORY_SEPARATOR . $path; |
|
| 89 | + $absolutePath = ($absolute) ? $path : CACHE_DIR.DIRECTORY_SEPARATOR.$path; |
|
| 90 | 90 | $lasModificationDate = filemtime($absolutePath); |
| 91 | 91 | return ($lasModificationDate + $expires <= time()); |
| 92 | 92 | } |
@@ -153,7 +153,7 @@ discard block |
||
| 153 | 153 | { |
| 154 | 154 | Inspector::stats('[Cache] Store data in cache', Inspector::SCOPE_DEBUG); |
| 155 | 155 | $data = self::transformData($data, $transform); |
| 156 | - $absolutePath = $absolute ? $path : CACHE_DIR . DIRECTORY_SEPARATOR . $path; |
|
| 156 | + $absolutePath = $absolute ? $path : CACHE_DIR.DIRECTORY_SEPARATOR.$path; |
|
| 157 | 157 | $this->saveTextToFile($data, $absolutePath); |
| 158 | 158 | } |
| 159 | 159 | |
@@ -170,12 +170,12 @@ discard block |
||
| 170 | 170 | public function readFromCache($path, $expires = 300, $function = null, $transform = Cache::TEXT, $ignoreExpiration = false) |
| 171 | 171 | { |
| 172 | 172 | $data = null; |
| 173 | - Inspector::stats('[Cache] Reading data from cache: ' . json_encode(['path' => $path]), Inspector::SCOPE_DEBUG); |
|
| 174 | - if (file_exists(CACHE_DIR . DIRECTORY_SEPARATOR . $path)) { |
|
| 173 | + Inspector::stats('[Cache] Reading data from cache: '.json_encode(['path' => $path]), Inspector::SCOPE_DEBUG); |
|
| 174 | + if (file_exists(CACHE_DIR.DIRECTORY_SEPARATOR.$path)) { |
|
| 175 | 175 | if (is_callable($function) && $this->hasExpiredCache($path, $expires) && !$ignoreExpiration) { |
| 176 | 176 | $data = $function(); |
| 177 | 177 | $this->storeData($path, $data, $transform); |
| 178 | - } else { |
|
| 178 | + }else { |
|
| 179 | 179 | $data = $this->getDataFromFile($path, $transform); |
| 180 | 180 | } |
| 181 | 181 | } |
@@ -221,7 +221,7 @@ discard block |
||
| 221 | 221 | $query[Api::HEADER_API_LANG] = Request::header(Api::HEADER_API_LANG, 'es'); |
| 222 | 222 | $filename = FileHelper::generateHashFilename($action['http'], $action['slug'], $query); |
| 223 | 223 | $hashPath = FileHelper::generateCachePath($action, $query); |
| 224 | - Inspector::stats('[Cache] Cache file calculated: ' . json_encode(['file' => $filename, 'hash' => $hashPath]), Inspector::SCOPE_DEBUG); |
|
| 224 | + Inspector::stats('[Cache] Cache file calculated: '.json_encode(['file' => $filename, 'hash' => $hashPath]), Inspector::SCOPE_DEBUG); |
|
| 225 | 225 | Logger::log('Cache file calculated', LOG_DEBUG, ['file' => $filename, 'hash' => $hashPath]); |
| 226 | 226 | } |
| 227 | 227 | return [$hashPath, $filename]; |
@@ -233,9 +233,9 @@ discard block |
||
| 233 | 233 | Inspector::stats('[Cache] Flushing cache', Inspector::SCOPE_DEBUG); |
| 234 | 234 | $action = Security::getInstance()->getSessionKey(self::CACHE_SESSION_VAR); |
| 235 | 235 | if (is_array($action)) { |
| 236 | - $hashPath = FileHelper::generateCachePath($action, $action['params']) . '..' . DIRECTORY_SEPARATOR . ' .. ' . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR; |
|
| 236 | + $hashPath = FileHelper::generateCachePath($action, $action['params']).'..'.DIRECTORY_SEPARATOR.' .. '.DIRECTORY_SEPARATOR.'..'.DIRECTORY_SEPARATOR; |
|
| 237 | 237 | if (!file_exists($hashPath)) { |
| 238 | - $hashPath = CACHE_DIR . DIRECTORY_SEPARATOR . $hashPath; |
|
| 238 | + $hashPath = CACHE_DIR.DIRECTORY_SEPARATOR.$hashPath; |
|
| 239 | 239 | } |
| 240 | 240 | FileHelper::deleteDir($hashPath); |
| 241 | 241 | } |