@@ -4,7 +4,6 @@ |
||
4 | 4 | use PSFS\base\config\Config; |
5 | 5 | use PSFS\base\Security; |
6 | 6 | use PSFS\base\Service; |
7 | - use PSFS\controller\Admin; |
|
8 | 7 | use Symfony\Component\Finder\Finder; |
9 | 8 | |
10 | 9 | class AdminServices extends Service{ |
@@ -7,7 +7,7 @@ discard block |
||
7 | 7 | use PSFS\controller\Admin; |
8 | 8 | use Symfony\Component\Finder\Finder; |
9 | 9 | |
10 | - class AdminServices extends Service{ |
|
10 | + class AdminServices extends Service { |
|
11 | 11 | |
12 | 12 | /** |
13 | 13 | * @Inyectable |
@@ -33,7 +33,7 @@ discard block |
||
33 | 33 | { |
34 | 34 | $platform = trim(Config::getInstance()->get("platform_name")); |
35 | 35 | header('HTTP/1.1 401 Unauthorized'); |
36 | - header('WWW-Authenticate: Basic Realm="' . $platform. '"'); |
|
36 | + header('WWW-Authenticate: Basic Realm="'.$platform.'"'); |
|
37 | 37 | echo _("Zona restringida"); |
38 | 38 | exit(); |
39 | 39 | } |
@@ -45,9 +45,9 @@ discard block |
||
45 | 45 | public function getAdmins() |
46 | 46 | { |
47 | 47 | $admins = $this->security->getAdmins(); |
48 | - if(!empty($admins)) |
|
48 | + if (!empty($admins)) |
|
49 | 49 | { |
50 | - if(!$this->security->checkAdmin()) |
|
50 | + if (!$this->security->checkAdmin()) |
|
51 | 51 | { |
52 | 52 | $this->setAdminHeaders(); |
53 | 53 | } |
@@ -62,17 +62,17 @@ discard block |
||
62 | 62 | */ |
63 | 63 | private function parseAdmins(&$admins) |
64 | 64 | { |
65 | - if(!empty($admins)) foreach($admins as &$admin) |
|
65 | + if (!empty($admins)) foreach ($admins as &$admin) |
|
66 | 66 | { |
67 | - if(isset($admin["profile"])) |
|
67 | + if (isset($admin["profile"])) |
|
68 | 68 | { |
69 | - switch($admin["profile"]) { |
|
69 | + switch ($admin["profile"]) { |
|
70 | 70 | case Security::MANAGER_ID_TOKEN: $admin['class'] = 'warning'; break; |
71 | 71 | case Security::ADMIN_ID_TOKEN: $admin['class'] = 'info'; break; |
72 | 72 | default: |
73 | 73 | case Security::USER_ID_TOKEN: $admin['class'] = 'primary'; break; |
74 | 74 | } |
75 | - }else{ |
|
75 | + }else { |
|
76 | 76 | $admin["class"] = "primary"; |
77 | 77 | } |
78 | 78 | } |
@@ -88,12 +88,12 @@ discard block |
||
88 | 88 | $files->files()->in(LOG_DIR)->name("*.log")->sortByModifiedTime(); |
89 | 89 | $logs = array(); |
90 | 90 | /** @var \SplFileInfo $file */ |
91 | - foreach($files as $file) |
|
91 | + foreach ($files as $file) |
|
92 | 92 | { |
93 | - $size = $file->getSize() / 8 / 1024; |
|
93 | + $size = $file->getSize()/8/1024; |
|
94 | 94 | $time = date("c", $file->getMTime()); |
95 | 95 | $dateTime = new \DateTime($time); |
96 | - if(!isset($logs[$dateTime->format("Y")])) $logs[$dateTime->format("Y")] = array(); |
|
96 | + if (!isset($logs[$dateTime->format("Y")])) $logs[$dateTime->format("Y")] = array(); |
|
97 | 97 | $logs[$dateTime->format("Y")][$dateTime->format("m")][$time] = array( |
98 | 98 | "filename" => $file->getFilename(), |
99 | 99 | "size" => round($size, 3) |
@@ -117,27 +117,27 @@ discard block |
||
117 | 117 | $files->files()->in(LOG_DIR)->name($selectedLog); |
118 | 118 | $file = null; |
119 | 119 | $log = array(); |
120 | - foreach($files as $match) |
|
120 | + foreach ($files as $match) |
|
121 | 121 | { |
122 | 122 | $file = $match; |
123 | 123 | break; |
124 | 124 | } |
125 | 125 | /** @var \SplFileInfo $file */ |
126 | - if(!empty($file)) |
|
126 | + if (!empty($file)) |
|
127 | 127 | { |
128 | 128 | $time = date("c", $file->getMTime()); |
129 | 129 | $dateTime = new \DateTime($time); |
130 | 130 | $monthOpen = $dateTime->format("m"); |
131 | - $content = file($file->getPath() . DIRECTORY_SEPARATOR . $file->getFilename()); |
|
131 | + $content = file($file->getPath().DIRECTORY_SEPARATOR.$file->getFilename()); |
|
132 | 132 | krsort($content); |
133 | 133 | $detailLog = array(); |
134 | - foreach($content as &$line) |
|
134 | + foreach ($content as &$line) |
|
135 | 135 | { |
136 | 136 | list($line, $detail) = $this->parseLogLine($line, $match); |
137 | 137 | $detailLog[] = array_merge(array( |
138 | 138 | "log" => $line, |
139 | 139 | ), $detail); |
140 | - if(count($detailLog) >= 1000) break; |
|
140 | + if (count($detailLog) >= 1000) break; |
|
141 | 141 | } |
142 | 142 | $log = $detailLog; |
143 | 143 | } |
@@ -166,7 +166,7 @@ discard block |
||
166 | 166 | |
167 | 167 | $type = (isset($match[1][0])) ? $match[1][0] : ''; |
168 | 168 | $type = explode(".", $type); |
169 | - $type = count($type)>1 ? $type[1] : $type[0]; |
|
169 | + $type = count($type) > 1 ? $type[1] : $type[0]; |
|
170 | 170 | switch ($type) { |
171 | 171 | case 'INFO': |
172 | 172 | $detail["type"] = "success"; |
@@ -182,7 +182,7 @@ discard block |
||
182 | 182 | break; |
183 | 183 | } |
184 | 184 | |
185 | - } catch (\Exception $e) { |
|
185 | + }catch (\Exception $e) { |
|
186 | 186 | $detail = array( |
187 | 187 | "type" => "danger", |
188 | 188 | ); |
@@ -62,17 +62,20 @@ discard block |
||
62 | 62 | */ |
63 | 63 | private function parseAdmins(&$admins) |
64 | 64 | { |
65 | - if(!empty($admins)) foreach($admins as &$admin) |
|
65 | + if(!empty($admins)) { |
|
66 | + foreach($admins as &$admin) |
|
66 | 67 | { |
67 | 68 | if(isset($admin["profile"])) |
68 | 69 | { |
69 | 70 | switch($admin["profile"]) { |
70 | - case Security::MANAGER_ID_TOKEN: $admin['class'] = 'warning'; break; |
|
71 | + case Security::MANAGER_ID_TOKEN: $admin['class'] = 'warning'; |
|
72 | + } |
|
73 | + break; |
|
71 | 74 | case Security::ADMIN_ID_TOKEN: $admin['class'] = 'info'; break; |
72 | 75 | default: |
73 | 76 | case Security::USER_ID_TOKEN: $admin['class'] = 'primary'; break; |
74 | 77 | } |
75 | - }else{ |
|
78 | + } else{ |
|
76 | 79 | $admin["class"] = "primary"; |
77 | 80 | } |
78 | 81 | } |
@@ -93,7 +96,9 @@ discard block |
||
93 | 96 | $size = $file->getSize() / 8 / 1024; |
94 | 97 | $time = date("c", $file->getMTime()); |
95 | 98 | $dateTime = new \DateTime($time); |
96 | - if(!isset($logs[$dateTime->format("Y")])) $logs[$dateTime->format("Y")] = array(); |
|
99 | + if(!isset($logs[$dateTime->format("Y")])) { |
|
100 | + $logs[$dateTime->format("Y")] = array(); |
|
101 | + } |
|
97 | 102 | $logs[$dateTime->format("Y")][$dateTime->format("m")][$time] = array( |
98 | 103 | "filename" => $file->getFilename(), |
99 | 104 | "size" => round($size, 3) |
@@ -137,7 +142,9 @@ discard block |
||
137 | 142 | $detailLog[] = array_merge(array( |
138 | 143 | "log" => $line, |
139 | 144 | ), $detail); |
140 | - if(count($detailLog) >= 1000) break; |
|
145 | + if(count($detailLog) >= 1000) { |
|
146 | + break; |
|
147 | + } |
|
141 | 148 | } |
142 | 149 | $log = $detailLog; |
143 | 150 | } |
@@ -161,7 +168,9 @@ discard block |
||
161 | 168 | |
162 | 169 | $detail = json_decode($match[0][0], TRUE); |
163 | 170 | } |
164 | - if (empty($detail)) $detail = array(); |
|
171 | + if (empty($detail)) { |
|
172 | + $detail = array(); |
|
173 | + } |
|
165 | 174 | preg_match_all('/\>\ (.*):/i', $line, $match); |
166 | 175 | |
167 | 176 | $type = (isset($match[1][0])) ? $match[1][0] : ''; |
@@ -393,8 +393,10 @@ |
||
393 | 393 | throw new RouterException(_("No existe la ruta especificada")); |
394 | 394 | } |
395 | 395 | $url = ($absolute) ? Request::getInstance()->getRootUrl() . $this->slugs[$slug] : $this->slugs[$slug]; |
396 | - if (!empty($params)) foreach ($params as $key => $value) { |
|
396 | + if (!empty($params)) { |
|
397 | + foreach ($params as $key => $value) { |
|
397 | 398 | $url = str_replace("{" . $key . "}", $value, $url); |
399 | + } |
|
398 | 400 | } elseif (!empty($this->routing[$this->slugs[$slug]]["default"])) { |
399 | 401 | $url = ($absolute) ? Request::getInstance()->getRootUrl() . $this->routing[$this->slugs[$slug]]["default"] : $this->routing[$this->slugs[$slug]]["default"]; |
400 | 402 | } |
@@ -59,12 +59,12 @@ discard block |
||
59 | 59 | */ |
60 | 60 | public function init() |
61 | 61 | { |
62 | - if (!file_exists(CONFIG_DIR . DIRECTORY_SEPARATOR . "urls.json") || Config::getInstance()->getDebugMode()) { |
|
62 | + if (!file_exists(CONFIG_DIR.DIRECTORY_SEPARATOR."urls.json") || Config::getInstance()->getDebugMode()) { |
|
63 | 63 | $this->hydrateRouting(); |
64 | 64 | $this->simpatize(); |
65 | - } else { |
|
66 | - list($this->routing, $this->slugs) = $this->cache->getDataFromFile(CONFIG_DIR . DIRECTORY_SEPARATOR . "urls.json", Cache::JSON, TRUE); |
|
67 | - $this->domains = $this->cache->getDataFromFile(CONFIG_DIR . DIRECTORY_SEPARATOR . "domains.json", Cache::JSON, TRUE); |
|
65 | + }else { |
|
66 | + list($this->routing, $this->slugs) = $this->cache->getDataFromFile(CONFIG_DIR.DIRECTORY_SEPARATOR."urls.json", Cache::JSON, TRUE); |
|
67 | + $this->domains = $this->cache->getDataFromFile(CONFIG_DIR.DIRECTORY_SEPARATOR."domains.json", Cache::JSON, TRUE); |
|
68 | 68 | } |
69 | 69 | } |
70 | 70 | |
@@ -88,7 +88,7 @@ discard block |
||
88 | 88 | "success" => FALSE, |
89 | 89 | "error" => $e->getMessage(), |
90 | 90 | )), 'application/json'); |
91 | - } else { |
|
91 | + }else { |
|
92 | 92 | return $template->render('error.html.twig', array( |
93 | 93 | 'exception' => $e, |
94 | 94 | 'trace' => $e->getTraceAsString(), |
@@ -112,8 +112,8 @@ discard block |
||
112 | 112 | */ |
113 | 113 | public function getAllRoutes() { |
114 | 114 | $routes = []; |
115 | - foreach($this->routing as $path => $route) { |
|
116 | - if(array_key_exists('slug', $route)) { |
|
115 | + foreach ($this->routing as $path => $route) { |
|
116 | + if (array_key_exists('slug', $route)) { |
|
117 | 117 | $routes[$route['slug']] = $path; |
118 | 118 | } |
119 | 119 | } |
@@ -138,12 +138,12 @@ discard block |
||
138 | 138 | SecurityHelper::checkRestrictedAccess($route); |
139 | 139 | //Search action and execute |
140 | 140 | $this->searchAction($route); |
141 | - } catch (AccessDeniedException $e) { |
|
141 | + }catch (AccessDeniedException $e) { |
|
142 | 142 | Logger::log(_('Solicitamos credenciales de acceso a zona restringida')); |
143 | 143 | return Admin::staticAdminLogon($route); |
144 | - } catch (RouterException $r) { |
|
144 | + }catch (RouterException $r) { |
|
145 | 145 | Logger::log($r->getMessage(), LOG_WARNING); |
146 | - } catch (\Exception $e) { |
|
146 | + }catch (\Exception $e) { |
|
147 | 147 | Logger::log($e->getMessage(), LOG_ERR); |
148 | 148 | throw $e; |
149 | 149 | } |
@@ -160,7 +160,7 @@ discard block |
||
160 | 160 | */ |
161 | 161 | protected function searchAction($route) |
162 | 162 | { |
163 | - Logger::log('Searching action to execute: ' . $route, LOG_INFO); |
|
163 | + Logger::log('Searching action to execute: '.$route, LOG_INFO); |
|
164 | 164 | //Revisamos si tenemos la ruta registrada |
165 | 165 | $parts = parse_url($route); |
166 | 166 | $path = (array_key_exists('path', $parts)) ? $parts['path'] : $route; |
@@ -174,7 +174,7 @@ discard block |
||
174 | 174 | $class = RouterHelper::getClassToCall($action); |
175 | 175 | try { |
176 | 176 | $this->executeCachedRoute($route, $action, $class, $get); |
177 | - } catch (\Exception $e) { |
|
177 | + }catch (\Exception $e) { |
|
178 | 178 | Logger::log($e->getMessage(), LOG_ERR); |
179 | 179 | throw new RouterException($e->getMessage(), 404, $e); |
180 | 180 | } |
@@ -194,20 +194,20 @@ discard block |
||
194 | 194 | |
195 | 195 | private function checkExternalModules() { |
196 | 196 | $externalModules = Config::getParam('modules.extend'); |
197 | - if(null !== $externalModules) { |
|
197 | + if (null !== $externalModules) { |
|
198 | 198 | $externalModules = explode(',', $externalModules); |
199 | - foreach($externalModules as &$module) { |
|
199 | + foreach ($externalModules as &$module) { |
|
200 | 200 | $module = preg_replace('/(\\\|\/)/', DIRECTORY_SEPARATOR, $module); |
201 | - $externalModulePath = VENDOR_DIR . DIRECTORY_SEPARATOR . $module . DIRECTORY_SEPARATOR . 'src'; |
|
202 | - if(file_exists($externalModulePath)) { |
|
201 | + $externalModulePath = VENDOR_DIR.DIRECTORY_SEPARATOR.$module.DIRECTORY_SEPARATOR.'src'; |
|
202 | + if (file_exists($externalModulePath)) { |
|
203 | 203 | $externalModule = $this->finder->directories()->in($externalModulePath)->depth(0); |
204 | - if(!empty($externalModule)) { |
|
205 | - foreach($externalModule as $modulePath) { |
|
204 | + if (!empty($externalModule)) { |
|
205 | + foreach ($externalModule as $modulePath) { |
|
206 | 206 | $extModule = $modulePath->getBasename(); |
207 | - $moduleAutoloader = realpath($externalModulePath . DIRECTORY_SEPARATOR . $extModule . DIRECTORY_SEPARATOR . 'autoload.php'); |
|
208 | - if(file_exists($moduleAutoloader)) { |
|
207 | + $moduleAutoloader = realpath($externalModulePath.DIRECTORY_SEPARATOR.$extModule.DIRECTORY_SEPARATOR.'autoload.php'); |
|
208 | + if (file_exists($moduleAutoloader)) { |
|
209 | 209 | @include $moduleAutoloader; |
210 | - $this->routing = $this->inspectDir($externalModulePath . DIRECTORY_SEPARATOR . $extModule, $extModule, $this->routing); |
|
210 | + $this->routing = $this->inspectDir($externalModulePath.DIRECTORY_SEPARATOR.$extModule, $extModule, $this->routing); |
|
211 | 211 | } |
212 | 212 | } |
213 | 213 | } |
@@ -226,13 +226,13 @@ discard block |
||
226 | 226 | $this->routing = $this->inspectDir($base, "PSFS", array()); |
227 | 227 | if (file_exists($modulesPath)) { |
228 | 228 | $modules = $this->finder->directories()->in($modulesPath)->depth(0); |
229 | - foreach($modules as $modulePath) { |
|
229 | + foreach ($modules as $modulePath) { |
|
230 | 230 | $module = $modulePath->getBasename(); |
231 | - $this->routing = $this->inspectDir($modulesPath . DIRECTORY_SEPARATOR . $module, $module, $this->routing); |
|
231 | + $this->routing = $this->inspectDir($modulesPath.DIRECTORY_SEPARATOR.$module, $module, $this->routing); |
|
232 | 232 | } |
233 | 233 | } |
234 | 234 | $this->checkExternalModules(); |
235 | - $this->cache->storeData(CONFIG_DIR . DIRECTORY_SEPARATOR . "domains.json", $this->domains, Cache::JSON, TRUE); |
|
235 | + $this->cache->storeData(CONFIG_DIR.DIRECTORY_SEPARATOR."domains.json", $this->domains, Cache::JSON, TRUE); |
|
236 | 236 | } |
237 | 237 | |
238 | 238 | /** |
@@ -247,7 +247,7 @@ discard block |
||
247 | 247 | $home_params = NULL; |
248 | 248 | foreach ($this->routing as $pattern => $params) { |
249 | 249 | list($method, $route) = RouterHelper::extractHttpRoute($pattern); |
250 | - if (preg_match("/" . preg_quote($route, "/") . "$/i", "/" . $home)) { |
|
250 | + if (preg_match("/".preg_quote($route, "/")."$/i", "/".$home)) { |
|
251 | 251 | $home_params = $params; |
252 | 252 | } |
253 | 253 | } |
@@ -272,7 +272,7 @@ discard block |
||
272 | 272 | $files = $this->finder->files()->in($origen)->path('/(controller|api)/i')->depth(1)->name("*.php"); |
273 | 273 | foreach ($files as $file) { |
274 | 274 | $filename = str_replace("/", '\\', str_replace($origen, '', $file->getPathname())); |
275 | - $routing = $this->addRouting($namespace . str_replace('.php', '', $filename), $routing, $namespace); |
|
275 | + $routing = $this->addRouting($namespace.str_replace('.php', '', $filename), $routing, $namespace); |
|
276 | 276 | } |
277 | 277 | $this->finder = new Finder(); |
278 | 278 | |
@@ -311,9 +311,9 @@ discard block |
||
311 | 311 | $api = array_key_exists(1, $apiPath) ? $apiPath[1] : $api; |
312 | 312 | } |
313 | 313 | foreach ($reflection->getMethods(\ReflectionMethod::IS_PUBLIC) as $method) { |
314 | - if(preg_match('/@route\ /i', $method->getDocComment())) { |
|
314 | + if (preg_match('/@route\ /i', $method->getDocComment())) { |
|
315 | 315 | list($route, $info) = RouterHelper::extractRouteInfo($method, $api, $module); |
316 | - if(null !== $route && null !== $info) { |
|
316 | + if (null !== $route && null !== $info) { |
|
317 | 317 | $info['class'] = $namespace; |
318 | 318 | $routing[$route] = $info; |
319 | 319 | } |
@@ -337,11 +337,11 @@ discard block |
||
337 | 337 | { |
338 | 338 | //Calculamos los dominios para las plantillas |
339 | 339 | if ($class->hasConstant("DOMAIN") && !$class->isAbstract()) { |
340 | - if(!$this->domains) { |
|
340 | + if (!$this->domains) { |
|
341 | 341 | $this->domains = []; |
342 | 342 | } |
343 | - $domain = "@" . $class->getConstant("DOMAIN") . "/"; |
|
344 | - if(!array_key_exists($domain, $this->domains)) { |
|
343 | + $domain = "@".$class->getConstant("DOMAIN")."/"; |
|
344 | + if (!array_key_exists($domain, $this->domains)) { |
|
345 | 345 | $this->domains[$domain] = RouterHelper::extractDomainInfo($class, $domain); |
346 | 346 | } |
347 | 347 | } |
@@ -355,11 +355,11 @@ discard block |
||
355 | 355 | */ |
356 | 356 | public function simpatize() |
357 | 357 | { |
358 | - $translationFileName = "translations" . DIRECTORY_SEPARATOR . "routes_translations.php"; |
|
359 | - $absoluteTranslationFileName = CACHE_DIR . DIRECTORY_SEPARATOR . $translationFileName; |
|
358 | + $translationFileName = "translations".DIRECTORY_SEPARATOR."routes_translations.php"; |
|
359 | + $absoluteTranslationFileName = CACHE_DIR.DIRECTORY_SEPARATOR.$translationFileName; |
|
360 | 360 | $this->generateSlugs($absoluteTranslationFileName); |
361 | 361 | Config::createDir(CONFIG_DIR); |
362 | - Cache::getInstance()->storeData(CONFIG_DIR . DIRECTORY_SEPARATOR . "urls.json", array($this->routing, $this->slugs), Cache::JSON, TRUE); |
|
362 | + Cache::getInstance()->storeData(CONFIG_DIR.DIRECTORY_SEPARATOR."urls.json", array($this->routing, $this->slugs), Cache::JSON, TRUE); |
|
363 | 363 | |
364 | 364 | return $this; |
365 | 365 | } |
@@ -377,16 +377,16 @@ discard block |
||
377 | 377 | public function getRoute($slug = '', $absolute = FALSE, $params = []) |
378 | 378 | { |
379 | 379 | if (strlen($slug) === 0) { |
380 | - return ($absolute) ? Request::getInstance()->getRootUrl() . '/' : '/'; |
|
380 | + return ($absolute) ? Request::getInstance()->getRootUrl().'/' : '/'; |
|
381 | 381 | } |
382 | 382 | if (NULL === $slug || !array_key_exists($slug, $this->slugs)) { |
383 | 383 | throw new RouterException(_("No existe la ruta especificada")); |
384 | 384 | } |
385 | - $url = ($absolute) ? Request::getInstance()->getRootUrl() . $this->slugs[$slug] : $this->slugs[$slug]; |
|
385 | + $url = ($absolute) ? Request::getInstance()->getRootUrl().$this->slugs[$slug] : $this->slugs[$slug]; |
|
386 | 386 | if (!empty($params)) foreach ($params as $key => $value) { |
387 | - $url = str_replace("{" . $key . "}", $value, $url); |
|
387 | + $url = str_replace("{".$key."}", $value, $url); |
|
388 | 388 | } elseif (!empty($this->routing[$this->slugs[$slug]]["default"])) { |
389 | - $url = ($absolute) ? Request::getInstance()->getRootUrl() . $this->routing[$this->slugs[$slug]]["default"] : $this->routing[$this->slugs[$slug]]["default"]; |
|
389 | + $url = ($absolute) ? Request::getInstance()->getRootUrl().$this->routing[$this->slugs[$slug]]["default"] : $this->routing[$this->slugs[$slug]]["default"]; |
|
390 | 390 | } |
391 | 391 | |
392 | 392 | return preg_replace('/(GET|POST|PUT|DELETE|ALL)\#\|\#/', '', $url); |
@@ -428,8 +428,8 @@ discard block |
||
428 | 428 | private function checkAction($class, $method, array $params) { |
429 | 429 | $action = new \ReflectionMethod($class, $method); |
430 | 430 | |
431 | - foreach($action->getParameters() as $parameter) { |
|
432 | - if(!$parameter->isOptional() && !array_key_exists($parameter->getName(), $params)) { |
|
431 | + foreach ($action->getParameters() as $parameter) { |
|
432 | + if (!$parameter->isOptional() && !array_key_exists($parameter->getName(), $params)) { |
|
433 | 433 | throw new RouterException('Required parameters not sent'); |
434 | 434 | } |
435 | 435 | } |
@@ -446,25 +446,25 @@ discard block |
||
446 | 446 | */ |
447 | 447 | protected function executeCachedRoute($route, $action, $class, $params = NULL) |
448 | 448 | { |
449 | - Logger::log('Executing route ' . $route, LOG_INFO); |
|
449 | + Logger::log('Executing route '.$route, LOG_INFO); |
|
450 | 450 | Security::getInstance()->setSessionKey("__CACHE__", $action); |
451 | 451 | $cache = Cache::needCache(); |
452 | 452 | $execute = TRUE; |
453 | 453 | if (FALSE !== $cache && Config::getInstance()->getDebugMode() === FALSE) { |
454 | 454 | $cacheDataName = $this->cache->getRequestCacheHash(); |
455 | - $tmpDir = substr($cacheDataName, 0, 2) . DIRECTORY_SEPARATOR . substr($cacheDataName, 2, 2) . DIRECTORY_SEPARATOR; |
|
456 | - $cachedData = $this->cache->readFromCache("json" . DIRECTORY_SEPARATOR . $tmpDir . $cacheDataName, |
|
457 | - $cache, function () {}); |
|
455 | + $tmpDir = substr($cacheDataName, 0, 2).DIRECTORY_SEPARATOR.substr($cacheDataName, 2, 2).DIRECTORY_SEPARATOR; |
|
456 | + $cachedData = $this->cache->readFromCache("json".DIRECTORY_SEPARATOR.$tmpDir.$cacheDataName, |
|
457 | + $cache, function() {}); |
|
458 | 458 | if (NULL !== $cachedData) { |
459 | - $headers = $this->cache->readFromCache("json" . DIRECTORY_SEPARATOR . $tmpDir . $cacheDataName . ".headers", |
|
460 | - $cache, function () {}, Cache::JSON); |
|
459 | + $headers = $this->cache->readFromCache("json".DIRECTORY_SEPARATOR.$tmpDir.$cacheDataName.".headers", |
|
460 | + $cache, function() {}, Cache::JSON); |
|
461 | 461 | Template::getInstance()->renderCache($cachedData, $headers); |
462 | 462 | $execute = FALSE; |
463 | 463 | } |
464 | 464 | } |
465 | 465 | if ($execute) { |
466 | 466 | Logger::log(_('Start executing action'), LOG_DEBUG); |
467 | - if(false === call_user_func_array(array($class, $action['method']), $params)) { |
|
467 | + if (false === call_user_func_array(array($class, $action['method']), $params)) { |
|
468 | 468 | Logger::log(_('An error ocurred trying to execute the action'), LOG_ERR, [error_get_last()]); |
469 | 469 | } |
470 | 470 | } |
@@ -56,8 +56,10 @@ discard block |
||
56 | 56 | $_route = explode("/", $url['path']); |
57 | 57 | $_pattern = explode("/", $pattern); |
58 | 58 | $get = array(); |
59 | - if (!empty($_pattern)) foreach ($_pattern as $index => $component) { |
|
59 | + if (!empty($_pattern)) { |
|
60 | + foreach ($_pattern as $index => $component) { |
|
60 | 61 | $_get = array(); |
62 | + } |
|
61 | 63 | preg_match_all('/^\{(.*)\}$/i', $component, $_get); |
62 | 64 | if (!empty($_get[1]) && isset($_route[$index])) { |
63 | 65 | $get[array_pop($_get[1])] = $_route[$index]; |
@@ -151,12 +153,16 @@ discard block |
||
151 | 153 | $params = []; |
152 | 154 | $parameters = $method->getParameters(); |
153 | 155 | /** @var \ReflectionParameter $param */ |
154 | - if (count($parameters) > 0) foreach ($parameters as $param) { |
|
156 | + if (count($parameters) > 0) { |
|
157 | + foreach ($parameters as $param) { |
|
155 | 158 | if ($param->isOptional() && !is_array($param->getDefaultValue())) { |
156 | 159 | $params[$param->getName()] = $param->getDefaultValue(); |
160 | + } |
|
157 | 161 | $default = str_replace('{' . $param->getName() . '}', $param->getDefaultValue(), $regex); |
158 | 162 | } |
159 | - } else $default = $regex; |
|
163 | + } else { |
|
164 | + $default = $regex; |
|
165 | + } |
|
160 | 166 | |
161 | 167 | return array($regex, $default, $params); |
162 | 168 | } |
@@ -140,7 +140,7 @@ discard block |
||
140 | 140 | /** |
141 | 141 | * Método que extrae los parámetros de una función |
142 | 142 | * |
143 | - * @param array $sr |
|
143 | + * @param string[] $sr |
|
144 | 144 | * @param \ReflectionMethod $method |
145 | 145 | * |
146 | 146 | * @return array |
@@ -207,7 +207,7 @@ discard block |
||
207 | 207 | * |
208 | 208 | * @param string $docComments |
209 | 209 | * |
210 | - * @return bool |
|
210 | + * @return string |
|
211 | 211 | */ |
212 | 212 | public static function extractReflectionCacheability($docComments) |
213 | 213 | { |
@@ -20,7 +20,7 @@ discard block |
||
20 | 20 | public static function getClassToCall($action) |
21 | 21 | { |
22 | 22 | Logger::log('Getting class to call for executing the request action', LOG_DEBUG, $action); |
23 | - $actionClass = class_exists($action["class"]) ? $action["class"] : "\\" . $action["class"]; |
|
23 | + $actionClass = class_exists($action["class"]) ? $action["class"] : "\\".$action["class"]; |
|
24 | 24 | $class = (method_exists($actionClass, "getInstance")) ? $actionClass::getInstance() : new $actionClass; |
25 | 25 | return $class; |
26 | 26 | } |
@@ -106,7 +106,7 @@ discard block |
||
106 | 106 | $expr = preg_quote($expr, '/'); |
107 | 107 | $expr = str_replace('###', '(.*)', $expr); |
108 | 108 | $expr2 = preg_replace('/\(\.\*\)$/', '', $expr); |
109 | - $matched = preg_match('/^' . $expr . '\/?$/i', $path) || preg_match('/^' . $expr2 . '?$/i', $path); |
|
109 | + $matched = preg_match('/^'.$expr.'\/?$/i', $path) || preg_match('/^'.$expr2.'?$/i', $path); |
|
110 | 110 | return $matched; |
111 | 111 | } |
112 | 112 | |
@@ -117,8 +117,8 @@ discard block |
||
117 | 117 | */ |
118 | 118 | public static function extractDomainInfo(\ReflectionClass $class, $domain) |
119 | 119 | { |
120 | - $path = dirname($class->getFileName()) . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR; |
|
121 | - $path = realpath($path) . DIRECTORY_SEPARATOR; |
|
120 | + $path = dirname($class->getFileName()).DIRECTORY_SEPARATOR.'..'.DIRECTORY_SEPARATOR; |
|
121 | + $path = realpath($path).DIRECTORY_SEPARATOR; |
|
122 | 122 | $tpl_path = "templates"; |
123 | 123 | $public_path = "public"; |
124 | 124 | $model_path = "models"; |
@@ -128,12 +128,12 @@ discard block |
||
128 | 128 | $model_path = ucfirst($model_path); |
129 | 129 | } |
130 | 130 | if ($class->hasConstant("TPL")) { |
131 | - $tpl_path .= DIRECTORY_SEPARATOR . $class->getConstant("TPL"); |
|
131 | + $tpl_path .= DIRECTORY_SEPARATOR.$class->getConstant("TPL"); |
|
132 | 132 | } |
133 | 133 | return [ |
134 | - "template" => $path . $tpl_path, |
|
135 | - "model" => $path . $model_path, |
|
136 | - "public" => $path . $public_path, |
|
134 | + "template" => $path.$tpl_path, |
|
135 | + "model" => $path.$model_path, |
|
136 | + "public" => $path.$public_path, |
|
137 | 137 | ]; |
138 | 138 | } |
139 | 139 | |
@@ -155,9 +155,9 @@ discard block |
||
155 | 155 | if (count($parameters) > 0) foreach ($parameters as $param) { |
156 | 156 | if ($param->isOptional() && !is_array($param->getDefaultValue())) { |
157 | 157 | $params[$param->getName()] = $param->getDefaultValue(); |
158 | - $default = str_replace('{' . $param->getName() . '}', $param->getDefaultValue(), $regex); |
|
158 | + $default = str_replace('{'.$param->getName().'}', $param->getDefaultValue(), $regex); |
|
159 | 159 | } |
160 | - } else $default = $regex; |
|
160 | + }else $default = $regex; |
|
161 | 161 | |
162 | 162 | return array($regex, $default, $params); |
163 | 163 | } |
@@ -237,7 +237,7 @@ discard block |
||
237 | 237 | $default = str_replace('{__DOMAIN__}', $module, $default); |
238 | 238 | $httpMethod = RouterHelper::extractReflectionHttpMethod($docComments); |
239 | 239 | $label = RouterHelper::extractReflectionLabel(str_replace('{__API__}', $api, $docComments)); |
240 | - $route = $httpMethod . "#|#" . $regex; |
|
240 | + $route = $httpMethod."#|#".$regex; |
|
241 | 241 | $info = [ |
242 | 242 | "method" => $method->getName(), |
243 | 243 | "params" => $params, |
@@ -264,7 +264,7 @@ discard block |
||
264 | 264 | $default = Config::getInstance()->get('admin_action') ?: 'admin-login'; |
265 | 265 | |
266 | 266 | } |
267 | - if(null !== $default) { |
|
267 | + if (null !== $default) { |
|
268 | 268 | return Router::getInstance()->execute(Router::getInstance()->getRoute($default)); |
269 | 269 | } |
270 | 270 | return null; |
@@ -30,14 +30,14 @@ discard block |
||
30 | 30 | try { |
31 | 31 | $reflectionClass = new \ReflectionClass($this); |
32 | 32 | $properties = $reflectionClass->getProperties(\ReflectionProperty::IS_PUBLIC); |
33 | - if(count($properties) > 0) { |
|
33 | + if (count($properties) > 0) { |
|
34 | 34 | /** @var \ReflectionProperty $property */ |
35 | - foreach($properties as $property) { |
|
35 | + foreach ($properties as $property) { |
|
36 | 36 | $dto[$property->getName()] = $property->getValue($this); |
37 | 37 | } |
38 | 38 | } |
39 | - } catch(\Exception $e) { |
|
40 | - Logger::log(get_class($this) . ': ' . $e->getMessage(), LOG_ERR); |
|
39 | + }catch (\Exception $e) { |
|
40 | + Logger::log(get_class($this).': '.$e->getMessage(), LOG_ERR); |
|
41 | 41 | } |
42 | 42 | return $dto; |
43 | 43 | } |
@@ -57,9 +57,9 @@ discard block |
||
57 | 57 | */ |
58 | 58 | public function fromArray(array $object = array()) |
59 | 59 | { |
60 | - if(count($object) > 0) { |
|
61 | - foreach($object as $key => $value) { |
|
62 | - if(property_exists($this, $key)) { |
|
60 | + if (count($object) > 0) { |
|
61 | + foreach ($object as $key => $value) { |
|
62 | + if (property_exists($this, $key)) { |
|
63 | 63 | $this->$key = $value; |
64 | 64 | } |
65 | 65 | } |
@@ -33,10 +33,10 @@ |
||
33 | 33 | */ |
34 | 34 | private static function __init($instance) { |
35 | 35 | $loaded = false; |
36 | - if(method_exists($instance, 'isLoaded')) { |
|
36 | + if (method_exists($instance, 'isLoaded')) { |
|
37 | 37 | $loaded = $instance->isLoaded(); |
38 | 38 | } |
39 | - if(false === $loaded && method_exists($instance, "init")) { |
|
39 | + if (false === $loaded && method_exists($instance, "init")) { |
|
40 | 40 | $instance->init(); |
41 | 41 | } |
42 | 42 | } |
@@ -21,7 +21,7 @@ |
||
21 | 21 | $translations = array(); |
22 | 22 | if (file_exists($absoluteTranslationFileName)) { |
23 | 23 | @include($absoluteTranslationFileName); |
24 | - } else { |
|
24 | + }else { |
|
25 | 25 | Cache::getInstance()->storeData($absoluteTranslationFileName, "<?php \$translations = array();\n", Cache::TEXT, TRUE); |
26 | 26 | } |
27 | 27 |
@@ -7,10 +7,7 @@ |
||
7 | 7 | use PSFS\base\extension\AssetsTokenParser; |
8 | 8 | use PSFS\base\extension\TemplateFunctions; |
9 | 9 | use PSFS\base\types\helpers\ResponseHelper; |
10 | -use PSFS\base\types\helpers\SecurityHelper; |
|
11 | -use PSFS\base\types\helpers\TemplateHelper; |
|
12 | 10 | use PSFS\base\types\SingletonTrait; |
13 | -use PSFS\Dispatcher; |
|
14 | 11 | |
15 | 12 | |
16 | 13 | class Template |
@@ -130,7 +130,7 @@ discard block |
||
130 | 130 | ResponseHelper::setStatusHeader($this->status_code); |
131 | 131 | ResponseHelper::setAuthHeaders($this->public_zone); |
132 | 132 | ResponseHelper::setCookieHeaders($cookies); |
133 | - header('Content-type: ' . $contentType); |
|
133 | + header('Content-type: '.$contentType); |
|
134 | 134 | |
135 | 135 | } |
136 | 136 | |
@@ -146,15 +146,15 @@ discard block |
||
146 | 146 | Logger::log('Start output response'); |
147 | 147 | ob_start(); |
148 | 148 | $this->setReponseHeaders($contentType, $cookies); |
149 | - header('Content-length: ' . strlen($output)); |
|
149 | + header('Content-length: '.strlen($output)); |
|
150 | 150 | |
151 | 151 | $cache = Cache::needCache(); |
152 | 152 | if (false !== $cache && $this->status_code === Template::STATUS_OK && $this->debug === false) { |
153 | 153 | Logger::log('Saving output response into cache'); |
154 | 154 | $cacheName = $this->cache->getRequestCacheHash(); |
155 | - $tmpDir = substr($cacheName, 0, 2) . DIRECTORY_SEPARATOR . substr($cacheName, 2, 2) . DIRECTORY_SEPARATOR; |
|
156 | - $this->cache->storeData("json" . DIRECTORY_SEPARATOR . $tmpDir . $cacheName, $output); |
|
157 | - $this->cache->storeData("json" . DIRECTORY_SEPARATOR . $tmpDir . $cacheName . ".headers", headers_list(), Cache::JSON); |
|
155 | + $tmpDir = substr($cacheName, 0, 2).DIRECTORY_SEPARATOR.substr($cacheName, 2, 2).DIRECTORY_SEPARATOR; |
|
156 | + $this->cache->storeData("json".DIRECTORY_SEPARATOR.$tmpDir.$cacheName, $output); |
|
157 | + $this->cache->storeData("json".DIRECTORY_SEPARATOR.$tmpDir.$cacheName.".headers", headers_list(), Cache::JSON); |
|
158 | 158 | } |
159 | 159 | echo $output; |
160 | 160 | |
@@ -171,11 +171,11 @@ discard block |
||
171 | 171 | { |
172 | 172 | Logger::log('Close template render'); |
173 | 173 | Security::getInstance()->setSessionKey("lastRequest", array( |
174 | - "url" => Request::getInstance()->getRootUrl() . Request::requestUri(), |
|
174 | + "url" => Request::getInstance()->getRootUrl().Request::requestUri(), |
|
175 | 175 | "ts" => microtime(true), |
176 | 176 | )); |
177 | 177 | Security::getInstance()->updateSession(); |
178 | - Logger::log('End request: ' . Request::requestUri(), LOG_INFO); |
|
178 | + Logger::log('End request: '.Request::requestUri(), LOG_INFO); |
|
179 | 179 | exit; |
180 | 180 | } |
181 | 181 | |
@@ -224,7 +224,7 @@ discard block |
||
224 | 224 | $dump = ''; |
225 | 225 | try { |
226 | 226 | $dump = $this->tpl->render($tpl, $vars); |
227 | - } catch (\Exception $e) { |
|
227 | + }catch (\Exception $e) { |
|
228 | 228 | Logger::log($e->getMessage(), LOG_ERR); |
229 | 229 | } |
230 | 230 | return $dump; |
@@ -338,7 +338,7 @@ discard block |
||
338 | 338 | public function regenerateTemplates() |
339 | 339 | { |
340 | 340 | $this->generateTemplatesCache(); |
341 | - $domains = Cache::getInstance()->getDataFromFile(CONFIG_DIR . DIRECTORY_SEPARATOR . "domains.json", Cache::JSON, true); |
|
341 | + $domains = Cache::getInstance()->getDataFromFile(CONFIG_DIR.DIRECTORY_SEPARATOR."domains.json", Cache::JSON, true); |
|
342 | 342 | $translations = []; |
343 | 343 | if (is_array($domains)) { |
344 | 344 | $translations = $this->parsePathTranslations($domains); |
@@ -360,8 +360,8 @@ discard block |
||
360 | 360 | // force compilation |
361 | 361 | if ($file->isFile()) { |
362 | 362 | try { |
363 | - $this->tpl->load(str_replace($tplDir . '/', '', $file)); |
|
364 | - } catch (\Exception $e) { |
|
363 | + $this->tpl->load(str_replace($tplDir.'/', '', $file)); |
|
364 | + }catch (\Exception $e) { |
|
365 | 365 | Logger::log($e->getMessage(), LOG_ERR, ['file' => $e->getFile(), 'line' => $e->getLine()]); |
366 | 366 | } |
367 | 367 | } |
@@ -435,9 +435,9 @@ discard block |
||
435 | 435 | */ |
436 | 436 | private function loadDomains() |
437 | 437 | { |
438 | - $domains = Cache::getInstance()->getDataFromFile(CONFIG_DIR . DIRECTORY_SEPARATOR . 'domains.json', Cache::JSON, true); |
|
439 | - if(null !== $domains) { |
|
440 | - foreach($domains as $domain => $paths) { |
|
438 | + $domains = Cache::getInstance()->getDataFromFile(CONFIG_DIR.DIRECTORY_SEPARATOR.'domains.json', Cache::JSON, true); |
|
439 | + if (null !== $domains) { |
|
440 | + foreach ($domains as $domain => $paths) { |
|
441 | 441 | $this->addPath($paths['template'], preg_replace('/(@|\/)/', '', $domain)); |
442 | 442 | } |
443 | 443 | } |
@@ -452,7 +452,7 @@ discard block |
||
452 | 452 | $this->cache = Cache::getInstance(); |
453 | 453 | $loader = new \Twig_Loader_Filesystem(Config::getInstance()->getTemplatePath()); |
454 | 454 | $this->tpl = new \Twig_Environment($loader, array( |
455 | - 'cache' => Config::getInstance()->getCachePath() . DIRECTORY_SEPARATOR . 'twig', |
|
455 | + 'cache' => Config::getInstance()->getCachePath().DIRECTORY_SEPARATOR.'twig', |
|
456 | 456 | 'debug' => (bool)$this->debug, |
457 | 457 | 'auto_reload' => Config::getParam('twig.auto_reload', TRUE), |
458 | 458 | )); |
@@ -38,7 +38,7 @@ discard block |
||
38 | 38 | unset($_SERVER["PHP_AUTH_USER"]); |
39 | 39 | unset($_SERVER["PHP_AUTH_PW"]); |
40 | 40 | header_remove("Authorization"); |
41 | - } else { |
|
41 | + }else { |
|
42 | 42 | header('Authorization:'); |
43 | 43 | } |
44 | 44 | } |
@@ -66,9 +66,9 @@ discard block |
||
66 | 66 | Logger::log('Adding debug headers to render response'); |
67 | 67 | $vars["__DEBUG__"]["includes"] = get_included_files(); |
68 | 68 | $vars["__DEBUG__"]["trace"] = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS); |
69 | - header('X-PSFS-DEBUG-TS: ' . Dispatcher::getInstance()->getTs() . ' s'); |
|
70 | - header('X-PSFS-DEBUG-MEM: ' . Dispatcher::getInstance()->getMem('MBytes') . ' MBytes'); |
|
71 | - header('X-PSFS-DEBUG-FILES: ' . count(get_included_files()) . ' files opened'); |
|
69 | + header('X-PSFS-DEBUG-TS: '.Dispatcher::getInstance()->getTs().' s'); |
|
70 | + header('X-PSFS-DEBUG-MEM: '.Dispatcher::getInstance()->getMem('MBytes').' MBytes'); |
|
71 | + header('X-PSFS-DEBUG-FILES: '.count(get_included_files()).' files opened'); |
|
72 | 72 | } |
73 | 73 | |
74 | 74 | return $vars; |
@@ -22,7 +22,7 @@ discard block |
||
22 | 22 | * @return string |
23 | 23 | */ |
24 | 24 | public static function showAdminManager() { |
25 | - if(Request::getInstance()->getMethod() != 'GET') { |
|
25 | + if (Request::getInstance()->getMethod() != 'GET') { |
|
26 | 26 | return self::updateAdminUsers(); |
27 | 27 | } |
28 | 28 | $admins = AdminServices::getInstance()->getAdmins(); |
@@ -60,7 +60,7 @@ discard block |
||
60 | 60 | Logger::log('Configuration saved successful'); |
61 | 61 | Security::getInstance()->setFlash("callback_message", _("Usuario agregado correctamente")); |
62 | 62 | Security::getInstance()->setFlash("callback_route", Router::getInstance()->getRoute("admin", true)); |
63 | - } else { |
|
63 | + }else { |
|
64 | 64 | throw new ConfigException(_('Error al guardar los administradores, prueba a cambiar los permisos')); |
65 | 65 | } |
66 | 66 | } |
@@ -94,9 +94,9 @@ discard block |
||
94 | 94 | */ |
95 | 95 | public function adminLogin($route = null) |
96 | 96 | { |
97 | - if($this->isAdmin()) { |
|
97 | + if ($this->isAdmin()) { |
|
98 | 98 | return $this->redirect('admin'); |
99 | - } else { |
|
99 | + }else { |
|
100 | 100 | return Admin::staticAdminLogon($route); |
101 | 101 | } |
102 | 102 | } |
@@ -128,7 +128,7 @@ discard block |
||
128 | 128 | $cookies = array( |
129 | 129 | array( |
130 | 130 | "name" => Security::getInstance()->getHash(), |
131 | - "value" => base64_encode($form->getFieldValue("user") . ":" . $form->getFieldValue("pass")), |
|
131 | + "value" => base64_encode($form->getFieldValue("user").":".$form->getFieldValue("pass")), |
|
132 | 132 | "expire" => time() + 3600, |
133 | 133 | "http" => true, |
134 | 134 | ) |
@@ -139,7 +139,7 @@ discard block |
||
139 | 139 | 'status_message' => _("Acceso permitido... redirigiendo!!"), |
140 | 140 | 'delay' => 1, |
141 | 141 | ); |
142 | - } else { |
|
142 | + }else { |
|
143 | 143 | $form->setError("user", _("El usuario no tiene acceso a la web")); |
144 | 144 | } |
145 | 145 | } |