@@ -22,7 +22,7 @@ discard block |
||
22 | 22 | */ |
23 | 23 | public function __construct() |
24 | 24 | { |
25 | - Logger::log(get_class($this) . ' constructor invoked'); |
|
25 | + Logger::log(get_class($this).' constructor invoked'); |
|
26 | 26 | $this->init(); |
27 | 27 | } |
28 | 28 | |
@@ -80,14 +80,14 @@ discard block |
||
80 | 80 | $calledClass = static::class; |
81 | 81 | try { |
82 | 82 | $instance = InjectorHelper::constructInyectableInstance($variable, $singleton, $classNameSpace, $calledClass); |
83 | - $setter = 'set' . ucfirst($variable); |
|
83 | + $setter = 'set'.ucfirst($variable); |
|
84 | 84 | if (method_exists($calledClass, $setter)) { |
85 | 85 | $this->$setter($instance); |
86 | - } else { |
|
86 | + }else { |
|
87 | 87 | $this->$variable = $instance; |
88 | 88 | } |
89 | - } catch (\Exception $e) { |
|
90 | - Logger::log($e->getMessage() . ': ' . $e->getFile() . ' [' . $e->getLine() . ']', LOG_ERR); |
|
89 | + }catch (\Exception $e) { |
|
90 | + Logger::log($e->getMessage().': '.$e->getFile().' ['.$e->getLine().']', LOG_ERR); |
|
91 | 91 | throw $e; |
92 | 92 | } |
93 | 93 | return $this; |
@@ -102,7 +102,7 @@ discard block |
||
102 | 102 | { |
103 | 103 | if (!$this->isLoaded()) { |
104 | 104 | $filename = sha1(get_class($this)); |
105 | - $cacheFilename = 'reflections' . DIRECTORY_SEPARATOR . substr($filename, 0, 2) . DIRECTORY_SEPARATOR . substr($filename, 2, 2) . DIRECTORY_SEPARATOR . $filename . ".json"; |
|
105 | + $cacheFilename = 'reflections'.DIRECTORY_SEPARATOR.substr($filename, 0, 2).DIRECTORY_SEPARATOR.substr($filename, 2, 2).DIRECTORY_SEPARATOR.$filename.".json"; |
|
106 | 106 | /** @var \PSFS\base\Cache $cacheService */ |
107 | 107 | $cacheService = Cache::getInstance(); |
108 | 108 | /** @var \PSFS\base\config\Config $configService */ |
@@ -120,8 +120,8 @@ discard block |
||
120 | 120 | } |
121 | 121 | } |
122 | 122 | $this->setLoaded(); |
123 | - } else { |
|
124 | - Logger::log(get_class($this) . ' already loaded', LOG_INFO); |
|
123 | + }else { |
|
124 | + Logger::log(get_class($this).' already loaded', LOG_INFO); |
|
125 | 125 | } |
126 | 126 | } |
127 | 127 | } |
@@ -73,7 +73,7 @@ discard block |
||
73 | 73 | session_start(); |
74 | 74 | } |
75 | 75 | // Fix for phpunits |
76 | - if(!isset($_SESSION)) { |
|
76 | + if (!isset($_SESSION)) { |
|
77 | 77 | $_SESSION = []; |
78 | 78 | } |
79 | 79 | } |
@@ -127,11 +127,11 @@ discard block |
||
127 | 127 | public static function save($user) |
128 | 128 | { |
129 | 129 | $saved = true; |
130 | - $admins = Cache::getInstance()->getDataFromFile(CONFIG_DIR . DIRECTORY_SEPARATOR . 'admins.json', Cache::JSONGZ, true) ?: []; |
|
131 | - $admins[$user['username']]['hash'] = sha1($user['username'] . $user['password']); |
|
130 | + $admins = Cache::getInstance()->getDataFromFile(CONFIG_DIR.DIRECTORY_SEPARATOR.'admins.json', Cache::JSONGZ, true) ?: []; |
|
131 | + $admins[$user['username']]['hash'] = sha1($user['username'].$user['password']); |
|
132 | 132 | $admins[$user['username']]['profile'] = $user['profile']; |
133 | 133 | |
134 | - Cache::getInstance()->storeData(CONFIG_DIR . DIRECTORY_SEPARATOR . 'admins.json', $admins, Cache::JSONGZ, true); |
|
134 | + Cache::getInstance()->storeData(CONFIG_DIR.DIRECTORY_SEPARATOR.'admins.json', $admins, Cache::JSONGZ, true); |
|
135 | 135 | return $saved; |
136 | 136 | } |
137 | 137 | |
@@ -174,7 +174,7 @@ discard block |
||
174 | 174 | */ |
175 | 175 | public function getAdmins() |
176 | 176 | { |
177 | - return Cache::getInstance()->getDataFromFile(CONFIG_DIR . DIRECTORY_SEPARATOR . 'admins.json', Cache::JSONGZ, true); |
|
177 | + return Cache::getInstance()->getDataFromFile(CONFIG_DIR.DIRECTORY_SEPARATOR.'admins.json', Cache::JSONGZ, true); |
|
178 | 178 | } |
179 | 179 | |
180 | 180 | /** |
@@ -199,9 +199,9 @@ discard block |
||
199 | 199 | } |
200 | 200 | if (!empty($user) && !empty($admins[$user])) { |
201 | 201 | $auth = $admins[$user]['hash']; |
202 | - $this->authorized = ($auth === sha1($user . $pass)); |
|
202 | + $this->authorized = ($auth === sha1($user.$pass)); |
|
203 | 203 | if ($this->authorized) { |
204 | - $this->updateAdmin($user , $admins[$user]['profile']); |
|
204 | + $this->updateAdmin($user, $admins[$user]['profile']); |
|
205 | 205 | ResponseHelper::setCookieHeaders([ |
206 | 206 | [ |
207 | 207 | 'name' => $this->getHash(), |
@@ -212,7 +212,7 @@ discard block |
||
212 | 212 | ]); |
213 | 213 | $this->setSessionKey(self::LOGGED_USER_TOKEN, base64_encode("{$user}:{$pass}")); |
214 | 214 | } |
215 | - } else { |
|
215 | + }else { |
|
216 | 216 | $this->admin = null; |
217 | 217 | $this->setSessionKey(self::ADMIN_ID_TOKEN, null); |
218 | 218 | } |
@@ -17,11 +17,11 @@ discard block |
||
17 | 17 | public static function checkApiActions($namespace, $domain, $api) { |
18 | 18 | $actions = []; |
19 | 19 | $reflector = new \ReflectionClass($namespace); |
20 | - if(null !== $reflector) { |
|
21 | - foreach($reflector->getMethods(\ReflectionMethod::IS_PUBLIC) as $apiAction) { |
|
20 | + if (null !== $reflector) { |
|
21 | + foreach ($reflector->getMethods(\ReflectionMethod::IS_PUBLIC) as $apiAction) { |
|
22 | 22 | $docComments = $apiAction->getDocComment(); |
23 | 23 | $action = self::extractAction($docComments); |
24 | - if(null !== $action) { |
|
24 | + if (null !== $action) { |
|
25 | 25 | list($route, $info) = RouterHelper::extractRouteInfo($apiAction, $api, $domain); |
26 | 26 | list($method, $cleanRoute) = RouterHelper::extractHttpRoute($route); |
27 | 27 | $formAction = new FormAction(); |
@@ -44,7 +44,7 @@ discard block |
||
44 | 44 | { |
45 | 45 | $action = null; |
46 | 46 | if (false !== preg_match('/@action\s+([^\s]+)/', $doc, $matches)) { |
47 | - if(count($matches) > 1) { |
|
47 | + if (count($matches) > 1) { |
|
48 | 48 | list(, $action) = $matches; |
49 | 49 | } |
50 | 50 | } |
@@ -6,20 +6,20 @@ discard block |
||
6 | 6 | |
7 | 7 | defined('SOURCE_DIR') or define('SOURCE_DIR', __DIR__); |
8 | 8 | if (preg_match('/vendor/', SOURCE_DIR)) { |
9 | - defined('BASE_DIR') or define('BASE_DIR', SOURCE_DIR . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . '..'); |
|
10 | - defined('CORE_DIR') or define('CORE_DIR', BASE_DIR . DIRECTORY_SEPARATOR . 'src'); |
|
11 | -} else { |
|
12 | - defined('BASE_DIR') or define('BASE_DIR', SOURCE_DIR . DIRECTORY_SEPARATOR . '..'); |
|
13 | - defined('CORE_DIR') or define('CORE_DIR', BASE_DIR . DIRECTORY_SEPARATOR . 'modules'); |
|
9 | + defined('BASE_DIR') or define('BASE_DIR', SOURCE_DIR.DIRECTORY_SEPARATOR.'..'.DIRECTORY_SEPARATOR.'..'.DIRECTORY_SEPARATOR.'..'.DIRECTORY_SEPARATOR.'..'); |
|
10 | + defined('CORE_DIR') or define('CORE_DIR', BASE_DIR.DIRECTORY_SEPARATOR.'src'); |
|
11 | +}else { |
|
12 | + defined('BASE_DIR') or define('BASE_DIR', SOURCE_DIR.DIRECTORY_SEPARATOR.'..'); |
|
13 | + defined('CORE_DIR') or define('CORE_DIR', BASE_DIR.DIRECTORY_SEPARATOR.'modules'); |
|
14 | 14 | } |
15 | -defined('VENDOR_DIR') or define('VENDOR_DIR', BASE_DIR . DIRECTORY_SEPARATOR . 'vendor'); |
|
16 | -defined('LOG_DIR') or define('LOG_DIR', BASE_DIR . DIRECTORY_SEPARATOR . 'logs'); |
|
17 | -defined('CACHE_DIR') or define('CACHE_DIR', BASE_DIR . DIRECTORY_SEPARATOR . 'cache'); |
|
18 | -defined('CONFIG_DIR') or define('CONFIG_DIR', BASE_DIR . DIRECTORY_SEPARATOR . 'config'); |
|
19 | -defined('WEB_DIR') or define('WEB_DIR', BASE_DIR . DIRECTORY_SEPARATOR . 'html'); |
|
20 | -defined('LOCALE_DIR') or define('LOCALE_DIR', BASE_DIR . DIRECTORY_SEPARATOR . 'locale'); |
|
15 | +defined('VENDOR_DIR') or define('VENDOR_DIR', BASE_DIR.DIRECTORY_SEPARATOR.'vendor'); |
|
16 | +defined('LOG_DIR') or define('LOG_DIR', BASE_DIR.DIRECTORY_SEPARATOR.'logs'); |
|
17 | +defined('CACHE_DIR') or define('CACHE_DIR', BASE_DIR.DIRECTORY_SEPARATOR.'cache'); |
|
18 | +defined('CONFIG_DIR') or define('CONFIG_DIR', BASE_DIR.DIRECTORY_SEPARATOR.'config'); |
|
19 | +defined('WEB_DIR') or define('WEB_DIR', BASE_DIR.DIRECTORY_SEPARATOR.'html'); |
|
20 | +defined('LOCALE_DIR') or define('LOCALE_DIR', BASE_DIR.DIRECTORY_SEPARATOR.'locale'); |
|
21 | 21 | |
22 | -if(!class_exists(bootstrap::class)) { |
|
22 | +if (!class_exists(bootstrap::class)) { |
|
23 | 23 | /** |
24 | 24 | * Class Bootstrap |
25 | 25 | * @package PSFS |
@@ -27,9 +27,9 @@ discard block |
||
27 | 27 | class bootstrap { |
28 | 28 | protected static $loaded = false; |
29 | 29 | public static function load() { |
30 | - if(!self::$loaded) { |
|
30 | + if (!self::$loaded) { |
|
31 | 31 | defined('PSFS_BOOTSTRAP_LOADED') or define('PSFS_BOOTSTRAP_LOADED', true); |
32 | - if(class_exists("\\PSFS\\base\\Logger")) \PSFS\base\Logger::log('Bootstrap initialized', LOG_INFO); |
|
32 | + if (class_exists("\\PSFS\\base\\Logger")) \PSFS\base\Logger::log('Bootstrap initialized', LOG_INFO); |
|
33 | 33 | self::$loaded = true; |
34 | 34 | } |
35 | 35 | } |
@@ -29,7 +29,9 @@ |
||
29 | 29 | public static function load() { |
30 | 30 | if(!self::$loaded) { |
31 | 31 | defined('PSFS_BOOTSTRAP_LOADED') or define('PSFS_BOOTSTRAP_LOADED', true); |
32 | - if(class_exists("\\PSFS\\base\\Logger")) \PSFS\base\Logger::log('Bootstrap initialized', LOG_INFO); |
|
32 | + if(class_exists("\\PSFS\\base\\Logger")) { |
|
33 | + \PSFS\base\Logger::log('Bootstrap initialized', LOG_INFO); |
|
34 | + } |
|
33 | 35 | self::$loaded = true; |
34 | 36 | } |
35 | 37 | } |
@@ -65,21 +65,21 @@ discard block |
||
65 | 65 | if (count($pks) == 1) { |
66 | 66 | $pks = array_keys($pks); |
67 | 67 | return [ |
68 | - $tableMap::TABLE_NAME . '.' . $pks[0] => Api::API_MODEL_KEY_FIELD |
|
68 | + $tableMap::TABLE_NAME.'.'.$pks[0] => Api::API_MODEL_KEY_FIELD |
|
69 | 69 | ]; |
70 | 70 | } elseif (count($pks) > 1) { |
71 | 71 | $apiPks = []; |
72 | 72 | $principal = ''; |
73 | 73 | $sep = 'CONCAT('; |
74 | 74 | foreach ($pks as $pk) { |
75 | - $apiPks[$tableMap::TABLE_NAME . '.' . $pk->getName()] = $pk->getPhpName(); |
|
76 | - $principal .= $sep . $tableMap::TABLE_NAME . '.' . $pk->getName(); |
|
77 | - $sep = ', "' . Api::API_PK_SEPARATOR . '", '; |
|
75 | + $apiPks[$tableMap::TABLE_NAME.'.'.$pk->getName()] = $pk->getPhpName(); |
|
76 | + $principal .= $sep.$tableMap::TABLE_NAME.'.'.$pk->getName(); |
|
77 | + $sep = ', "'.Api::API_PK_SEPARATOR.'", '; |
|
78 | 78 | } |
79 | 79 | $principal .= ')'; |
80 | 80 | $apiPks[$principal] = Api::API_MODEL_KEY_FIELD; |
81 | 81 | return $apiPks; |
82 | - } else { |
|
82 | + }else { |
|
83 | 83 | throw new ApiException(_('El modelo de la API no está debidamente mapeado, no hay Primary Key o es compuesta')); |
84 | 84 | } |
85 | 85 | } |
@@ -102,10 +102,10 @@ discard block |
||
102 | 102 | $pks = ''; |
103 | 103 | $sep = ''; |
104 | 104 | foreach ($tableMap->getPrimaryKeys() as $pk) { |
105 | - $pks .= $sep . $pk->getFullyQualifiedName(); |
|
105 | + $pks .= $sep.$pk->getFullyQualifiedName(); |
|
106 | 106 | $sep = ', "|", '; |
107 | 107 | } |
108 | - $this->extraColumns['CONCAT("' . $tableMap->getPhpName() . ' #", ' . $pks . ')'] = Api::API_LIST_NAME_FIELD; |
|
108 | + $this->extraColumns['CONCAT("'.$tableMap->getPhpName().' #", '.$pks.')'] = Api::API_LIST_NAME_FIELD; |
|
109 | 109 | } |
110 | 110 | |
111 | 111 | /** |
@@ -127,7 +127,7 @@ discard block |
||
127 | 127 | } |
128 | 128 | if (null !== $column) { |
129 | 129 | $this->extraColumns[$column->getFullyQualifiedName()] = Api::API_LIST_NAME_FIELD; |
130 | - } else { |
|
130 | + }else { |
|
131 | 131 | $this->addClassListName($tableMap); |
132 | 132 | } |
133 | 133 | } |
@@ -146,15 +146,15 @@ discard block |
||
146 | 146 | $this->addPkToList(); |
147 | 147 | } |
148 | 148 | if (!empty($this->extraColumns)) { |
149 | - if(Config::getParam('api.extrafields.compat', true)) { |
|
149 | + if (Config::getParam('api.extrafields.compat', true)) { |
|
150 | 150 | $fields = array_values($this->extraColumns); |
151 | - } else { |
|
151 | + }else { |
|
152 | 152 | $returnFields = Request::getInstance()->getQuery(Api::API_FIELDS_RESULT_FIELD); |
153 | 153 | $fields = explode(',', $returnFields ?: ''); |
154 | 154 | $fields[] = self::API_MODEL_KEY_FIELD; |
155 | 155 | } |
156 | 156 | foreach ($this->extraColumns as $expression => $columnName) { |
157 | - if(empty($fields) || in_array($columnName, $fields)) { |
|
157 | + if (empty($fields) || in_array($columnName, $fields)) { |
|
158 | 158 | $query->withColumn($expression, $columnName); |
159 | 159 | } |
160 | 160 | } |
@@ -186,17 +186,17 @@ discard block |
||
186 | 186 | { |
187 | 187 | $this->extractApiLang(); |
188 | 188 | $model = $this->getModelNamespace(); |
189 | - $modelI18n = $model . 'I18n'; |
|
189 | + $modelI18n = $model.'I18n'; |
|
190 | 190 | if (method_exists($query, 'useI18nQuery')) { |
191 | 191 | $query->useI18nQuery($this->lang); |
192 | - $modelI18nTableMapClass = str_replace('\\Models\\', '\\Models\\Map\\', $modelI18n) . 'TableMap'; |
|
192 | + $modelI18nTableMapClass = str_replace('\\Models\\', '\\Models\\Map\\', $modelI18n).'TableMap'; |
|
193 | 193 | /** @var TableMap $modelI18nTableMap */ |
194 | 194 | $modelI18nTableMap = $modelI18nTableMapClass::getTableMap(); |
195 | - foreach($modelI18nTableMap->getColumns() as $columnMap) { |
|
196 | - if(!$columnMap->isPrimaryKey()) { |
|
197 | - $query->withColumn($modelI18nTableMapClass::TABLE_NAME . '.' . $columnMap->getName(), $columnMap->getPhpName()); |
|
198 | - } elseif(!$columnMap->isForeignKey()) { |
|
199 | - $query->withColumn('IFNULL(' . $modelI18nTableMapClass::TABLE_NAME . '.' . $columnMap->getName() . ', "'.$this->lang.'")', $columnMap->getPhpName()); |
|
195 | + foreach ($modelI18nTableMap->getColumns() as $columnMap) { |
|
196 | + if (!$columnMap->isPrimaryKey()) { |
|
197 | + $query->withColumn($modelI18nTableMapClass::TABLE_NAME.'.'.$columnMap->getName(), $columnMap->getPhpName()); |
|
198 | + } elseif (!$columnMap->isForeignKey()) { |
|
199 | + $query->withColumn('IFNULL('.$modelI18nTableMapClass::TABLE_NAME.'.'.$columnMap->getName().', "'.$this->lang.'")', $columnMap->getPhpName()); |
|
200 | 200 | } |
201 | 201 | } |
202 | 202 | } |
@@ -210,20 +210,20 @@ discard block |
||
210 | 210 | $model->fromArray($data); |
211 | 211 | $tableMap = $this->getTableMap(); |
212 | 212 | try { |
213 | - if($tableMap->hasRelation($tableMap->getPhpName() . 'I18n')) |
|
213 | + if ($tableMap->hasRelation($tableMap->getPhpName().'I18n')) |
|
214 | 214 | { |
215 | - $relateI18n = $tableMap->getRelation($tableMap->getPhpName() . 'I18n'); |
|
215 | + $relateI18n = $tableMap->getRelation($tableMap->getPhpName().'I18n'); |
|
216 | 216 | $i18NTableMap = $relateI18n->getLocalTable(); |
217 | - foreach($i18NTableMap->getColumns() as $columnMap) { |
|
218 | - $method = 'set' . $columnMap->getPhpName(); |
|
219 | - if(!($columnMap->isPrimaryKey() && $columnMap->isForeignKey()) |
|
217 | + foreach ($i18NTableMap->getColumns() as $columnMap) { |
|
218 | + $method = 'set'.$columnMap->getPhpName(); |
|
219 | + if (!($columnMap->isPrimaryKey() && $columnMap->isForeignKey()) |
|
220 | 220 | &&array_key_exists($columnMap->getPhpName(), $data) |
221 | 221 | && method_exists($model, $method)) { |
222 | 222 | $model->$method($data[$columnMap->getPhpName()]); |
223 | 223 | } |
224 | 224 | } |
225 | 225 | } |
226 | - } catch(\Exception $e) { |
|
226 | + }catch (\Exception $e) { |
|
227 | 227 | Logger::log($e->getMessage(), LOG_DEBUG); |
228 | 228 | } |
229 | 229 | } |
@@ -21,7 +21,7 @@ |
||
21 | 21 | |
22 | 22 | /** |
23 | 23 | * @param string $default |
24 | - * @return array|mixed|string |
|
24 | + * @return string |
|
25 | 25 | */ |
26 | 26 | public static function extractLocale($default = 'es_ES') |
27 | 27 | { |
@@ -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; $i < count($BrowserLocales); $i++) { |
34 | 34 | list($BrowserLocales[$i]) = explode(";", $BrowserLocales[$i]); //trick for "en;q=0.8" |
@@ -40,15 +40,15 @@ discard block |
||
40 | 40 | if (false !== strpos($locale, '_')) { |
41 | 41 | $locale = explode('_', $locale); |
42 | 42 | if ($locale[0] == 'en') { |
43 | - $locale = $locale[0] . '_GB'; |
|
44 | - } else { |
|
45 | - $locale = $locale[0] . '_' . strtoupper($locale[1]); |
|
43 | + $locale = $locale[0].'_GB'; |
|
44 | + }else { |
|
45 | + $locale = $locale[0].'_'.strtoupper($locale[1]); |
|
46 | 46 | } |
47 | - } else { |
|
47 | + }else { |
|
48 | 48 | if (strtolower($locale) === 'en') { |
49 | 49 | $locale = 'en_GB'; |
50 | - } else { |
|
51 | - $locale = $locale . '_' . strtoupper($locale); |
|
50 | + }else { |
|
51 | + $locale = $locale.'_'.strtoupper($locale); |
|
52 | 52 | } |
53 | 53 | } |
54 | 54 | $default_locales = explode(',', Config::getParam('i18n.locales', '')); |
@@ -70,7 +70,7 @@ discard block |
||
70 | 70 | $translations = array(); |
71 | 71 | if (file_exists($absoluteTranslationFileName)) { |
72 | 72 | @include($absoluteTranslationFileName); |
73 | - } else { |
|
73 | + }else { |
|
74 | 74 | Cache::getInstance()->storeData($absoluteTranslationFileName, "<?php \$translations = array();\n", Cache::TEXT, TRUE); |
75 | 75 | } |
76 | 76 | |
@@ -85,13 +85,13 @@ discard block |
||
85 | 85 | public static function setLocale($default = 'es_ES') |
86 | 86 | { |
87 | 87 | $locale = self::extractLocale($default); |
88 | - Logger::log('Set locale to project [' . $locale . ']'); |
|
88 | + Logger::log('Set locale to project ['.$locale.']'); |
|
89 | 89 | // Load translations |
90 | - putenv("LC_ALL=" . $locale); |
|
90 | + putenv("LC_ALL=".$locale); |
|
91 | 91 | setlocale(LC_ALL, $locale); |
92 | 92 | // Load the locale path |
93 | - $locale_path = BASE_DIR . DIRECTORY_SEPARATOR . 'locale'; |
|
94 | - Logger::log('Set locale dir ' . $locale_path); |
|
93 | + $locale_path = BASE_DIR.DIRECTORY_SEPARATOR.'locale'; |
|
94 | + Logger::log('Set locale dir '.$locale_path); |
|
95 | 95 | GeneratorHelper::createDir($locale_path); |
96 | 96 | bindtextdomain('translations', $locale_path); |
97 | 97 | textdomain('translations'); |
@@ -126,9 +126,9 @@ discard block |
||
126 | 126 | */ |
127 | 127 | public static function checkI18Class($namespace) { |
128 | 128 | $isI18n = false; |
129 | - if(preg_match('/I18n$/i', $namespace)) { |
|
129 | + if (preg_match('/I18n$/i', $namespace)) { |
|
130 | 130 | $parentClass = preg_replace('/I18n$/i', '', $namespace); |
131 | - if(Router::exists($parentClass)) { |
|
131 | + if (Router::exists($parentClass)) { |
|
132 | 132 | $isI18n = true; |
133 | 133 | } |
134 | 134 | } |
@@ -27,22 +27,22 @@ 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) self::dropInstance(); |
|
30 | + if ($force_reload) self::dropInstance(); |
|
31 | 31 | self::$locale = I18nHelper::extractLocale(Security::getInstance()->getSessionKey(I18nHelper::PSFS_SESSION_LANGUAGE_KEY)); |
32 | 32 | self::$generate = (boolean)Config::getParam('i18n.autogenerate', false); |
33 | - if(!$use_base) { |
|
33 | + if (!$use_base) { |
|
34 | 34 | $custom_key = $custom_key ?: Security::getInstance()->getSessionKey(self::CUSTOM_LOCALE_SESSION_KEY); |
35 | 35 | } |
36 | - if(null !== $custom_key) { |
|
37 | - Logger::log('[' . self::class . '] Custom key detected: ' . $custom_key, LOG_INFO); |
|
38 | - self::$filename = implode(DIRECTORY_SEPARATOR, [LOCALE_DIR, 'custom', $custom_key, self::$locale . '.json']); |
|
39 | - } else { |
|
40 | - self::$filename = implode(DIRECTORY_SEPARATOR, [LOCALE_DIR, 'custom', self::$locale . '.json']); |
|
36 | + if (null !== $custom_key) { |
|
37 | + Logger::log('['.self::class.'] Custom key detected: '.$custom_key, LOG_INFO); |
|
38 | + self::$filename = implode(DIRECTORY_SEPARATOR, [LOCALE_DIR, 'custom', $custom_key, self::$locale.'.json']); |
|
39 | + }else { |
|
40 | + self::$filename = implode(DIRECTORY_SEPARATOR, [LOCALE_DIR, 'custom', self::$locale.'.json']); |
|
41 | 41 | } |
42 | - if(file_exists(self::$filename)) { |
|
43 | - Logger::log('[' . self::class . '] Custom locale detected: ' . $custom_key . ' [' . self::$locale . ']', LOG_INFO); |
|
42 | + if (file_exists(self::$filename)) { |
|
43 | + Logger::log('['.self::class.'] Custom locale detected: '.$custom_key.' ['.self::$locale.']', LOG_INFO); |
|
44 | 44 | self::$translations = json_decode(file_get_contents(self::$filename), true); |
45 | - } elseif(null !== $custom_key) { |
|
45 | + } elseif (null !== $custom_key) { |
|
46 | 46 | self::checkLoad(null, $force_reload, true); |
47 | 47 | } |
48 | 48 | } |
@@ -83,12 +83,12 @@ discard block |
||
83 | 83 | */ |
84 | 84 | public static function _($message, $custom_key = null, $force_reload = false) { |
85 | 85 | self::checkLoad($custom_key, $force_reload); |
86 | - if(array_key_exists($message, self::$translations)) { |
|
87 | - $translation = self::$translations[$message]; |
|
88 | - } else { |
|
86 | + if (array_key_exists($message, self::$translations)) { |
|
87 | + $translation = self::$translations[$message]; |
|
88 | + }else { |
|
89 | 89 | $translation = gettext($message); |
90 | 90 | } |
91 | - if(self::$generate) { |
|
91 | + if (self::$generate) { |
|
92 | 92 | self::generate($message, $translation); |
93 | 93 | } |
94 | 94 | return $translation; |
@@ -99,7 +99,7 @@ discard block |
||
99 | 99 | * @param string $translation |
100 | 100 | */ |
101 | 101 | protected static function generate($message, $translation) { |
102 | - if(!array_key_exists($message, self::$translations)) { |
|
102 | + if (!array_key_exists($message, self::$translations)) { |
|
103 | 103 | self::$translations[$message] = $translation; |
104 | 104 | } |
105 | 105 | file_put_contents(self::$filename, json_encode(array_unique(self::$translations), JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT)); |
@@ -27,7 +27,9 @@ |
||
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) self::dropInstance(); |
|
30 | + if($force_reload) { |
|
31 | + self::dropInstance(); |
|
32 | + } |
|
31 | 33 | self::$locale = I18nHelper::extractLocale(Security::getInstance()->getSessionKey(I18nHelper::PSFS_SESSION_LANGUAGE_KEY)); |
32 | 34 | self::$generate = (boolean)Config::getParam('i18n.autogenerate', false); |
33 | 35 | if(!$use_base) { |
@@ -90,7 +90,7 @@ discard block |
||
90 | 90 | * @param string $msg |
91 | 91 | * @param array $context |
92 | 92 | * |
93 | - * @return bool |
|
93 | + * @return boolean|null |
|
94 | 94 | */ |
95 | 95 | public function debugLog($msg = '', array $context = []) |
96 | 96 | { |
@@ -98,7 +98,7 @@ discard block |
||
98 | 98 | } |
99 | 99 | |
100 | 100 | /** |
101 | - * @param $msg |
|
101 | + * @param string $msg |
|
102 | 102 | * @param array $context |
103 | 103 | * |
104 | 104 | * @return bool |
@@ -109,7 +109,7 @@ discard block |
||
109 | 109 | } |
110 | 110 | |
111 | 111 | /** |
112 | - * @param $msg |
|
112 | + * @param string $msg |
|
113 | 113 | * @param array $context |
114 | 114 | * |
115 | 115 | * @return bool |
@@ -123,7 +123,7 @@ discard block |
||
123 | 123 | } |
124 | 124 | |
125 | 125 | /** |
126 | - * @param $msg |
|
126 | + * @param string $msg |
|
127 | 127 | * @param array $context |
128 | 128 | * @return bool |
129 | 129 | */ |
@@ -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 | /** |
@@ -55,7 +55,7 @@ discard block |
||
55 | 55 | $config = Config::getInstance(); |
56 | 56 | $args = func_get_args(); |
57 | 57 | list($logger, $debug, $path) = $this->setup($config, $args); |
58 | - $this->stream = fopen($path . DIRECTORY_SEPARATOR . date('Ymd') . '.log', 'a+'); |
|
58 | + $this->stream = fopen($path.DIRECTORY_SEPARATOR.date('Ymd').'.log', 'a+'); |
|
59 | 59 | $this->addPushLogger($logger, $debug, $config); |
60 | 60 | $this->log_level = Config::getParam('log.level', 'info'); |
61 | 61 | } |
@@ -116,7 +116,7 @@ discard block |
||
116 | 116 | */ |
117 | 117 | public function criticalLog($msg, array $context = []) |
118 | 118 | { |
119 | - if(Config::getParam('log.slack.hook')) { |
|
119 | + if (Config::getParam('log.slack.hook')) { |
|
120 | 120 | SlackHelper::getInstance()->trace($msg, '', '', $context); |
121 | 121 | } |
122 | 122 | return $this->logger->addCritical($msg, $this->addMinimalContext($context)); |
@@ -212,7 +212,7 @@ discard block |
||
212 | 212 | private function createLoggerPath(Config $config) |
213 | 213 | { |
214 | 214 | $logger = $this->setLoggerName($config); |
215 | - $path = LOG_DIR . DIRECTORY_SEPARATOR . $logger . DIRECTORY_SEPARATOR . date('Y') . DIRECTORY_SEPARATOR . date('m'); |
|
215 | + $path = LOG_DIR.DIRECTORY_SEPARATOR.$logger.DIRECTORY_SEPARATOR.date('Y').DIRECTORY_SEPARATOR.date('m'); |
|
216 | 216 | GeneratorHelper::createDir($path); |
217 | 217 | |
218 | 218 | return $path; |
@@ -225,10 +225,10 @@ discard block |
||
225 | 225 | */ |
226 | 226 | public static function log($msg, $type = LOG_DEBUG, array $context = null) |
227 | 227 | { |
228 | - if(null === $context) { |
|
228 | + if (null === $context) { |
|
229 | 229 | $context = []; |
230 | 230 | } |
231 | - if(Config::getParam('profiling.enable')) { |
|
231 | + if (Config::getParam('profiling.enable')) { |
|
232 | 232 | Inspector::stats($msg); |
233 | 233 | } |
234 | 234 | switch ($type) { |
@@ -279,7 +279,7 @@ discard block |
||
279 | 279 | { |
280 | 280 | $context['uri'] = null !== $_SERVER && array_key_exists('REQUEST_URI', $_SERVER) ? $_SERVER['REQUEST_URI'] : 'Unknow'; |
281 | 281 | $context['method'] = null !== $_SERVER && array_key_exists('REQUEST_METHOD', $_SERVER) ? $_SERVER['REQUEST_METHOD'] : 'Unknow'; |
282 | - if(null !== $_SERVER && array_key_exists('HTTP_X_PSFS_UID', $_SERVER)) { |
|
282 | + if (null !== $_SERVER && array_key_exists('HTTP_X_PSFS_UID', $_SERVER)) { |
|
283 | 283 | $context['uid'] = $_SERVER['HTTP_X_PSFS_UID']; |
284 | 284 | } |
285 | 285 | return $context; |
@@ -3,8 +3,6 @@ |
||
3 | 3 | |
4 | 4 | use PSFS\base\config\Config; |
5 | 5 | use PSFS\base\Logger; |
6 | -use PSFS\base\Request; |
|
7 | -use PSFS\base\Router; |
|
8 | 6 | use PSFS\base\types\helpers\SlackHelper; |
9 | 7 | |
10 | 8 | /** |
@@ -38,7 +38,7 @@ discard block |
||
38 | 38 | $use /= 1024; |
39 | 39 | break; |
40 | 40 | case "MBytes": |
41 | - $use /= (1024 * 1024); |
|
41 | + $use /= (1024*1024); |
|
42 | 42 | break; |
43 | 43 | case "Bytes": |
44 | 44 | default: |
@@ -62,34 +62,34 @@ discard block |
||
62 | 62 | protected function bindWarningAsExceptions() |
63 | 63 | { |
64 | 64 | Logger::log('Added handlers for errors'); |
65 | - if(Config::getParam('debug')) { |
|
65 | + if (Config::getParam('debug')) { |
|
66 | 66 | Logger::log('Setting error_reporting as E_ALL'); |
67 | 67 | ini_set('error_reporting', E_ALL); |
68 | 68 | ini_set('display_errors', 1); |
69 | 69 | } |
70 | 70 | //Warning & Notice handler |
71 | - set_error_handler(function ($errno, $errstr, $errfile, $errline) { |
|
71 | + set_error_handler(function($errno, $errstr, $errfile, $errline) { |
|
72 | 72 | Logger::log($errstr, LOG_CRIT, ['file' => $errfile, 'line' => $errline, 'errno' => $errno]); |
73 | 73 | return true; |
74 | 74 | }, E_ALL | E_STRICT | E_DEPRECATED | E_USER_DEPRECATED | E_ERROR | E_CORE_ERROR | E_COMPILE_ERROR); |
75 | 75 | |
76 | - register_shutdown_function(function () { |
|
76 | + register_shutdown_function(function() { |
|
77 | 77 | $error = error_get_last() or json_last_error() or preg_last_error() or \DateTime::getLastErrors(); |
78 | - if( $error !== NULL) { |
|
78 | + if ($error !== NULL) { |
|
79 | 79 | $errno = $error["type"]; |
80 | 80 | $errfile = $error["file"]; |
81 | 81 | $errline = $error["line"]; |
82 | 82 | $errstr = $error["message"]; |
83 | 83 | Logger::log($errstr, LOG_CRIT, ['file' => $errfile, 'line' => $errline, 'errno' => $errno]); |
84 | - if(null !== Config::getParam('log.slack.hook')) { |
|
84 | + if (null !== Config::getParam('log.slack.hook')) { |
|
85 | 85 | SlackHelper::getInstance()->trace($errstr, $errfile, $errline, $error); |
86 | 86 | } |
87 | 87 | } |
88 | 88 | |
89 | - if(self::getTs() > 10 && null !== Config::getParam('log.slack.hook')) { |
|
89 | + if (self::getTs() > 10 && null !== Config::getParam('log.slack.hook')) { |
|
90 | 90 | SlackHelper::getInstance()->trace('Slow service endpoint', '', '', [ |
91 | - 'time' => round(self::getTs(), 3) . ' secs', |
|
92 | - 'memory' => round(self::getMem('MBytes'), 3) . ' Mb', |
|
91 | + 'time' => round(self::getTs(), 3).' secs', |
|
92 | + 'memory' => round(self::getMem('MBytes'), 3).' Mb', |
|
93 | 93 | ]); |
94 | 94 | } |
95 | 95 | return false; |
@@ -104,7 +104,7 @@ discard block |
||
104 | 104 | Logger::log('Initializing stats (mem + ts)'); |
105 | 105 | if (null !== $_SERVER && array_key_exists('REQUEST_TIME_FLOAT', $_SERVER)) { |
106 | 106 | $this->ts = (float)$_SERVER['REQUEST_TIME_FLOAT']; |
107 | - } else { |
|
107 | + }else { |
|
108 | 108 | $this->ts = PSFS_START_TS; |
109 | 109 | } |
110 | 110 | $this->mem = PSFS_START_MEM; |