@@ -47,7 +47,7 @@ discard block |
||
| 47 | 47 | * @param $object |
| 48 | 48 | * @param $paths |
| 49 | 49 | * @param $url |
| 50 | - * @param $method |
|
| 50 | + * @param string $method |
|
| 51 | 51 | * @param $dtos |
| 52 | 52 | * @param $isReturn |
| 53 | 53 | * @return array |
@@ -87,7 +87,7 @@ discard block |
||
| 87 | 87 | * Translator from php types to swagger types |
| 88 | 88 | * @param string $format |
| 89 | 89 | * |
| 90 | - * @return array |
|
| 90 | + * @return string[] |
|
| 91 | 91 | */ |
| 92 | 92 | public static function translateSwaggerFormats($format) |
| 93 | 93 | { |
@@ -14,9 +14,9 @@ discard block |
||
| 14 | 14 | */ |
| 15 | 15 | private static function searchPayloadParam($params, $variable) { |
| 16 | 16 | $exists = false; |
| 17 | - if(null !== $params && count($params)) { |
|
| 18 | - foreach($params as $param) { |
|
| 19 | - if($param['name'] === $variable) { |
|
| 17 | + if (null !== $params && count($params)) { |
|
| 18 | + foreach ($params as $param) { |
|
| 19 | + if ($param['name'] === $variable) { |
|
| 20 | 20 | $exists = true; |
| 21 | 21 | break; |
| 22 | 22 | } |
@@ -40,12 +40,12 @@ discard block |
||
| 40 | 40 | ]; |
| 41 | 41 | if ($endpoint['payload']['is_array']) { |
| 42 | 42 | $schema['items'] = [ |
| 43 | - '$ref' => '#/definitions/' . $endpoint['payload']['type'], |
|
| 43 | + '$ref' => '#/definitions/'.$endpoint['payload']['type'], |
|
| 44 | 44 | ]; |
| 45 | - } else { |
|
| 46 | - $schema['$ref'] = '#/definitions/' . $endpoint['payload']['type']; |
|
| 45 | + }else { |
|
| 46 | + $schema['$ref'] = '#/definitions/'.$endpoint['payload']['type']; |
|
| 47 | 47 | } |
| 48 | - if(!self::searchPayloadParam($paths[$url][$method]['parameters'], $endpoint['payload']['type'])) { |
|
| 48 | + if (!self::searchPayloadParam($paths[$url][$method]['parameters'], $endpoint['payload']['type'])) { |
|
| 49 | 49 | $paths[$url][$method]['parameters'][] = [ |
| 50 | 50 | 'in' => 'body', |
| 51 | 51 | 'name' => $endpoint['payload']['type'], |
@@ -74,18 +74,18 @@ discard block |
||
| 74 | 74 | if (array_key_exists('data', $endpoint['return']) && count(array_keys($object)) === count(array_keys($endpoint['return']['data']))) { |
| 75 | 75 | $classDefinition = [ |
| 76 | 76 | 'type' => 'object', |
| 77 | - '$ref' => '#/definitions/' . $class, |
|
| 77 | + '$ref' => '#/definitions/'.$class, |
|
| 78 | 78 | ]; |
| 79 | - } else { |
|
| 79 | + }else { |
|
| 80 | 80 | $classDefinition = [ |
| 81 | 81 | 'type' => 'array', |
| 82 | 82 | 'items' => [ |
| 83 | - '$ref' => '#/definitions/' . $class, |
|
| 83 | + '$ref' => '#/definitions/'.$class, |
|
| 84 | 84 | ], |
| 85 | 85 | ]; |
| 86 | 86 | } |
| 87 | 87 | |
| 88 | - if($paths[$url][$method]['responses'][200]['schema']['properties']['data']['type'] === 'boolean') { |
|
| 88 | + if ($paths[$url][$method]['responses'][200]['schema']['properties']['data']['type'] === 'boolean') { |
|
| 89 | 89 | $paths[$url][$method]['responses'][200]['schema']['properties']['data'] = $classDefinition; |
| 90 | 90 | } |
| 91 | 91 | $dtos += self::extractSwaggerDefinition($class, $object); |
@@ -163,18 +163,18 @@ discard block |
||
| 163 | 163 | ], |
| 164 | 164 | ]; |
| 165 | 165 | foreach ($fields as $field => $info) { |
| 166 | - if(array_key_exists('type', $info) || in_array($info['type'], ['array', 'object'])) { |
|
| 166 | + if (array_key_exists('type', $info) || in_array($info['type'], ['array', 'object'])) { |
|
| 167 | 167 | $definition[$name]['properties'][$field] = $info; |
| 168 | - } else { |
|
| 168 | + }else { |
|
| 169 | 169 | list($type, $format) = self::translateSwaggerFormats($info['type']); |
| 170 | 170 | $fieldData = [ |
| 171 | 171 | "type" => $type, |
| 172 | 172 | "required" => $info['required'], |
| 173 | 173 | ]; |
| 174 | - if(array_key_exists('description', $info)) { |
|
| 174 | + if (array_key_exists('description', $info)) { |
|
| 175 | 175 | $fieldData['description'] = $info['description']; |
| 176 | 176 | } |
| 177 | - if(array_key_exists('format', $info)) { |
|
| 177 | + if (array_key_exists('format', $info)) { |
|
| 178 | 178 | $fieldData['format'] = $info['format']; |
| 179 | 179 | } |
| 180 | 180 | $dto['properties'][$field] = $fieldData; |
@@ -73,18 +73,18 @@ |
||
| 73 | 73 | if (!Request::getInstance()->isFile()) { |
| 74 | 74 | return $this->router->execute($this->actualUri); |
| 75 | 75 | } |
| 76 | - } else { |
|
| 76 | + }else { |
|
| 77 | 77 | return ConfigController::getInstance()->config(); |
| 78 | 78 | } |
| 79 | - } catch (AdminCredentialsException $a) { |
|
| 79 | + }catch (AdminCredentialsException $a) { |
|
| 80 | 80 | return UserController::showAdminManager(); |
| 81 | - } catch (SecurityException $s) { |
|
| 81 | + }catch (SecurityException $s) { |
|
| 82 | 82 | return $this->security->notAuthorized($this->actualUri); |
| 83 | - } catch (RouterException $r) { |
|
| 83 | + }catch (RouterException $r) { |
|
| 84 | 84 | return $this->router->httpNotFound($r); |
| 85 | - } catch(ApiException $a) { |
|
| 85 | + }catch (ApiException $a) { |
|
| 86 | 86 | return $this->router->httpNotFound($a, true); |
| 87 | - } catch (\Exception $e) { |
|
| 87 | + }catch (\Exception $e) { |
|
| 88 | 88 | return $this->dumpException($e); |
| 89 | 89 | } |
| 90 | 90 | } |
@@ -18,7 +18,7 @@ discard block |
||
| 18 | 18 | public function __construct($hydrate = true) |
| 19 | 19 | { |
| 20 | 20 | parent::__construct(); |
| 21 | - if($hydrate) { |
|
| 21 | + if ($hydrate) { |
|
| 22 | 22 | $this->fromArray(Request::getInstance()->getData()); |
| 23 | 23 | } |
| 24 | 24 | } |
@@ -46,15 +46,15 @@ discard block |
||
| 46 | 46 | /** @var \ReflectionProperty $property */ |
| 47 | 47 | foreach ($properties as $property) { |
| 48 | 48 | $value = $property->getValue($this); |
| 49 | - if(is_object($value) && method_exists($value, 'toArray')) { |
|
| 49 | + if (is_object($value) && method_exists($value, 'toArray')) { |
|
| 50 | 50 | $dto[$property->getName()] = $value->toArray(); |
| 51 | - } else { |
|
| 51 | + }else { |
|
| 52 | 52 | $dto[$property->getName()] = $property->getValue($this); |
| 53 | 53 | } |
| 54 | 54 | } |
| 55 | 55 | } |
| 56 | - } catch (\Exception $e) { |
|
| 57 | - Logger::log(get_class($this) . ': ' . $e->getMessage(), LOG_ERR); |
|
| 56 | + }catch (\Exception $e) { |
|
| 57 | + Logger::log(get_class($this).': '.$e->getMessage(), LOG_ERR); |
|
| 58 | 58 | } |
| 59 | 59 | return $dto; |
| 60 | 60 | } |
@@ -76,32 +76,32 @@ discard block |
||
| 76 | 76 | protected function parseDtoField(array $properties, $key, $value = null) { |
| 77 | 77 | $type = 'string'; |
| 78 | 78 | $is_array = false; |
| 79 | - if(array_key_exists($key, $properties)) { |
|
| 79 | + if (array_key_exists($key, $properties)) { |
|
| 80 | 80 | $type = $properties[$key]; |
| 81 | - if(preg_match('/(\[\]|Array)/i', $type)) { |
|
| 81 | + if (preg_match('/(\[\]|Array)/i', $type)) { |
|
| 82 | 82 | $type = preg_replace('/(\[\]|Array)/i', '', $type); |
| 83 | 83 | $is_array = true; |
| 84 | 84 | } |
| 85 | 85 | } |
| 86 | 86 | $reflector = (class_exists($type)) ? new \ReflectionClass($type) : null; |
| 87 | - if(null !== $reflector && $reflector->isSubclassOf(Dto::class)) { |
|
| 88 | - if(null !== $value && is_array($value)) { |
|
| 89 | - if($is_array) { |
|
| 87 | + if (null !== $reflector && $reflector->isSubclassOf(Dto::class)) { |
|
| 88 | + if (null !== $value && is_array($value)) { |
|
| 89 | + if ($is_array) { |
|
| 90 | 90 | $this->$key = []; |
| 91 | - foreach($value as $data) { |
|
| 92 | - if(null !== $data && is_array($data)) { |
|
| 91 | + foreach ($value as $data) { |
|
| 92 | + if (null !== $data && is_array($data)) { |
|
| 93 | 93 | $dto = new $type(false); |
| 94 | 94 | $dto->fromArray($data); |
| 95 | 95 | array_push($this->$key, $dto); |
| 96 | 96 | } |
| 97 | 97 | } |
| 98 | - } else { |
|
| 98 | + }else { |
|
| 99 | 99 | $this->$key = new $type(false); |
| 100 | 100 | $this->$key->fromArray($value); |
| 101 | 101 | } |
| 102 | 102 | } |
| 103 | - } else { |
|
| 104 | - switch($type) { |
|
| 103 | + }else { |
|
| 104 | + switch ($type) { |
|
| 105 | 105 | default: |
| 106 | 106 | case 'string': |
| 107 | 107 | $this->$key = $value; |
@@ -29,7 +29,7 @@ discard block |
||
| 29 | 29 | if (!Config::getInstance()->checkTryToSaveConfig() |
| 30 | 30 | && (preg_match('/^\/(admin|setup\-admin)/i', $route) || Config::getParam('restricted', false)) |
| 31 | 31 | ) { |
| 32 | - if (null === Cache::getInstance()->getDataFromFile(CONFIG_DIR . DIRECTORY_SEPARATOR . 'admins.json', Cache::JSONGZ, true)) { |
|
| 32 | + if (null === Cache::getInstance()->getDataFromFile(CONFIG_DIR.DIRECTORY_SEPARATOR.'admins.json', Cache::JSONGZ, true)) { |
|
| 33 | 33 | throw new AdminCredentialsException(); |
| 34 | 34 | } |
| 35 | 35 | if (!Security::getInstance()->checkAdmin()) { |
@@ -49,8 +49,8 @@ discard block |
||
| 49 | 49 | $token = ''; |
| 50 | 50 | $ct = strlen($ts); |
| 51 | 51 | for ($i = 0; $i < $ct; $i++) { |
| 52 | - $token = substr($hash, $i, 1) . |
|
| 53 | - substr($ts, $i, 1) . |
|
| 52 | + $token = substr($hash, $i, 1). |
|
| 53 | + substr($ts, $i, 1). |
|
| 54 | 54 | $token; |
| 55 | 55 | } |
| 56 | 56 | return $token; |
@@ -68,16 +68,16 @@ discard block |
||
| 68 | 68 | $charsLength = strlen(self::RAND_SEP) - 1; |
| 69 | 69 | $tsLength = strlen($ts); |
| 70 | 70 | $i = 0; |
| 71 | - $ct = ceil($hashRest / 4); |
|
| 72 | - $part = substr($hash, $tsLength + $ct * $i, $ct); |
|
| 73 | - while(false !== $part) { |
|
| 74 | - $mixedToken .= $part . |
|
| 75 | - substr(self::RAND_SEP, round(rand(0, $charsLength), 0, PHP_ROUND_HALF_DOWN), 1) . |
|
| 71 | + $ct = ceil($hashRest/4); |
|
| 72 | + $part = substr($hash, $tsLength + $ct*$i, $ct); |
|
| 73 | + while (false !== $part) { |
|
| 74 | + $mixedToken .= $part. |
|
| 75 | + substr(self::RAND_SEP, round(rand(0, $charsLength), 0, PHP_ROUND_HALF_DOWN), 1). |
|
| 76 | 76 | substr(self::RAND_SEP, round(rand(0, $charsLength), 0, PHP_ROUND_HALF_DOWN), 1); |
| 77 | - $part = substr($hash, $tsLength + $ct * $i, $ct); |
|
| 77 | + $part = substr($hash, $tsLength + $ct*$i, $ct); |
|
| 78 | 78 | $i++; |
| 79 | 79 | } |
| 80 | - return $mixedToken . $token; |
|
| 80 | + return $mixedToken.$token; |
|
| 81 | 81 | } |
| 82 | 82 | |
| 83 | 83 | /** |
@@ -86,10 +86,10 @@ discard block |
||
| 86 | 86 | */ |
| 87 | 87 | private static function getTs($isOdd = null) { |
| 88 | 88 | $ts = time(); |
| 89 | - $tsIsOdd = (bool)((int)substr($ts, -1) % 2); |
|
| 90 | - if(false === $isOdd && !$tsIsOdd) { |
|
| 89 | + $tsIsOdd = (bool)((int)substr($ts, -1)%2); |
|
| 90 | + if (false === $isOdd && !$tsIsOdd) { |
|
| 91 | 91 | $ts--; |
| 92 | - } elseif(true === $isOdd && !$tsIsOdd) { |
|
| 92 | + } elseif (true === $isOdd && !$tsIsOdd) { |
|
| 93 | 93 | $ts--; |
| 94 | 94 | } |
| 95 | 95 | return $ts; |
@@ -121,10 +121,10 @@ discard block |
||
| 121 | 121 | $partToken = ''; |
| 122 | 122 | $ts = ''; |
| 123 | 123 | $part = strrev($part); |
| 124 | - for($i = 0, $ct = strlen($part); $i < $ct; $i++) { |
|
| 125 | - if($i % 2 == 0) { |
|
| 124 | + for ($i = 0, $ct = strlen($part); $i < $ct; $i++) { |
|
| 125 | + if ($i%2 == 0) { |
|
| 126 | 126 | $ts .= substr($part, $i, 1); |
| 127 | - } else { |
|
| 127 | + }else { |
|
| 128 | 128 | $partToken .= substr($part, $i, 1); |
| 129 | 129 | } |
| 130 | 130 | } |
@@ -139,11 +139,11 @@ discard block |
||
| 139 | 139 | private static function parseTokenParts(array $parts) { |
| 140 | 140 | $token = ''; |
| 141 | 141 | list($partToken, $ts) = self::extractTs(array_pop($parts)); |
| 142 | - if($ts > 0) { |
|
| 143 | - foreach($parts as $part) { |
|
| 142 | + if ($ts > 0) { |
|
| 143 | + foreach ($parts as $part) { |
|
| 144 | 144 | $token .= $part; |
| 145 | 145 | } |
| 146 | - $token = $partToken . $token; |
|
| 146 | + $token = $partToken.$token; |
|
| 147 | 147 | } |
| 148 | 148 | return [$token, $ts]; |
| 149 | 149 | } |
@@ -171,8 +171,8 @@ discard block |
||
| 171 | 171 | * @return array |
| 172 | 172 | */ |
| 173 | 173 | private static function extractTokenParts($token) { |
| 174 | - for($i = 0, $ct = strlen(self::RAND_SEP); $i < $ct; $i++) { |
|
| 175 | - $token = str_replace(substr(self::RAND_SEP,$i,1), "|", $token); |
|
| 174 | + for ($i = 0, $ct = strlen(self::RAND_SEP); $i < $ct; $i++) { |
|
| 175 | + $token = str_replace(substr(self::RAND_SEP, $i, 1), "|", $token); |
|
| 176 | 176 | } |
| 177 | 177 | return array_unique(explode('||', $token)); |
| 178 | 178 | } |
@@ -49,7 +49,7 @@ discard block |
||
| 49 | 49 | |
| 50 | 50 | /** |
| 51 | 51 | * Método que verifica si existe una cabecera concreta |
| 52 | - * @param $header |
|
| 52 | + * @param string $header |
|
| 53 | 53 | * |
| 54 | 54 | * @return boolean |
| 55 | 55 | */ |
@@ -174,7 +174,7 @@ discard block |
||
| 174 | 174 | * |
| 175 | 175 | * @param string $queryParams |
| 176 | 176 | * |
| 177 | - * @return mixed |
|
| 177 | + * @return string |
|
| 178 | 178 | */ |
| 179 | 179 | public function getQuery($queryParams) |
| 180 | 180 | { |
@@ -235,7 +235,7 @@ discard block |
||
| 235 | 235 | /** |
| 236 | 236 | * Devuelve un parámetro de $_SERVER |
| 237 | 237 | * @param string $param |
| 238 | - * @param $default |
|
| 238 | + * @param string $default |
|
| 239 | 239 | * @return string|null |
| 240 | 240 | */ |
| 241 | 241 | public function getServer($param, $default = null) |
@@ -145,7 +145,7 @@ discard block |
||
| 145 | 145 | */ |
| 146 | 146 | public static function header($name, $default = null) |
| 147 | 147 | { |
| 148 | - return self::getInstance()->getHeader($name, $default); |
|
| 148 | + return self::getInstance()->getHeader($name, $default); |
|
| 149 | 149 | } |
| 150 | 150 | |
| 151 | 151 | /** |
@@ -158,10 +158,10 @@ discard block |
||
| 158 | 158 | $header = null; |
| 159 | 159 | if ($this->hasHeader($name)) { |
| 160 | 160 | $header = $this->header[$name]; |
| 161 | - } else if(array_key_exists('h_' . strtolower($name), $this->query)) { |
|
| 162 | - $header = $this->query['h_' . strtolower($name)]; |
|
| 163 | - } else if(array_key_exists('HTTP_' . strtoupper(str_replace('-', '_', $name)), $this->server)) { |
|
| 164 | - $header = $this->server['HTTP_' . strtoupper(str_replace('-', '_', $name))]; |
|
| 161 | + }else if (array_key_exists('h_'.strtolower($name), $this->query)) { |
|
| 162 | + $header = $this->query['h_'.strtolower($name)]; |
|
| 163 | + }else if (array_key_exists('HTTP_'.strtoupper(str_replace('-', '_', $name)), $this->server)) { |
|
| 164 | + $header = $this->server['HTTP_'.strtoupper(str_replace('-', '_', $name))]; |
|
| 165 | 165 | } |
| 166 | 166 | return $header ?: $default; |
| 167 | 167 | } |
@@ -258,7 +258,7 @@ discard block |
||
| 258 | 258 | { |
| 259 | 259 | if (null === $url) $url = $this->getServer('HTTP_ORIGIN'); |
| 260 | 260 | ob_start(); |
| 261 | - header('Location: ' . $url); |
|
| 261 | + header('Location: '.$url); |
|
| 262 | 262 | ob_end_clean(); |
| 263 | 263 | Security::getInstance()->updateSession(); |
| 264 | 264 | exit(_('Redireccionando...')); |
@@ -302,9 +302,9 @@ discard block |
||
| 302 | 302 | { |
| 303 | 303 | $url = $this->getServerName(); |
| 304 | 304 | $protocol = $protocol ? $this->getProtocol() : ''; |
| 305 | - if (!empty($protocol)) $url = $protocol . $url; |
|
| 305 | + if (!empty($protocol)) $url = $protocol.$url; |
|
| 306 | 306 | if (!in_array($this->getServer('SERVER_PORT'), [80, 443], true)) { |
| 307 | - $url .= ':' . $this->getServer('SERVER_PORT'); |
|
| 307 | + $url .= ':'.$this->getServer('SERVER_PORT'); |
|
| 308 | 308 | } |
| 309 | 309 | return $url; |
| 310 | 310 | } |
@@ -256,7 +256,9 @@ discard block |
||
| 256 | 256 | */ |
| 257 | 257 | public function redirect($url = null) |
| 258 | 258 | { |
| 259 | - if (null === $url) $url = $this->getServer('HTTP_ORIGIN'); |
|
| 259 | + if (null === $url) { |
|
| 260 | + $url = $this->getServer('HTTP_ORIGIN'); |
|
| 261 | + } |
|
| 260 | 262 | ob_start(); |
| 261 | 263 | header('Location: ' . $url); |
| 262 | 264 | ob_end_clean(); |
@@ -302,7 +304,9 @@ discard block |
||
| 302 | 304 | { |
| 303 | 305 | $url = $this->getServerName(); |
| 304 | 306 | $protocol = $protocol ? $this->getProtocol() : ''; |
| 305 | - if (!empty($protocol)) $url = $protocol . $url; |
|
| 307 | + if (!empty($protocol)) { |
|
| 308 | + $url = $protocol . $url; |
|
| 309 | + } |
|
| 306 | 310 | if (!in_array($this->getServer('SERVER_PORT'), [80, 443], true)) { |
| 307 | 311 | $url .= ':' . $this->getServer('SERVER_PORT'); |
| 308 | 312 | } |
@@ -188,7 +188,7 @@ |
||
| 188 | 188 | } |
| 189 | 189 | |
| 190 | 190 | /** |
| 191 | - * @return integer|boolean |
|
| 191 | + * @return integer |
|
| 192 | 192 | */ |
| 193 | 193 | public static function needCache() |
| 194 | 194 | { |
@@ -54,7 +54,7 @@ discard block |
||
| 54 | 54 | { |
| 55 | 55 | GeneratorHelper::createDir(dirname($path)); |
| 56 | 56 | if (false === FileHelper::writeFile($path, $data)) { |
| 57 | - throw new ConfigException(_('No se tienen los permisos suficientes para escribir en el fichero ') . $path); |
|
| 57 | + throw new ConfigException(_('No se tienen los permisos suficientes para escribir en el fichero ').$path); |
|
| 58 | 58 | } |
| 59 | 59 | } |
| 60 | 60 | |
@@ -68,7 +68,7 @@ discard block |
||
| 68 | 68 | { |
| 69 | 69 | Logger::log('Gathering data from cache', LOG_DEBUG, ['path' => $path]); |
| 70 | 70 | $data = null; |
| 71 | - $absolutePath = $absolute ? $path : CACHE_DIR . DIRECTORY_SEPARATOR . $path; |
|
| 71 | + $absolutePath = $absolute ? $path : CACHE_DIR.DIRECTORY_SEPARATOR.$path; |
|
| 72 | 72 | if (file_exists($absolutePath)) { |
| 73 | 73 | $data = FileHelper::readFile($absolutePath); |
| 74 | 74 | } |
@@ -84,7 +84,7 @@ discard block |
||
| 84 | 84 | private function hasExpiredCache($path, $expires = 300, $absolute = false) |
| 85 | 85 | { |
| 86 | 86 | Logger::log('Checking expiration', LOG_DEBUG, ['path' => $path]); |
| 87 | - $absolutePath = ($absolute) ? $path : CACHE_DIR . DIRECTORY_SEPARATOR . $path; |
|
| 87 | + $absolutePath = ($absolute) ? $path : CACHE_DIR.DIRECTORY_SEPARATOR.$path; |
|
| 88 | 88 | $lasModificationDate = filemtime($absolutePath); |
| 89 | 89 | return ($lasModificationDate + $expires <= time()); |
| 90 | 90 | } |
@@ -151,7 +151,7 @@ discard block |
||
| 151 | 151 | { |
| 152 | 152 | Logger::log('Store data in cache', LOG_DEBUG, ['path' => $path]); |
| 153 | 153 | $data = self::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 | |
@@ -168,11 +168,11 @@ discard block |
||
| 168 | 168 | { |
| 169 | 169 | $data = null; |
| 170 | 170 | Logger::log('Reading data from cache', LOG_DEBUG, ['path' => $path]); |
| 171 | - if (file_exists(CACHE_DIR . DIRECTORY_SEPARATOR . $path)) { |
|
| 171 | + if (file_exists(CACHE_DIR.DIRECTORY_SEPARATOR.$path)) { |
|
| 172 | 172 | if (is_callable($function) && $this->hasExpiredCache($path, $expires)) { |
| 173 | 173 | $data = $function(); |
| 174 | 174 | $this->storeData($path, $data, $transform, false, $expires); |
| 175 | - } else { |
|
| 175 | + }else { |
|
| 176 | 176 | $data = $this->getDataFromFile($path, $transform); |
| 177 | 177 | } |
| 178 | 178 | } |
@@ -224,13 +224,13 @@ discard block |
||
| 224 | 224 | } |
| 225 | 225 | |
| 226 | 226 | public function flushCache() { |
| 227 | - if(Config::getParam('cache.data.enable', false)) { |
|
| 227 | + if (Config::getParam('cache.data.enable', false)) { |
|
| 228 | 228 | Logger::log('Flushing cache', LOG_DEBUG); |
| 229 | 229 | $action = Security::getInstance()->getSessionKey(self::CACHE_SESSION_VAR); |
| 230 | - if(is_array($action)) { |
|
| 231 | - $hashPath = FileHelper::generateCachePath($action, $action['params']) . '..' . DIRECTORY_SEPARATOR . ' .. ' . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR; |
|
| 232 | - if(!file_exists($hashPath)) { |
|
| 233 | - $hashPath = CACHE_DIR . DIRECTORY_SEPARATOR . $hashPath; |
|
| 230 | + if (is_array($action)) { |
|
| 231 | + $hashPath = FileHelper::generateCachePath($action, $action['params']).'..'.DIRECTORY_SEPARATOR.' .. '.DIRECTORY_SEPARATOR.'..'.DIRECTORY_SEPARATOR; |
|
| 232 | + if (!file_exists($hashPath)) { |
|
| 233 | + $hashPath = CACHE_DIR.DIRECTORY_SEPARATOR.$hashPath; |
|
| 234 | 234 | } |
| 235 | 235 | FileHelper::deleteDir($hashPath); |
| 236 | 236 | } |
@@ -179,7 +179,7 @@ discard block |
||
| 179 | 179 | } |
| 180 | 180 | |
| 181 | 181 | /** |
| 182 | - * @param $route |
|
| 182 | + * @param string|null $route |
|
| 183 | 183 | * @throws AccessDeniedException |
| 184 | 184 | * @throws AdminCredentialsException |
| 185 | 185 | * @throws RouterException |
@@ -535,7 +535,7 @@ discard block |
||
| 535 | 535 | /** |
| 536 | 536 | * @param bool $hydrateRoute |
| 537 | 537 | * @param $modulePath |
| 538 | - * @param $externalModulePath |
|
| 538 | + * @param string $externalModulePath |
|
| 539 | 539 | */ |
| 540 | 540 | private function loadExternalAutoloader($hydrateRoute, SplFileInfo $modulePath, $externalModulePath) |
| 541 | 541 | { |
@@ -550,7 +550,7 @@ discard block |
||
| 550 | 550 | } |
| 551 | 551 | |
| 552 | 552 | /** |
| 553 | - * @param $hydrateRoute |
|
| 553 | + * @param boolean $hydrateRoute |
|
| 554 | 554 | * @param $module |
| 555 | 555 | * @return mixed |
| 556 | 556 | */ |
@@ -75,11 +75,11 @@ discard block |
||
| 75 | 75 | */ |
| 76 | 76 | public function init() |
| 77 | 77 | { |
| 78 | - list($this->routing, $this->slugs) = $this->cache->getDataFromFile(CONFIG_DIR . DIRECTORY_SEPARATOR . 'urls.json', $this->cacheType, TRUE); |
|
| 78 | + list($this->routing, $this->slugs) = $this->cache->getDataFromFile(CONFIG_DIR.DIRECTORY_SEPARATOR.'urls.json', $this->cacheType, TRUE); |
|
| 79 | 79 | if (empty($this->routing) || Config::getInstance()->getDebugMode()) { |
| 80 | 80 | $this->debugLoad(); |
| 81 | - } else { |
|
| 82 | - $this->domains = $this->cache->getDataFromFile(CONFIG_DIR . DIRECTORY_SEPARATOR . 'domains.json', $this->cacheType, TRUE); |
|
| 81 | + }else { |
|
| 82 | + $this->domains = $this->cache->getDataFromFile(CONFIG_DIR.DIRECTORY_SEPARATOR.'domains.json', $this->cacheType, TRUE); |
|
| 83 | 83 | } |
| 84 | 84 | $this->checkExternalModules(false); |
| 85 | 85 | $this->setLoaded(); |
@@ -117,9 +117,9 @@ discard block |
||
| 117 | 117 | } |
| 118 | 118 | |
| 119 | 119 | $not_found_route = Config::getParam('route.404'); |
| 120 | - if(null !== $not_found_route) { |
|
| 120 | + if (null !== $not_found_route) { |
|
| 121 | 121 | Request::getInstance()->redirect($this->getRoute($not_found_route, true)); |
| 122 | - } else { |
|
| 122 | + }else { |
|
| 123 | 123 | return $template->render('error.html.twig', array( |
| 124 | 124 | 'exception' => $e, |
| 125 | 125 | 'trace' => $e->getTraceAsString(), |
@@ -170,12 +170,12 @@ discard block |
||
| 170 | 170 | try { |
| 171 | 171 | //Search action and execute |
| 172 | 172 | $this->searchAction($route); |
| 173 | - } catch (AccessDeniedException $e) { |
|
| 174 | - Logger::log(_('Solicitamos credenciales de acceso a zona restringida'), LOG_WARNING, ['file' => $e->getFile() . '[' . $e->getLine() . ']']); |
|
| 173 | + }catch (AccessDeniedException $e) { |
|
| 174 | + Logger::log(_('Solicitamos credenciales de acceso a zona restringida'), LOG_WARNING, ['file' => $e->getFile().'['.$e->getLine().']']); |
|
| 175 | 175 | return Admin::staticAdminLogon($route); |
| 176 | - } catch (RouterException $r) { |
|
| 176 | + }catch (RouterException $r) { |
|
| 177 | 177 | Logger::log($r->getMessage(), LOG_WARNING); |
| 178 | - } catch (\Exception $e) { |
|
| 178 | + }catch (\Exception $e) { |
|
| 179 | 179 | Logger::log($e->getMessage(), LOG_ERR); |
| 180 | 180 | throw $e; |
| 181 | 181 | } |
@@ -192,7 +192,7 @@ discard block |
||
| 192 | 192 | */ |
| 193 | 193 | protected function searchAction($route) |
| 194 | 194 | { |
| 195 | - Logger::log('Searching action to execute: ' . $route, LOG_INFO); |
|
| 195 | + Logger::log('Searching action to execute: '.$route, LOG_INFO); |
|
| 196 | 196 | //Revisamos si tenemos la ruta registrada |
| 197 | 197 | $parts = parse_url($route); |
| 198 | 198 | $path = array_key_exists('path', $parts) ? $parts['path'] : $route; |
@@ -207,12 +207,12 @@ discard block |
||
| 207 | 207 | /** @var $class \PSFS\base\types\Controller */ |
| 208 | 208 | $class = RouterHelper::getClassToCall($action); |
| 209 | 209 | try { |
| 210 | - if($this->checkRequirements($action, $get)) { |
|
| 210 | + if ($this->checkRequirements($action, $get)) { |
|
| 211 | 211 | $this->executeCachedRoute($route, $action, $class, $get); |
| 212 | - } else { |
|
| 212 | + }else { |
|
| 213 | 213 | throw new RouterException(_('La ruta no es válida'), 400); |
| 214 | 214 | } |
| 215 | - } catch (\Exception $e) { |
|
| 215 | + }catch (\Exception $e) { |
|
| 216 | 216 | Logger::log($e->getMessage(), LOG_ERR); |
| 217 | 217 | throw $e; |
| 218 | 218 | } |
@@ -227,15 +227,15 @@ discard block |
||
| 227 | 227 | * @return bool |
| 228 | 228 | */ |
| 229 | 229 | private function checkRequirements(array $action, $params = []) { |
| 230 | - if(!empty($params) && !empty($action['requirements'])) { |
|
| 230 | + if (!empty($params) && !empty($action['requirements'])) { |
|
| 231 | 231 | $checked = 0; |
| 232 | - foreach(array_keys($params) as $key) { |
|
| 233 | - if(in_array($key, $action['requirements'], true)) { |
|
| 232 | + foreach (array_keys($params) as $key) { |
|
| 233 | + if (in_array($key, $action['requirements'], true)) { |
|
| 234 | 234 | $checked++; |
| 235 | 235 | } |
| 236 | 236 | } |
| 237 | 237 | $valid = count($action['requirements']) === $checked; |
| 238 | - } else { |
|
| 238 | + }else { |
|
| 239 | 239 | $valid = true; |
| 240 | 240 | } |
| 241 | 241 | return $valid; |
@@ -285,14 +285,14 @@ discard block |
||
| 285 | 285 | $this->checkExternalModules(); |
| 286 | 286 | if (file_exists($modulesPath)) { |
| 287 | 287 | $modules = $this->finder->directories()->in($modulesPath)->depth(0); |
| 288 | - if($modules->hasResults()) { |
|
| 288 | + if ($modules->hasResults()) { |
|
| 289 | 289 | foreach ($modules->getIterator() as $modulePath) { |
| 290 | 290 | $module = $modulePath->getBasename(); |
| 291 | - $this->routing = $this->inspectDir($modulesPath . DIRECTORY_SEPARATOR . $module, $module, $this->routing); |
|
| 291 | + $this->routing = $this->inspectDir($modulesPath.DIRECTORY_SEPARATOR.$module, $module, $this->routing); |
|
| 292 | 292 | } |
| 293 | 293 | } |
| 294 | 294 | } |
| 295 | - $this->cache->storeData(CONFIG_DIR . DIRECTORY_SEPARATOR . 'domains.json', $this->domains, Cache::JSON, TRUE); |
|
| 295 | + $this->cache->storeData(CONFIG_DIR.DIRECTORY_SEPARATOR.'domains.json', $this->domains, Cache::JSON, TRUE); |
|
| 296 | 296 | } |
| 297 | 297 | |
| 298 | 298 | /** |
@@ -308,7 +308,7 @@ discard block |
||
| 308 | 308 | $home_params = NULL; |
| 309 | 309 | foreach ($this->routing as $pattern => $params) { |
| 310 | 310 | list($method, $route) = RouterHelper::extractHttpRoute($pattern); |
| 311 | - if (preg_match('/' . preg_quote($route, '/') . '$/i', '/' . $home)) { |
|
| 311 | + if (preg_match('/'.preg_quote($route, '/').'$/i', '/'.$home)) { |
|
| 312 | 312 | $home_params = $params; |
| 313 | 313 | } |
| 314 | 314 | } |
@@ -329,14 +329,14 @@ discard block |
||
| 329 | 329 | private function inspectDir($origen, $namespace = 'PSFS', $routing = []) |
| 330 | 330 | { |
| 331 | 331 | $files = $this->finder->files()->in($origen)->path('/(controller|api)/i')->depth(1)->name('*.php'); |
| 332 | - if($files->hasResults()) { |
|
| 332 | + if ($files->hasResults()) { |
|
| 333 | 333 | foreach ($files->getIterator() as $file) { |
| 334 | - if(method_exists($file, 'getRelativePathname') && $namespace !== 'PSFS') { |
|
| 335 | - $filename = '\\' . str_replace('/', '\\', str_replace($origen, '', $file->getRelativePathname())); |
|
| 336 | - } else { |
|
| 334 | + if (method_exists($file, 'getRelativePathname') && $namespace !== 'PSFS') { |
|
| 335 | + $filename = '\\'.str_replace('/', '\\', str_replace($origen, '', $file->getRelativePathname())); |
|
| 336 | + }else { |
|
| 337 | 337 | $filename = str_replace('/', '\\', str_replace($origen, '', $file->getPathname())); |
| 338 | 338 | } |
| 339 | - $routing = $this->addRouting($namespace . str_replace('.php', '', $filename), $routing, $namespace); |
|
| 339 | + $routing = $this->addRouting($namespace.str_replace('.php', '', $filename), $routing, $namespace); |
|
| 340 | 340 | } |
| 341 | 341 | } |
| 342 | 342 | $this->finder = new Finder(); |
@@ -365,7 +365,7 @@ discard block |
||
| 365 | 365 | private function addRouting($namespace, &$routing, $module = 'PSFS') |
| 366 | 366 | { |
| 367 | 367 | if (self::exists($namespace)) { |
| 368 | - if(I18nHelper::checkI18Class($namespace)) { |
|
| 368 | + if (I18nHelper::checkI18Class($namespace)) { |
|
| 369 | 369 | return $routing; |
| 370 | 370 | } |
| 371 | 371 | $reflection = new \ReflectionClass($namespace); |
@@ -407,7 +407,7 @@ discard block |
||
| 407 | 407 | if (!$this->domains) { |
| 408 | 408 | $this->domains = []; |
| 409 | 409 | } |
| 410 | - $domain = '@' . $class->getConstant('DOMAIN') . '/'; |
|
| 410 | + $domain = '@'.$class->getConstant('DOMAIN').'/'; |
|
| 411 | 411 | if (!array_key_exists($domain, $this->domains)) { |
| 412 | 412 | $this->domains[$domain] = RouterHelper::extractDomainInfo($class, $domain); |
| 413 | 413 | } |
@@ -423,11 +423,11 @@ discard block |
||
| 423 | 423 | */ |
| 424 | 424 | public function simpatize() |
| 425 | 425 | { |
| 426 | - $translationFileName = 'translations' . DIRECTORY_SEPARATOR . 'routes_translations.php'; |
|
| 427 | - $absoluteTranslationFileName = CACHE_DIR . DIRECTORY_SEPARATOR . $translationFileName; |
|
| 426 | + $translationFileName = 'translations'.DIRECTORY_SEPARATOR.'routes_translations.php'; |
|
| 427 | + $absoluteTranslationFileName = CACHE_DIR.DIRECTORY_SEPARATOR.$translationFileName; |
|
| 428 | 428 | $this->generateSlugs($absoluteTranslationFileName); |
| 429 | 429 | GeneratorHelper::createDir(CONFIG_DIR); |
| 430 | - Cache::getInstance()->storeData(CONFIG_DIR . DIRECTORY_SEPARATOR . 'urls.json', array($this->routing, $this->slugs), Cache::JSON, TRUE); |
|
| 430 | + Cache::getInstance()->storeData(CONFIG_DIR.DIRECTORY_SEPARATOR.'urls.json', array($this->routing, $this->slugs), Cache::JSON, TRUE); |
|
| 431 | 431 | |
| 432 | 432 | return $this; |
| 433 | 433 | } |
@@ -443,18 +443,18 @@ discard block |
||
| 443 | 443 | public function getRoute($slug = '', $absolute = FALSE, array $params = []) |
| 444 | 444 | { |
| 445 | 445 | if ('' === $slug) { |
| 446 | - return $absolute ? Request::getInstance()->getRootUrl() . '/' : '/'; |
|
| 446 | + return $absolute ? Request::getInstance()->getRootUrl().'/' : '/'; |
|
| 447 | 447 | } |
| 448 | 448 | if (!is_array($this->slugs) || !array_key_exists($slug, $this->slugs)) { |
| 449 | 449 | throw new RouterException(_('No existe la ruta especificada')); |
| 450 | 450 | } |
| 451 | - $url = $absolute ? Request::getInstance()->getRootUrl() . $this->slugs[$slug] : $this->slugs[$slug]; |
|
| 451 | + $url = $absolute ? Request::getInstance()->getRootUrl().$this->slugs[$slug] : $this->slugs[$slug]; |
|
| 452 | 452 | if (!empty($params)) { |
| 453 | 453 | foreach ($params as $key => $value) { |
| 454 | - $url = str_replace('{' . $key . '}', $value, $url); |
|
| 454 | + $url = str_replace('{'.$key.'}', $value, $url); |
|
| 455 | 455 | } |
| 456 | 456 | } elseif (!empty($this->routing[$this->slugs[$slug]]['default'])) { |
| 457 | - $url = $absolute ? Request::getInstance()->getRootUrl() . $this->routing[$this->slugs[$slug]]['default'] : $this->routing[$this->slugs[$slug]]['default']; |
|
| 457 | + $url = $absolute ? Request::getInstance()->getRootUrl().$this->routing[$this->slugs[$slug]]['default'] : $this->routing[$this->slugs[$slug]]['default']; |
|
| 458 | 458 | } |
| 459 | 459 | |
| 460 | 460 | return preg_replace('/(GET|POST|PUT|DELETE|ALL)\#\|\#/', '', $url); |
@@ -491,15 +491,15 @@ discard block |
||
| 491 | 491 | * @param string $method |
| 492 | 492 | */ |
| 493 | 493 | private function checkPreActions($class, $method) { |
| 494 | - $preAction = 'pre' . ucfirst($method); |
|
| 495 | - if(method_exists($class, $preAction)) { |
|
| 494 | + $preAction = 'pre'.ucfirst($method); |
|
| 495 | + if (method_exists($class, $preAction)) { |
|
| 496 | 496 | Logger::log(_('Pre action invoked')); |
| 497 | 497 | try { |
| 498 | - if(false === call_user_func_array([$class, $preAction])) { |
|
| 498 | + if (false === call_user_func_array([$class, $preAction])) { |
|
| 499 | 499 | Logger::log(_('Pre action failed'), LOG_ERR, [error_get_last()]); |
| 500 | 500 | error_clear_last(); |
| 501 | 501 | } |
| 502 | - } catch (\Exception $e) { |
|
| 502 | + }catch (\Exception $e) { |
|
| 503 | 503 | Logger::log($e->getMessage(), LOG_ERR, [$class, $method]); |
| 504 | 504 | } |
| 505 | 505 | } |
@@ -515,16 +515,16 @@ discard block |
||
| 515 | 515 | */ |
| 516 | 516 | protected function executeCachedRoute($route, $action, $class, $params = NULL) |
| 517 | 517 | { |
| 518 | - Logger::log('Executing route ' . $route, LOG_INFO); |
|
| 518 | + Logger::log('Executing route '.$route, LOG_INFO); |
|
| 519 | 519 | $action['params'] = array_merge($action['params'], $params, Request::getInstance()->getQueryParams()); |
| 520 | 520 | Security::getInstance()->setSessionKey(Cache::CACHE_SESSION_VAR, $action); |
| 521 | 521 | $cache = Cache::needCache(); |
| 522 | 522 | $execute = TRUE; |
| 523 | 523 | if (FALSE !== $cache && $action['http'] === 'GET' && Config::getParam('debug') === FALSE) { |
| 524 | 524 | list($path, $cacheDataName) = $this->cache->getRequestCacheHash(); |
| 525 | - $cachedData = $this->cache->readFromCache('json' . DIRECTORY_SEPARATOR . $path . $cacheDataName, $cache); |
|
| 525 | + $cachedData = $this->cache->readFromCache('json'.DIRECTORY_SEPARATOR.$path.$cacheDataName, $cache); |
|
| 526 | 526 | if (NULL !== $cachedData) { |
| 527 | - $headers = $this->cache->readFromCache('json' . DIRECTORY_SEPARATOR . $path . $cacheDataName . '.headers', $cache, null, Cache::JSON); |
|
| 527 | + $headers = $this->cache->readFromCache('json'.DIRECTORY_SEPARATOR.$path.$cacheDataName.'.headers', $cache, null, Cache::JSON); |
|
| 528 | 528 | Template::getInstance()->renderCache($cachedData, $headers); |
| 529 | 529 | $execute = FALSE; |
| 530 | 530 | } |
@@ -567,11 +567,11 @@ discard block |
||
| 567 | 567 | private function loadExternalAutoloader($hydrateRoute, SplFileInfo $modulePath, $externalModulePath) |
| 568 | 568 | { |
| 569 | 569 | $extModule = $modulePath->getBasename(); |
| 570 | - $moduleAutoloader = realpath($externalModulePath . DIRECTORY_SEPARATOR . $extModule . DIRECTORY_SEPARATOR . 'autoload.php'); |
|
| 571 | - if(file_exists($moduleAutoloader)) { |
|
| 570 | + $moduleAutoloader = realpath($externalModulePath.DIRECTORY_SEPARATOR.$extModule.DIRECTORY_SEPARATOR.'autoload.php'); |
|
| 571 | + if (file_exists($moduleAutoloader)) { |
|
| 572 | 572 | include_once $moduleAutoloader; |
| 573 | 573 | if ($hydrateRoute) { |
| 574 | - $this->routing = $this->inspectDir($externalModulePath . DIRECTORY_SEPARATOR . $extModule, '\\' . $extModule, $this->routing); |
|
| 574 | + $this->routing = $this->inspectDir($externalModulePath.DIRECTORY_SEPARATOR.$extModule, '\\'.$extModule, $this->routing); |
|
| 575 | 575 | } |
| 576 | 576 | } |
| 577 | 577 | } |
@@ -585,16 +585,16 @@ discard block |
||
| 585 | 585 | { |
| 586 | 586 | try { |
| 587 | 587 | $module = preg_replace('/(\\\|\/)/', DIRECTORY_SEPARATOR, $module); |
| 588 | - $externalModulePath = VENDOR_DIR . DIRECTORY_SEPARATOR . $module . DIRECTORY_SEPARATOR . 'src'; |
|
| 589 | - if(file_exists($externalModulePath)) { |
|
| 588 | + $externalModulePath = VENDOR_DIR.DIRECTORY_SEPARATOR.$module.DIRECTORY_SEPARATOR.'src'; |
|
| 589 | + if (file_exists($externalModulePath)) { |
|
| 590 | 590 | $externalModule = $this->finder->directories()->in($externalModulePath)->depth(0); |
| 591 | - if($externalModule->hasResults()) { |
|
| 591 | + if ($externalModule->hasResults()) { |
|
| 592 | 592 | foreach ($externalModule->getIterator() as $modulePath) { |
| 593 | 593 | $this->loadExternalAutoloader($hydrateRoute, $modulePath, $externalModulePath); |
| 594 | 594 | } |
| 595 | 595 | } |
| 596 | 596 | } |
| 597 | - } catch (\Exception $e) { |
|
| 597 | + }catch (\Exception $e) { |
|
| 598 | 598 | Logger::log($e->getMessage(), LOG_WARNING); |
| 599 | 599 | $module = null; |
| 600 | 600 | } |
@@ -23,7 +23,7 @@ discard block |
||
| 23 | 23 | */ |
| 24 | 24 | public static function readFile($path) { |
| 25 | 25 | $data = false; |
| 26 | - if(file_exists($path)) { |
|
| 26 | + if (file_exists($path)) { |
|
| 27 | 27 | $data = @file_get_contents($path); |
| 28 | 28 | } |
| 29 | 29 | return $data; |
@@ -36,7 +36,7 @@ discard block |
||
| 36 | 36 | * @return string |
| 37 | 37 | */ |
| 38 | 38 | public static function generateHashFilename($verb, $slug, array $query = []) { |
| 39 | - return sha1(strtolower($verb) . ' ' . $slug . ' ' . strtolower(http_build_query($query))); |
|
| 39 | + return sha1(strtolower($verb).' '.$slug.' '.strtolower(http_build_query($query))); |
|
| 40 | 40 | } |
| 41 | 41 | |
| 42 | 42 | /** |
@@ -47,8 +47,8 @@ discard block |
||
| 47 | 47 | public static function generateCachePath(array $action, array $query = []) { |
| 48 | 48 | $class = GeneratorHelper::extractClassFromNamespace($action['class']); |
| 49 | 49 | $filename = self::generateHashFilename($action['http'], $action['slug'], $query); |
| 50 | - $subPath = substr($filename, 0, 2) . DIRECTORY_SEPARATOR . substr($filename, 2, 2); |
|
| 51 | - return $action['module'] . DIRECTORY_SEPARATOR . $class . DIRECTORY_SEPARATOR . $action['method'] . DIRECTORY_SEPARATOR . $subPath . DIRECTORY_SEPARATOR; |
|
| 50 | + $subPath = substr($filename, 0, 2).DIRECTORY_SEPARATOR.substr($filename, 2, 2); |
|
| 51 | + return $action['module'].DIRECTORY_SEPARATOR.$class.DIRECTORY_SEPARATOR.$action['method'].DIRECTORY_SEPARATOR.$subPath.DIRECTORY_SEPARATOR; |
|
| 52 | 52 | } |
| 53 | 53 | |
| 54 | 54 | /** |
@@ -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 | } |