@@ -19,10 +19,10 @@ discard block |
||
19 | 19 | $objects = scandir($dir); |
20 | 20 | foreach ($objects as $object) { |
21 | 21 | if ($object != "." && $object != "..") { |
22 | - if (filetype($dir . "/" . $object) == "dir") { |
|
23 | - self::deleteDir($dir . "/" . $object); |
|
24 | - } else { |
|
25 | - unlink($dir . "/" . $object); |
|
22 | + if (filetype($dir."/".$object) == "dir") { |
|
23 | + self::deleteDir($dir."/".$object); |
|
24 | + }else { |
|
25 | + unlink($dir."/".$object); |
|
26 | 26 | } |
27 | 27 | } |
28 | 28 | } |
@@ -38,10 +38,10 @@ discard block |
||
38 | 38 | { |
39 | 39 | $rootDirs = array("css", "js", "media", "font"); |
40 | 40 | foreach ($rootDirs as $dir) { |
41 | - if (file_exists(WEB_DIR . DIRECTORY_SEPARATOR . $dir)) { |
|
41 | + if (file_exists(WEB_DIR.DIRECTORY_SEPARATOR.$dir)) { |
|
42 | 42 | try { |
43 | - self::deleteDir(WEB_DIR . DIRECTORY_SEPARATOR . $dir); |
|
44 | - } catch (\Exception $e) { |
|
43 | + self::deleteDir(WEB_DIR.DIRECTORY_SEPARATOR.$dir); |
|
44 | + }catch (\Exception $e) { |
|
45 | 45 | Logger::log($e->getMessage()); |
46 | 46 | } |
47 | 47 | } |
@@ -57,12 +57,12 @@ discard block |
||
57 | 57 | { |
58 | 58 | try { |
59 | 59 | if (!is_dir($dir) && @mkdir($dir, 0775, true) === false) { |
60 | - throw new \Exception(_('Can\'t create directory ') . $dir); |
|
60 | + throw new \Exception(_('Can\'t create directory ').$dir); |
|
61 | 61 | } |
62 | - } catch (\Exception $e) { |
|
62 | + }catch (\Exception $e) { |
|
63 | 63 | Logger::log($e->getMessage(), LOG_WARNING); |
64 | 64 | if (!file_exists(dirname($dir))) { |
65 | - throw new GeneratorException($e->getMessage() . $dir); |
|
65 | + throw new GeneratorException($e->getMessage().$dir); |
|
66 | 66 | } |
67 | 67 | } |
68 | 68 | } |
@@ -73,7 +73,7 @@ discard block |
||
73 | 73 | */ |
74 | 74 | public static function getTemplatePath() |
75 | 75 | { |
76 | - $path = __DIR__ . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'templates' . DIRECTORY_SEPARATOR; |
|
76 | + $path = __DIR__.DIRECTORY_SEPARATOR.'..'.DIRECTORY_SEPARATOR.'..'.DIRECTORY_SEPARATOR.'..'.DIRECTORY_SEPARATOR.'templates'.DIRECTORY_SEPARATOR; |
|
77 | 77 | return realpath($path); |
78 | 78 | } |
79 | 79 | |
@@ -91,15 +91,15 @@ discard block |
||
91 | 91 | * @throws GeneratorException |
92 | 92 | */ |
93 | 93 | public static function checkCustomNamespaceApi($namespace) { |
94 | - if(!empty($namespace)) { |
|
95 | - if(class_exists($namespace)) { |
|
94 | + if (!empty($namespace)) { |
|
95 | + if (class_exists($namespace)) { |
|
96 | 96 | $reflector = new \ReflectionClass($namespace); |
97 | - if(!$reflector->isSubclassOf(\PSFS\base\types\Api::class)) { |
|
97 | + if (!$reflector->isSubclassOf(\PSFS\base\types\Api::class)) { |
|
98 | 98 | throw new GeneratorException(_('La clase definida debe extender de PSFS\\\base\\\types\\\Api'), 501); |
99 | - } elseif(!$reflector->isAbstract()) { |
|
99 | + } elseif (!$reflector->isAbstract()) { |
|
100 | 100 | throw new GeneratorException(_('La clase definida debe ser abstracta'), 501); |
101 | 101 | } |
102 | - } else { |
|
102 | + }else { |
|
103 | 103 | throw new GeneratorException(_('La clase definida para extender la API no existe'), 501); |
104 | 104 | } |
105 | 105 | } |
@@ -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 | } |
@@ -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 |
@@ -192,7 +192,7 @@ discard block |
||
192 | 192 | /** |
193 | 193 | * Method that returns a config value |
194 | 194 | * @param string $param |
195 | - * @param mixed $defaultValue |
|
195 | + * @param string $defaultValue |
|
196 | 196 | * |
197 | 197 | * @return mixed|null |
198 | 198 | */ |
@@ -230,7 +230,7 @@ discard block |
||
230 | 230 | /** |
231 | 231 | * Static wrapper for extracting params |
232 | 232 | * @param string $key |
233 | - * @param mixed|null $defaultValue |
|
233 | + * @param string|boolean $defaultValue |
|
234 | 234 | * @return mixed|null |
235 | 235 | */ |
236 | 236 | public static function getParam($key, $defaultValue = null) |
@@ -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 | } |