@@ -27,24 +27,24 @@ discard block |
||
| 27 | 27 | * @param bool $use_base |
| 28 | 28 | */ |
| 29 | 29 | protected static function checkLoad($custom_key = null, $force_reload = false, $use_base = false) { |
| 30 | - if($force_reload) { |
|
| 30 | + if ($force_reload) { |
|
| 31 | 31 | self::dropInstance(); |
| 32 | 32 | } |
| 33 | 33 | self::$locale = I18nHelper::extractLocale(Security::getInstance()->getSessionKey(I18nHelper::PSFS_SESSION_LANGUAGE_KEY)); |
| 34 | 34 | self::$generate = (boolean)Config::getParam('i18n.autogenerate', false); |
| 35 | - if(!$use_base) { |
|
| 35 | + if (!$use_base) { |
|
| 36 | 36 | $custom_key = $custom_key ?: Security::getInstance()->getSessionKey(self::CUSTOM_LOCALE_SESSION_KEY); |
| 37 | 37 | } |
| 38 | - if(null !== $custom_key) { |
|
| 39 | - Logger::log('[' . self::class . '] Custom key detected: ' . $custom_key, LOG_INFO); |
|
| 40 | - self::$filename = implode(DIRECTORY_SEPARATOR, [LOCALE_DIR, 'custom', $custom_key, self::$locale . '.json']); |
|
| 41 | - } else { |
|
| 42 | - self::$filename = implode(DIRECTORY_SEPARATOR, [LOCALE_DIR, 'custom', self::$locale . '.json']); |
|
| 38 | + if (null !== $custom_key) { |
|
| 39 | + Logger::log('['.self::class.'] Custom key detected: '.$custom_key, LOG_INFO); |
|
| 40 | + self::$filename = implode(DIRECTORY_SEPARATOR, [LOCALE_DIR, 'custom', $custom_key, self::$locale.'.json']); |
|
| 41 | + }else { |
|
| 42 | + self::$filename = implode(DIRECTORY_SEPARATOR, [LOCALE_DIR, 'custom', self::$locale.'.json']); |
|
| 43 | 43 | } |
| 44 | - if(file_exists(self::$filename)) { |
|
| 45 | - Logger::log('[' . self::class . '] Custom locale detected: ' . $custom_key . ' [' . self::$locale . ']', LOG_INFO); |
|
| 44 | + if (file_exists(self::$filename)) { |
|
| 45 | + Logger::log('['.self::class.'] Custom locale detected: '.$custom_key.' ['.self::$locale.']', LOG_INFO); |
|
| 46 | 46 | self::$translations = json_decode(file_get_contents(self::$filename), true); |
| 47 | - } elseif(null !== $custom_key) { |
|
| 47 | + } elseif (null !== $custom_key) { |
|
| 48 | 48 | self::checkLoad(null, $force_reload, true); |
| 49 | 49 | } |
| 50 | 50 | } |
@@ -85,12 +85,12 @@ discard block |
||
| 85 | 85 | */ |
| 86 | 86 | public static function _($message, $custom_key = null, $force_reload = false) { |
| 87 | 87 | self::checkLoad($custom_key, $force_reload); |
| 88 | - if(array_key_exists($message, self::$translations)) { |
|
| 89 | - $translation = self::$translations[$message]; |
|
| 90 | - } else { |
|
| 88 | + if (array_key_exists($message, self::$translations)) { |
|
| 89 | + $translation = self::$translations[$message]; |
|
| 90 | + }else { |
|
| 91 | 91 | $translation = gettext($message); |
| 92 | 92 | } |
| 93 | - if(self::$generate) { |
|
| 93 | + if (self::$generate) { |
|
| 94 | 94 | self::generate($message, $translation); |
| 95 | 95 | } |
| 96 | 96 | return $translation; |
@@ -101,7 +101,7 @@ discard block |
||
| 101 | 101 | * @param string $translation |
| 102 | 102 | */ |
| 103 | 103 | protected static function generate($message, $translation) { |
| 104 | - if(!array_key_exists($message, self::$translations)) { |
|
| 104 | + if (!array_key_exists($message, self::$translations)) { |
|
| 105 | 105 | self::$translations[$message] = $translation; |
| 106 | 106 | } |
| 107 | 107 | file_put_contents(self::$filename, json_encode(array_unique(self::$translations), JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT)); |
@@ -27,10 +27,10 @@ discard block |
||
| 27 | 27 | $label = self::getLabel($property->getDocComment()); |
| 28 | 28 | $values = self::getValues($property->getDocComment()); |
| 29 | 29 | $isArray = (bool)preg_match('/\[\]$/', $instanceType); |
| 30 | - if($isArray) { |
|
| 30 | + if ($isArray) { |
|
| 31 | 31 | $instanceType = str_replace('[]', '', $instanceType); |
| 32 | 32 | } |
| 33 | - if($instanceType === '\\DateTime' || !Router::exists($instanceType)) { |
|
| 33 | + if ($instanceType === '\\DateTime' || !Router::exists($instanceType)) { |
|
| 34 | 34 | list($type, $format) = DocumentorHelper::translateSwaggerFormats($instanceType); |
| 35 | 35 | $variables[$property->getName()] = [ |
| 36 | 36 | 'type' => $type, |
@@ -38,7 +38,7 @@ discard block |
||
| 38 | 38 | 'required' => $isRequired, |
| 39 | 39 | 'description' => $label, |
| 40 | 40 | ]; |
| 41 | - } else { |
|
| 41 | + }else { |
|
| 42 | 42 | $instance = new \ReflectionClass($instanceType); |
| 43 | 43 | $variables[$property->getName()] = [ |
| 44 | 44 | 'is_array' => $isArray, |
@@ -47,7 +47,7 @@ discard block |
||
| 47 | 47 | 'properties' => self::extractVariables($instance), |
| 48 | 48 | ]; |
| 49 | 49 | } |
| 50 | - if(!empty($values)){ |
|
| 50 | + if (!empty($values)) { |
|
| 51 | 51 | $variables[$property->getName()]['enum'] = $values; |
| 52 | 52 | } |
| 53 | 53 | } |
@@ -127,7 +127,7 @@ discard block |
||
| 127 | 127 | // Extract description |
| 128 | 128 | $label = null; |
| 129 | 129 | preg_match('/@label\ (.*)\n/i', $doc, $matches); |
| 130 | - if(count($matches) > 1) { |
|
| 130 | + if (count($matches) > 1) { |
|
| 131 | 131 | $label = t($matches[1]); |
| 132 | 132 | } |
| 133 | 133 | return $label; |
@@ -141,7 +141,7 @@ discard block |
||
| 141 | 141 | // Extract description |
| 142 | 142 | $label = null; |
| 143 | 143 | preg_match('/@values\ (.*)\n/i', $doc, $matches); |
| 144 | - if(count($matches) > 1) { |
|
| 144 | + if (count($matches) > 1) { |
|
| 145 | 145 | $label = t($matches[1]); |
| 146 | 146 | } |
| 147 | 147 | return false !== strpos($label, '|') ? explode('|', $label) : $label; |
@@ -154,7 +154,7 @@ discard block |
||
| 154 | 154 | public static function getDefaultValue($doc) { |
| 155 | 155 | $default = null; |
| 156 | 156 | preg_match('/@default\ (.*)\n/i', $doc, $matches); |
| 157 | - if(count($matches) > 1) { |
|
| 157 | + if (count($matches) > 1) { |
|
| 158 | 158 | $default = $matches[1]; |
| 159 | 159 | } |
| 160 | 160 | return $default; |
@@ -169,13 +169,13 @@ discard block |
||
| 169 | 169 | */ |
| 170 | 170 | public static function constructInyectableInstance($variable, $singleton, $classNameSpace, $calledClass) |
| 171 | 171 | { |
| 172 | - Logger::log('Create inyectable instance for ' . $classNameSpace); |
|
| 172 | + Logger::log('Create inyectable instance for '.$classNameSpace); |
|
| 173 | 173 | $reflector = new \ReflectionClass($calledClass); |
| 174 | 174 | $property = $reflector->getProperty($variable); |
| 175 | 175 | $varInstanceType = (null === $classNameSpace) ? InjectorHelper::extractVarType($property->getDocComment()) : $classNameSpace; |
| 176 | 176 | if (true === $singleton && method_exists($varInstanceType, 'getInstance')) { |
| 177 | 177 | $instance = $varInstanceType::getInstance(); |
| 178 | - } else { |
|
| 178 | + }else { |
|
| 179 | 179 | $instance = new $varInstanceType(); |
| 180 | 180 | } |
| 181 | 181 | return $instance; |
@@ -189,7 +189,7 @@ discard block |
||
| 189 | 189 | public static function getClassProperties($class) |
| 190 | 190 | { |
| 191 | 191 | $properties = []; |
| 192 | - Logger::log('Extracting annotations properties from class ' . $class); |
|
| 192 | + Logger::log('Extracting annotations properties from class '.$class); |
|
| 193 | 193 | $selfReflector = new \ReflectionClass($class); |
| 194 | 194 | if (false !== $selfReflector->getParentClass()) { |
| 195 | 195 | $properties = self::getClassProperties($selfReflector->getParentClass()->getName()); |