@@ -146,7 +146,7 @@ discard block |
||
146 | 146 | |
147 | 147 | /** |
148 | 148 | * Método que guarda en fichero los datos pasados |
149 | - * @param $path |
|
149 | + * @param string $path |
|
150 | 150 | * @param $data |
151 | 151 | * @param int $transform |
152 | 152 | * @param boolean $absolute |
@@ -201,7 +201,7 @@ discard block |
||
201 | 201 | |
202 | 202 | /** |
203 | 203 | * Método estático que revisa si se necesita cachear la respuesta de un servicio o no |
204 | - * @return integer|boolean |
|
204 | + * @return integer |
|
205 | 205 | */ |
206 | 206 | public static function needCache() |
207 | 207 | { |
@@ -50,7 +50,7 @@ discard block |
||
50 | 50 | { |
51 | 51 | GeneratorHelper::createDir(dirname($path)); |
52 | 52 | if (false === FileHelper::writeFile($path, $data)) { |
53 | - throw new ConfigException(_('No se tienen los permisos suficientes para escribir en el fichero ') . $path); |
|
53 | + throw new ConfigException(_('No se tienen los permisos suficientes para escribir en el fichero ').$path); |
|
54 | 54 | } |
55 | 55 | } |
56 | 56 | |
@@ -65,7 +65,7 @@ discard block |
||
65 | 65 | { |
66 | 66 | Logger::log('Gathering data from cache', LOG_DEBUG, ['path' => $path]); |
67 | 67 | $data = null; |
68 | - $absolutePath = ($absolute) ? $path : CACHE_DIR . DIRECTORY_SEPARATOR . $path; |
|
68 | + $absolutePath = ($absolute) ? $path : CACHE_DIR.DIRECTORY_SEPARATOR.$path; |
|
69 | 69 | if (file_exists($absolutePath)) { |
70 | 70 | $data = FileHelper::readFile($absolutePath); |
71 | 71 | } |
@@ -82,7 +82,7 @@ discard block |
||
82 | 82 | private function hasExpiredCache($path, $expires = 300, $absolute = false) |
83 | 83 | { |
84 | 84 | Logger::log('Checking expiration', LOG_DEBUG, ['path' => $path]); |
85 | - $absolutePath = ($absolute) ? $path : CACHE_DIR . DIRECTORY_SEPARATOR . $path; |
|
85 | + $absolutePath = ($absolute) ? $path : CACHE_DIR.DIRECTORY_SEPARATOR.$path; |
|
86 | 86 | $lasModificationDate = filemtime($absolutePath); |
87 | 87 | return ($lasModificationDate + $expires <= time()); |
88 | 88 | } |
@@ -151,7 +151,7 @@ discard block |
||
151 | 151 | { |
152 | 152 | Logger::log('Store data in cache', LOG_DEBUG, ['path' => $path]); |
153 | 153 | $data = Cache::transformData($data, $transform); |
154 | - $absolutePath = ($absolute) ? $path : CACHE_DIR . DIRECTORY_SEPARATOR . $path; |
|
154 | + $absolutePath = ($absolute) ? $path : CACHE_DIR.DIRECTORY_SEPARATOR.$path; |
|
155 | 155 | $this->saveTextToFile($data, $absolutePath); |
156 | 156 | } |
157 | 157 | |
@@ -167,11 +167,11 @@ discard block |
||
167 | 167 | { |
168 | 168 | $data = null; |
169 | 169 | Logger::log('Reading data from cache', LOG_DEBUG, ['path' => $path]); |
170 | - if (file_exists(CACHE_DIR . DIRECTORY_SEPARATOR . $path)) { |
|
170 | + if (file_exists(CACHE_DIR.DIRECTORY_SEPARATOR.$path)) { |
|
171 | 171 | if (is_callable($function) && $this->hasExpiredCache($path, $expires)) { |
172 | 172 | $data = call_user_func($function); |
173 | 173 | $this->storeData($path, $data, $transform, false, $expires); |
174 | - } else { |
|
174 | + }else { |
|
175 | 175 | $data = $this->getDataFromFile($path, $transform); |
176 | 176 | } |
177 | 177 | } |
@@ -228,10 +228,10 @@ discard block |
||
228 | 228 | * Flush cache when save a registry |
229 | 229 | */ |
230 | 230 | public function flushCache() { |
231 | - if(Config::getParam('cache.data.enable', false)) { |
|
231 | + if (Config::getParam('cache.data.enable', false)) { |
|
232 | 232 | Logger::log('Flushing cache', LOG_DEBUG); |
233 | 233 | $action = Security::getInstance()->getSessionKey("__CACHE__"); |
234 | - $hashPath = FileHelper::generateCachePath($action, $action['params']) . '..' . DIRECTORY_SEPARATOR . ' .. ' . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR; |
|
234 | + $hashPath = FileHelper::generateCachePath($action, $action['params']).'..'.DIRECTORY_SEPARATOR.' .. '.DIRECTORY_SEPARATOR.'..'.DIRECTORY_SEPARATOR; |
|
235 | 235 | FileHelper::deleteDir($hashPath); |
236 | 236 | } |
237 | 237 | } |
@@ -121,9 +121,11 @@ |
||
121 | 121 | $cacheService->storeData($cacheFilename, $properties, $cache); |
122 | 122 | } |
123 | 123 | /** @var \ReflectionProperty $property */ |
124 | - if (!empty($properties) && is_array($properties)) foreach ($properties as $property => $class) { |
|
124 | + if (!empty($properties) && is_array($properties)) { |
|
125 | + foreach ($properties as $property => $class) { |
|
125 | 126 | $this->load($property, true, $class); |
126 | 127 | } |
128 | + } |
|
127 | 129 | $this->setLoaded(); |
128 | 130 | } else { |
129 | 131 | Logger::log(get_class($this) . ' already loaded', LOG_INFO); |
@@ -15,7 +15,7 @@ discard block |
||
15 | 15 | |
16 | 16 | public function __construct() |
17 | 17 | { |
18 | - Logger::log(get_class($this) . ' constructor invoked'); |
|
18 | + Logger::log(get_class($this).' constructor invoked'); |
|
19 | 19 | $this->init(); |
20 | 20 | } |
21 | 21 | |
@@ -68,14 +68,14 @@ discard block |
||
68 | 68 | $calledClass = get_called_class(); |
69 | 69 | try { |
70 | 70 | $instance = InjectorHelper::constructInyectableInstance($variable, $singleton, $classNameSpace, $calledClass); |
71 | - $setter = "set" . ucfirst($variable); |
|
71 | + $setter = "set".ucfirst($variable); |
|
72 | 72 | if (method_exists($calledClass, $setter)) { |
73 | 73 | $this->$setter($instance); |
74 | - } else { |
|
74 | + }else { |
|
75 | 75 | $this->$variable = $instance; |
76 | 76 | } |
77 | - } catch (\Exception $e) { |
|
78 | - Logger::log($e->getMessage() . ': ' . $e->getFile() . ' [' . $e->getLine() . ']', LOG_ERR); |
|
77 | + }catch (\Exception $e) { |
|
78 | + Logger::log($e->getMessage().': '.$e->getFile().' ['.$e->getLine().']', LOG_ERR); |
|
79 | 79 | throw $e; |
80 | 80 | } |
81 | 81 | return $this; |
@@ -88,7 +88,7 @@ discard block |
||
88 | 88 | { |
89 | 89 | if (!$this->isLoaded()) { |
90 | 90 | $filename = sha1(get_class($this)); |
91 | - $cacheFilename = "reflections" . DIRECTORY_SEPARATOR . substr($filename, 0, 2) . DIRECTORY_SEPARATOR . substr($filename, 2, 2) . DIRECTORY_SEPARATOR . $filename . ".json"; |
|
91 | + $cacheFilename = "reflections".DIRECTORY_SEPARATOR.substr($filename, 0, 2).DIRECTORY_SEPARATOR.substr($filename, 2, 2).DIRECTORY_SEPARATOR.$filename.".json"; |
|
92 | 92 | /** @var \PSFS\base\Cache $cacheService */ |
93 | 93 | $cacheService = Cache::getInstance(); |
94 | 94 | /** @var \PSFS\base\config\Config $configService */ |
@@ -104,8 +104,8 @@ discard block |
||
104 | 104 | $this->load($property, true, $class); |
105 | 105 | } |
106 | 106 | $this->setLoaded(); |
107 | - } else { |
|
108 | - Logger::log(get_class($this) . ' already loaded', LOG_INFO); |
|
107 | + }else { |
|
108 | + Logger::log(get_class($this).' already loaded', LOG_INFO); |
|
109 | 109 | } |
110 | 110 | } |
111 | 111 | } |
@@ -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; |
@@ -182,10 +182,10 @@ discard block |
||
182 | 182 | $final_data = array_filter($final_data, function($key, $value) { |
183 | 183 | return in_array($key, Config::$required) || !empty($value); |
184 | 184 | }, ARRAY_FILTER_USE_BOTH); |
185 | - $saved = (false !== file_put_contents(CONFIG_DIR . DIRECTORY_SEPARATOR . self::CONFIG_FILE, json_encode($final_data, JSON_PRETTY_PRINT))); |
|
185 | + $saved = (false !== file_put_contents(CONFIG_DIR.DIRECTORY_SEPARATOR.self::CONFIG_FILE, json_encode($final_data, JSON_PRETTY_PRINT))); |
|
186 | 186 | Config::getInstance()->loadConfigData(); |
187 | 187 | $saved = true; |
188 | - } catch (ConfigException $e) { |
|
188 | + }catch (ConfigException $e) { |
|
189 | 189 | Logger::log($e->getMessage(), LOG_ERR); |
190 | 190 | } |
191 | 191 | return $saved; |
@@ -217,7 +217,7 @@ discard block |
||
217 | 217 | */ |
218 | 218 | public function loadConfigData() |
219 | 219 | { |
220 | - $this->config = json_decode(file_get_contents(CONFIG_DIR . DIRECTORY_SEPARATOR . self::CONFIG_FILE), true) ?: []; |
|
220 | + $this->config = json_decode(file_get_contents(CONFIG_DIR.DIRECTORY_SEPARATOR.self::CONFIG_FILE), true) ?: []; |
|
221 | 221 | $this->debug = (array_key_exists('debug', $this->config)) ? (bool)$this->config['debug'] : FALSE; |
222 | 222 | } |
223 | 223 |
@@ -196,7 +196,7 @@ |
||
196 | 196 | /** |
197 | 197 | * Method that returns a config value |
198 | 198 | * @param string $param |
199 | - * @param mixed $defaultValue |
|
199 | + * @param string $defaultValue |
|
200 | 200 | * |
201 | 201 | * @return mixed|null |
202 | 202 | */ |
@@ -17,11 +17,11 @@ |
||
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(); |
@@ -31,9 +31,10 @@ |
||
31 | 31 | function getallheaders() |
32 | 32 | { |
33 | 33 | $headers = array(); |
34 | - foreach ($_SERVER as $h => $v) |
|
35 | - if (preg_match('/HTTP_(.+)/', $h, $hp)) |
|
34 | + foreach ($_SERVER as $h => $v) { |
|
35 | + if (preg_match('/HTTP_(.+)/', $h, $hp)) |
|
36 | 36 | $headers[$hp[1]] = $v; |
37 | + } |
|
37 | 38 | return $headers; |
38 | 39 | } |
39 | 40 | } |
@@ -46,7 +46,7 @@ |
||
46 | 46 | /* @var $file SplFileInfo */ |
47 | 47 | foreach ($finder as $file) { |
48 | 48 | $path = $file->getRealPath(); |
49 | - if(!in_array($path, $loaded_files)) { |
|
49 | + if (!in_array($path, $loaded_files)) { |
|
50 | 50 | $loaded_files[] = $path; |
51 | 51 | require_once($path); |
52 | 52 | } |
@@ -7,4 +7,4 @@ |
||
7 | 7 | */ |
8 | 8 | Trait BoostrapTrait {} |
9 | 9 | |
10 | -require_once __DIR__ . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'bootstrap.php'; |
|
11 | 10 | \ No newline at end of file |
11 | +require_once __DIR__.DIRECTORY_SEPARATOR.'..'.DIRECTORY_SEPARATOR.'..'.DIRECTORY_SEPARATOR.'..'.DIRECTORY_SEPARATOR.'bootstrap.php'; |
|
12 | 12 | \ No newline at end of file |
@@ -35,7 +35,7 @@ discard block |
||
35 | 35 | $use /= 1024; |
36 | 36 | break; |
37 | 37 | case "MBytes": |
38 | - $use /= (1024 * 1024); |
|
38 | + $use /= (1024*1024); |
|
39 | 39 | break; |
40 | 40 | case "Bytes": |
41 | 41 | default: |
@@ -60,7 +60,7 @@ discard block |
||
60 | 60 | { |
61 | 61 | Logger::log('Added handlers for errors'); |
62 | 62 | //Warning & Notice handler |
63 | - set_error_handler(function ($errno, $errstr, $errfile, $errline) { |
|
63 | + set_error_handler(function($errno, $errstr, $errfile, $errline) { |
|
64 | 64 | Logger::log($errstr, LOG_CRIT, ['file' => $errfile, 'line' => $errline, 'errno' => $errno]); |
65 | 65 | return true; |
66 | 66 | }, E_ALL | E_STRICT); |
@@ -74,7 +74,7 @@ discard block |
||
74 | 74 | Logger::log('Initializing stats (mem + ts)'); |
75 | 75 | if (null !== $_SERVER && array_key_exists('REQUEST_TIME_FLOAT', $_SERVER)) { |
76 | 76 | $this->ts = (float)$_SERVER['REQUEST_TIME_FLOAT']; |
77 | - } else { |
|
77 | + }else { |
|
78 | 78 | $this->ts = Request::getInstance()->getTs(); |
79 | 79 | } |
80 | 80 | $this->mem = memory_get_usage(); |
@@ -34,7 +34,7 @@ |
||
34 | 34 | */ |
35 | 35 | public static function dropInstance() { |
36 | 36 | $class = get_called_class(); |
37 | - if(isset(self::$instance[$class])) { |
|
37 | + if (isset(self::$instance[$class])) { |
|
38 | 38 | self::$instance[$class] = null; |
39 | 39 | } |
40 | 40 | } |
@@ -212,7 +212,9 @@ discard block |
||
212 | 212 | */ |
213 | 213 | public function redirect($url = null) |
214 | 214 | { |
215 | - if (null === $url) $url = $this->getServer('HTTP_ORIGIN'); |
|
215 | + if (null === $url) { |
|
216 | + $url = $this->getServer('HTTP_ORIGIN'); |
|
217 | + } |
|
216 | 218 | ob_start(); |
217 | 219 | header('Location: ' . $url); |
218 | 220 | ob_end_clean(); |
@@ -259,7 +261,9 @@ discard block |
||
259 | 261 | $host = $this->getServerName(); |
260 | 262 | $protocol = $protocol ? $this->getProtocol() : ''; |
261 | 263 | $url = ''; |
262 | - if (!empty($host) && !empty($protocol)) $url = $protocol . $host; |
|
264 | + if (!empty($host) && !empty($protocol)) { |
|
265 | + $url = $protocol . $host; |
|
266 | + } |
|
263 | 267 | if (!in_array($this->getServer('SERVER_PORT'), [80, 443])) { |
264 | 268 | $url .= ':' . $this->getServer('SERVER_PORT'); |
265 | 269 | } |
@@ -54,7 +54,7 @@ discard block |
||
54 | 54 | |
55 | 55 | /** |
56 | 56 | * Método que verifica si existe una cabecera concreta |
57 | - * @param $header |
|
57 | + * @param string $header |
|
58 | 58 | * |
59 | 59 | * @return boolean |
60 | 60 | */ |
@@ -175,7 +175,7 @@ discard block |
||
175 | 175 | * |
176 | 176 | * @param string $queryParams |
177 | 177 | * |
178 | - * @return mixed |
|
178 | + * @return string |
|
179 | 179 | */ |
180 | 180 | public function getQuery($queryParams) |
181 | 181 | { |
@@ -112,7 +112,7 @@ discard block |
||
112 | 112 | */ |
113 | 113 | public static function header($name, $default = null) |
114 | 114 | { |
115 | - return self::getInstance()->getHeader($name, $default); |
|
115 | + return self::getInstance()->getHeader($name, $default); |
|
116 | 116 | } |
117 | 117 | |
118 | 118 | /** |
@@ -125,8 +125,8 @@ discard block |
||
125 | 125 | $header = null; |
126 | 126 | if ($this->hasHeader($name)) { |
127 | 127 | $header = $this->header[$name]; |
128 | - } else if(array_key_exists('h_' . strtolower($name), $this->query)) { |
|
129 | - $header = $this->query['h_' . strtolower($name)]; |
|
128 | + }else if (array_key_exists('h_'.strtolower($name), $this->query)) { |
|
129 | + $header = $this->query['h_'.strtolower($name)]; |
|
130 | 130 | } |
131 | 131 | return $header ?: $default; |
132 | 132 | } |
@@ -224,7 +224,7 @@ discard block |
||
224 | 224 | { |
225 | 225 | if (null === $url) $url = $this->getServer('HTTP_ORIGIN'); |
226 | 226 | ob_start(); |
227 | - header('Location: ' . $url); |
|
227 | + header('Location: '.$url); |
|
228 | 228 | ob_end_clean(); |
229 | 229 | Security::getInstance()->updateSession(); |
230 | 230 | exit(_("Redireccionando...")); |
@@ -269,9 +269,9 @@ discard block |
||
269 | 269 | $host = $this->getServerName(); |
270 | 270 | $protocol = $protocol ? $this->getProtocol() : ''; |
271 | 271 | $url = ''; |
272 | - if (!empty($host) && !empty($protocol)) $url = $protocol . $host; |
|
272 | + if (!empty($host) && !empty($protocol)) $url = $protocol.$host; |
|
273 | 273 | if (!in_array($this->getServer('SERVER_PORT'), [80, 443])) { |
274 | - $url .= ':' . $this->getServer('SERVER_PORT'); |
|
274 | + $url .= ':'.$this->getServer('SERVER_PORT'); |
|
275 | 275 | } |
276 | 276 | return $url; |
277 | 277 | } |