@@ -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 | } |
@@ -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; |
@@ -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 | /** |
@@ -27,10 +27,10 @@ discard block |
||
27 | 27 | $isRequired = self::checkIsRequired($property->getDocComment()); |
28 | 28 | $label = self::getLabel($property->getDocComment()); |
29 | 29 | $isArray = (bool)preg_match('/\[\]$/', $instanceType); |
30 | - if($isArray) { |
|
30 | + if ($isArray) { |
|
31 | 31 | $instanceType = str_replace('[]', '', $instanceType); |
32 | 32 | } |
33 | - if($instanceType === '\\DateTime' || !Router::exists($instanceType)) { |
|
33 | + if ($instanceType === '\\DateTime' || !Router::exists($instanceType)) { |
|
34 | 34 | list($type, $format) = DocumentorHelper::translateSwaggerFormats($instanceType); |
35 | 35 | $variables[$property->getName()] = [ |
36 | 36 | 'type' => $type, |
@@ -38,7 +38,7 @@ discard block |
||
38 | 38 | 'required' => $isRequired, |
39 | 39 | 'description' => $label, |
40 | 40 | ]; |
41 | - } else { |
|
41 | + }else { |
|
42 | 42 | $instance = new \ReflectionClass($instanceType); |
43 | 43 | $variables[$property->getName()] = [ |
44 | 44 | 'is_array' => $isArray, |
@@ -124,7 +124,7 @@ discard block |
||
124 | 124 | // Extract description |
125 | 125 | $label = null; |
126 | 126 | preg_match('/@label\ (.*)\n/i', $doc, $matches); |
127 | - if(count($matches)) { |
|
127 | + if (count($matches)) { |
|
128 | 128 | $label = _($matches[1]); |
129 | 129 | } |
130 | 130 | return $label; |
@@ -137,7 +137,7 @@ discard block |
||
137 | 137 | public static function getDefaultValue($doc) { |
138 | 138 | $default = null; |
139 | 139 | preg_match('/@default\ (.*)\n/i', $doc, $matches); |
140 | - if(count($matches)) { |
|
140 | + if (count($matches)) { |
|
141 | 141 | $default = $matches[1]; |
142 | 142 | } |
143 | 143 | return $default; |
@@ -152,13 +152,13 @@ discard block |
||
152 | 152 | */ |
153 | 153 | public static function constructInyectableInstance($variable, $singleton, $classNameSpace, $calledClass) |
154 | 154 | { |
155 | - Logger::log('Create inyectable instance for ' . $classNameSpace); |
|
155 | + Logger::log('Create inyectable instance for '.$classNameSpace); |
|
156 | 156 | $reflector = new \ReflectionClass($calledClass); |
157 | 157 | $property = $reflector->getProperty($variable); |
158 | 158 | $varInstanceType = (null === $classNameSpace) ? InjectorHelper::extractVarType($property->getDocComment()) : $classNameSpace; |
159 | 159 | if (true === $singleton && method_exists($varInstanceType, 'getInstance')) { |
160 | 160 | $instance = $varInstanceType::getInstance(); |
161 | - } else { |
|
161 | + }else { |
|
162 | 162 | $instance = new $varInstanceType(); |
163 | 163 | } |
164 | 164 | return $instance; |
@@ -172,7 +172,7 @@ discard block |
||
172 | 172 | public static function getClassProperties($class) |
173 | 173 | { |
174 | 174 | $properties = []; |
175 | - Logger::log('Extracting annotations properties from class ' . $class); |
|
175 | + Logger::log('Extracting annotations properties from class '.$class); |
|
176 | 176 | $selfReflector = new \ReflectionClass($class); |
177 | 177 | if (false !== $selfReflector->getParentClass()) { |
178 | 178 | $properties = self::getClassProperties($selfReflector->getParentClass()->getName()); |
@@ -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 | } |
@@ -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 | } |
@@ -59,8 +59,10 @@ |
||
59 | 59 | $_route = explode("/", $url['path']); |
60 | 60 | $_pattern = explode("/", $pattern); |
61 | 61 | $get = array(); |
62 | - if (!empty($_pattern)) foreach ($_pattern as $index => $component) { |
|
62 | + if (!empty($_pattern)) { |
|
63 | + foreach ($_pattern as $index => $component) { |
|
63 | 64 | $_get = array(); |
65 | + } |
|
64 | 66 | preg_match_all('/^\{(.*)\}$/i', $component, $_get); |
65 | 67 | if (!empty($_get[1]) && isset($_route[$index])) { |
66 | 68 | $get[array_pop($_get[1])] = $_route[$index]; |
@@ -19,11 +19,11 @@ discard block |
||
19 | 19 | public static function getClassToCall(array $action) |
20 | 20 | { |
21 | 21 | Logger::log('Getting class to call for executing the request action', LOG_DEBUG, $action); |
22 | - $actionClass = class_exists($action['class']) ? $action['class'] : "\\" . $action['class']; |
|
22 | + $actionClass = class_exists($action['class']) ? $action['class'] : "\\".$action['class']; |
|
23 | 23 | $reflectionClass = new \ReflectionClass($actionClass); |
24 | - if($reflectionClass->hasMethod('getInstance')) { |
|
24 | + if ($reflectionClass->hasMethod('getInstance')) { |
|
25 | 25 | $class = $reflectionClass->getMethod('getInstance')->invoke(null, $action['method']); |
26 | - } else { |
|
26 | + }else { |
|
27 | 27 | $class = new $actionClass; |
28 | 28 | } |
29 | 29 | return $class; |
@@ -110,7 +110,7 @@ discard block |
||
110 | 110 | $expr = preg_quote($expr, '/'); |
111 | 111 | $expr = str_replace('###', '(.*)', $expr); |
112 | 112 | $expr2 = preg_replace('/\(\.\*\)$/', '', $expr); |
113 | - $matched = preg_match('/^' . $expr . '\/?$/i', $path) || preg_match('/^' . $expr2 . '?$/i', $path); |
|
113 | + $matched = preg_match('/^'.$expr.'\/?$/i', $path) || preg_match('/^'.$expr2.'?$/i', $path); |
|
114 | 114 | return $matched; |
115 | 115 | } |
116 | 116 | |
@@ -121,8 +121,8 @@ discard block |
||
121 | 121 | */ |
122 | 122 | public static function extractDomainInfo(\ReflectionClass $class, $domain) |
123 | 123 | { |
124 | - $path = dirname($class->getFileName()) . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR; |
|
125 | - $path = realpath($path) . DIRECTORY_SEPARATOR; |
|
124 | + $path = dirname($class->getFileName()).DIRECTORY_SEPARATOR.'..'.DIRECTORY_SEPARATOR; |
|
125 | + $path = realpath($path).DIRECTORY_SEPARATOR; |
|
126 | 126 | $tpl_path = "templates"; |
127 | 127 | $public_path = "public"; |
128 | 128 | $model_path = "models"; |
@@ -132,13 +132,13 @@ discard block |
||
132 | 132 | $model_path = ucfirst($model_path); |
133 | 133 | } |
134 | 134 | if ($class->hasConstant("TPL")) { |
135 | - $tpl_path .= DIRECTORY_SEPARATOR . $class->getConstant("TPL"); |
|
135 | + $tpl_path .= DIRECTORY_SEPARATOR.$class->getConstant("TPL"); |
|
136 | 136 | } |
137 | 137 | return [ |
138 | 138 | 'base' => $path, |
139 | - 'template' => $path . $tpl_path, |
|
140 | - 'model' => $path . $model_path, |
|
141 | - 'public' => $path . $public_path, |
|
139 | + 'template' => $path.$tpl_path, |
|
140 | + 'model' => $path.$model_path, |
|
141 | + 'public' => $path.$public_path, |
|
142 | 142 | ]; |
143 | 143 | } |
144 | 144 | |
@@ -162,12 +162,12 @@ discard block |
||
162 | 162 | foreach ($parameters as $param) { |
163 | 163 | if ($param->isOptional() && !is_array($param->getDefaultValue())) { |
164 | 164 | $params[$param->getName()] = $param->getDefaultValue(); |
165 | - $default = str_replace('{' . $param->getName() . '}', $param->getDefaultValue(), $regex); |
|
166 | - } elseif(!$param->isOptional()) { |
|
165 | + $default = str_replace('{'.$param->getName().'}', $param->getDefaultValue(), $regex); |
|
166 | + } elseif (!$param->isOptional()) { |
|
167 | 167 | $requirements[] = $param->getName(); |
168 | 168 | } |
169 | 169 | } |
170 | - } else { |
|
170 | + }else { |
|
171 | 171 | $default = $regex; |
172 | 172 | } |
173 | 173 | |
@@ -249,7 +249,7 @@ discard block |
||
249 | 249 | $default = str_replace('{__DOMAIN__}', $module, $default); |
250 | 250 | $httpMethod = self::extractReflectionHttpMethod($docComments); |
251 | 251 | $label = self::extractReflectionLabel(str_replace('{__API__}', $api, $docComments)); |
252 | - $route = $httpMethod . "#|#" . $regex; |
|
252 | + $route = $httpMethod."#|#".$regex; |
|
253 | 253 | $route = preg_replace('/(\\r|\\f|\\t|\\n)/', '', $route); |
254 | 254 | $info = [ |
255 | 255 | 'method' => $method->getName(), |