@@ -74,7 +74,7 @@ discard block |
||
74 | 74 | */ |
75 | 75 | protected function init() |
76 | 76 | { |
77 | - if (file_exists(CONFIG_DIR . DIRECTORY_SEPARATOR . self::CONFIG_FILE)) { |
|
77 | + if (file_exists(CONFIG_DIR.DIRECTORY_SEPARATOR.self::CONFIG_FILE)) { |
|
78 | 78 | $this->loadConfigData(); |
79 | 79 | } |
80 | 80 | return $this; |
@@ -190,10 +190,10 @@ discard block |
||
190 | 190 | $final_data = array_filter($final_data, function($key, $value) { |
191 | 191 | return in_array($key, self::$required, true) || !empty($value); |
192 | 192 | }, ARRAY_FILTER_USE_BOTH); |
193 | - $saved = (false !== file_put_contents(CONFIG_DIR . DIRECTORY_SEPARATOR . self::CONFIG_FILE, json_encode($final_data, JSON_PRETTY_PRINT))); |
|
193 | + $saved = (false !== file_put_contents(CONFIG_DIR.DIRECTORY_SEPARATOR.self::CONFIG_FILE, json_encode($final_data, JSON_PRETTY_PRINT))); |
|
194 | 194 | self::getInstance()->loadConfigData(); |
195 | 195 | $saved = true; |
196 | - } catch (ConfigException $e) { |
|
196 | + }catch (ConfigException $e) { |
|
197 | 197 | Logger::log($e->getMessage(), LOG_ERR); |
198 | 198 | } |
199 | 199 | return $saved; |
@@ -225,7 +225,7 @@ discard block |
||
225 | 225 | */ |
226 | 226 | public function loadConfigData() |
227 | 227 | { |
228 | - $this->config = json_decode(file_get_contents(CONFIG_DIR . DIRECTORY_SEPARATOR . self::CONFIG_FILE), true) ?: []; |
|
228 | + $this->config = json_decode(file_get_contents(CONFIG_DIR.DIRECTORY_SEPARATOR.self::CONFIG_FILE), true) ?: []; |
|
229 | 229 | $this->debug = array_key_exists('debug', $this->config) ? (bool)$this->config['debug'] : FALSE; |
230 | 230 | } |
231 | 231 | |
@@ -246,8 +246,8 @@ discard block |
||
246 | 246 | */ |
247 | 247 | public static function getParam($key, $defaultValue = null, $module = null) |
248 | 248 | { |
249 | - if(null !== $module) { |
|
250 | - return self::getParam(strtolower($module) . '.' . $key, self::getParam($key, $defaultValue)); |
|
249 | + if (null !== $module) { |
|
250 | + return self::getParam(strtolower($module).'.'.$key, self::getParam($key, $defaultValue)); |
|
251 | 251 | } |
252 | 252 | $param = self::getInstance()->get($key); |
253 | 253 | return (null !== $param) ? $param : $defaultValue; |
@@ -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 | } |
@@ -43,7 +43,7 @@ |
||
43 | 43 | $this->success = $result; |
44 | 44 | $this->total = $total ?: (is_array($data) ? count($data) : 0); |
45 | 45 | $this->pages = $pages; |
46 | - if(null !== $message) { |
|
46 | + if (null !== $message) { |
|
47 | 47 | $this->message = $message; |
48 | 48 | } |
49 | 49 | } |
@@ -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; |
@@ -48,14 +48,14 @@ |
||
48 | 48 | /* @var $file SplFileInfo */ |
49 | 49 | foreach ($finder as $file) { |
50 | 50 | $path = $file->getRealPath(); |
51 | - if(!in_array($path, $loaded_files)) { |
|
51 | + if (!in_array($path, $loaded_files)) { |
|
52 | 52 | $loaded_files[] = $path; |
53 | 53 | require_once($path); |
54 | 54 | } |
55 | 55 | } |
56 | 56 | } |
57 | 57 | |
58 | -if(!function_exists('t')) { |
|
58 | +if (!function_exists('t')) { |
|
59 | 59 | function t($message, $key = null, $reload = false) { |
60 | 60 | return CustomTranslateExtension::_($message, $key, $reload); |
61 | 61 | } |
@@ -34,9 +34,10 @@ |
||
34 | 34 | function getallheaders() |
35 | 35 | { |
36 | 36 | $headers = []; |
37 | - foreach ($_SERVER as $h => $v) |
|
38 | - if (preg_match('/HTTP_(.+)/', $h, $hp)) { |
|
37 | + foreach ($_SERVER as $h => $v) { |
|
38 | + if (preg_match('/HTTP_(.+)/', $h, $hp)) { |
|
39 | 39 | $headers[$hp[1]] = $v; |
40 | + } |
|
40 | 41 | } |
41 | 42 | return $headers; |
42 | 43 | } |
@@ -40,7 +40,7 @@ |
||
40 | 40 | */ |
41 | 41 | public static function dropInstance() { |
42 | 42 | $class = static::class; |
43 | - if(isset(self::$instance[$class])) { |
|
43 | + if (isset(self::$instance[$class])) { |
|
44 | 44 | self::$instance[$class] = null; |
45 | 45 | } |
46 | 46 | } |
@@ -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 | - Logger::log('Set locale to project [' . $locale . ']'); |
|
84 | + Logger::log('Set locale to project ['.$locale.']'); |
|
85 | 85 | // Load translations |
86 | - putenv("LC_ALL=" . $locale); |
|
86 | + putenv("LC_ALL=".$locale); |
|
87 | 87 | setlocale(LC_ALL, $locale); |
88 | 88 | // Load the locale path |
89 | - $locale_path = BASE_DIR . DIRECTORY_SEPARATOR . 'locale'; |
|
90 | - Logger::log('Set locale dir ' . $locale_path); |
|
89 | + $locale_path = BASE_DIR.DIRECTORY_SEPARATOR.'locale'; |
|
90 | + Logger::log('Set locale dir '.$locale_path); |
|
91 | 91 | GeneratorHelper::createDir($locale_path); |
92 | 92 | bindtextdomain('translations', $locale_path); |
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; |