@@ -62,7 +62,7 @@ discard block |
||
62 | 62 | { |
63 | 63 | if (preg_match('/^asc$/i', $direction)) { |
64 | 64 | return self::ASC; |
65 | - } else { |
|
65 | + }else { |
|
66 | 66 | return self::DESC; |
67 | 67 | } |
68 | 68 | } |
@@ -81,7 +81,7 @@ discard block |
||
81 | 81 | */ |
82 | 82 | public function fromArray(array $object = []) |
83 | 83 | { |
84 | - foreach($object as $field => $order) { |
|
84 | + foreach ($object as $field => $order) { |
|
85 | 85 | $this->addOrder($field, $order); |
86 | 86 | } |
87 | 87 | } |
@@ -19,7 +19,7 @@ discard block |
||
19 | 19 | public function __construct($hydrate = true) |
20 | 20 | { |
21 | 21 | parent::__construct(); |
22 | - if($hydrate) { |
|
22 | + if ($hydrate) { |
|
23 | 23 | $this->fromArray(Request::getInstance()->getData()); |
24 | 24 | } |
25 | 25 | } |
@@ -47,23 +47,23 @@ discard block |
||
47 | 47 | /** @var \ReflectionProperty $property */ |
48 | 48 | foreach ($properties as $property) { |
49 | 49 | $value = $property->getValue($this); |
50 | - if(is_object($value) && method_exists($value, 'toArray')) { |
|
50 | + if (is_object($value) && method_exists($value, 'toArray')) { |
|
51 | 51 | $dto[$property->getName()] = $value->toArray(); |
52 | - } elseif(is_array($value)) { |
|
53 | - foreach($value as &$arrValue) { |
|
54 | - if($arrValue instanceof Dto) { |
|
52 | + } elseif (is_array($value)) { |
|
53 | + foreach ($value as &$arrValue) { |
|
54 | + if ($arrValue instanceof Dto) { |
|
55 | 55 | $arrValue = $arrValue->toArray(); |
56 | 56 | } |
57 | 57 | } |
58 | 58 | $dto[$property->getName()] = $value; |
59 | - } else { |
|
59 | + }else { |
|
60 | 60 | $type = InjectorHelper::extractVarType($property->getDocComment()); |
61 | 61 | $dto[$property->getName()] = $this->checkCastedValue($property->getValue($this), $type); |
62 | 62 | } |
63 | 63 | } |
64 | 64 | } |
65 | - } catch (\Exception $e) { |
|
66 | - Logger::log(get_class($this) . ': ' . $e->getMessage(), LOG_ERR); |
|
65 | + }catch (\Exception $e) { |
|
66 | + Logger::log(get_class($this).': '.$e->getMessage(), LOG_ERR); |
|
67 | 67 | } |
68 | 68 | return $dto; |
69 | 69 | } |
@@ -86,26 +86,26 @@ discard block |
||
86 | 86 | protected function parseDtoField(array $properties, $key, $value = null) { |
87 | 87 | list($type, $isArray) = $this->extractTypes($properties, $key); |
88 | 88 | $reflector = (class_exists($type)) ? new \ReflectionClass($type) : null; |
89 | - if(null !== $reflector && $reflector->isSubclassOf(Dto::class)) { |
|
90 | - if(null !== $value && is_array($value)) { |
|
91 | - if(!array_key_exists($type, $this->__cache)) { |
|
89 | + if (null !== $reflector && $reflector->isSubclassOf(Dto::class)) { |
|
90 | + if (null !== $value && is_array($value)) { |
|
91 | + if (!array_key_exists($type, $this->__cache)) { |
|
92 | 92 | $this->__cache[$type] = new $type(false); |
93 | 93 | } |
94 | - if($isArray) { |
|
94 | + if ($isArray) { |
|
95 | 95 | $this->$key = []; |
96 | - foreach($value as $data) { |
|
97 | - if(null !== $data && is_array($data)) { |
|
96 | + foreach ($value as $data) { |
|
97 | + if (null !== $data && is_array($data)) { |
|
98 | 98 | $dto = clone $this->__cache[$type]; |
99 | 99 | $dto->fromArray($data); |
100 | 100 | array_push($this->$key, $dto); |
101 | 101 | } |
102 | 102 | } |
103 | - } else { |
|
103 | + }else { |
|
104 | 104 | $this->$key = clone $this->__cache[$type]; |
105 | 105 | $this->$key->fromArray($value); |
106 | 106 | } |
107 | 107 | } |
108 | - } else { |
|
108 | + }else { |
|
109 | 109 | $this->castValue($key, $value, $type); |
110 | 110 | } |
111 | 111 | } |
@@ -62,10 +62,10 @@ discard block |
||
62 | 62 | if ($module === $requestModule && !preg_match('/^ROOT/i', $module)) { |
63 | 63 | $modules = [ |
64 | 64 | 'name' => $module, |
65 | - 'path' => realpath(dirname($info['base'] . DIRECTORY_SEPARATOR . '..')), |
|
65 | + 'path' => realpath(dirname($info['base'].DIRECTORY_SEPARATOR.'..')), |
|
66 | 66 | ]; |
67 | 67 | } |
68 | - } catch (Exception $e) { |
|
68 | + }catch (Exception $e) { |
|
69 | 69 | $modules[] = $e->getMessage(); |
70 | 70 | } |
71 | 71 | } |
@@ -83,7 +83,7 @@ discard block |
||
83 | 83 | */ |
84 | 84 | public function extractApiEndpoints(array $module) |
85 | 85 | { |
86 | - $modulePath = $module['path'] . DIRECTORY_SEPARATOR . 'Api'; |
|
86 | + $modulePath = $module['path'].DIRECTORY_SEPARATOR.'Api'; |
|
87 | 87 | $moduleName = $module['name']; |
88 | 88 | $endpoints = []; |
89 | 89 | if (file_exists($modulePath)) { |
@@ -93,7 +93,7 @@ discard block |
||
93 | 93 | /** @var SplFileInfo $file */ |
94 | 94 | foreach ($finder as $file) { |
95 | 95 | $filename = str_replace([$modulePath, '/'], ['', '\\'], $file->getPathname()); |
96 | - $namespace = "\\{$moduleName}\\Api" . str_replace('.php', '', $filename); |
|
96 | + $namespace = "\\{$moduleName}\\Api".str_replace('.php', '', $filename); |
|
97 | 97 | $info = $this->extractApiInfo($namespace, $moduleName); |
98 | 98 | if (!empty($info)) { |
99 | 99 | $endpoints[$namespace] = $info; |
@@ -123,7 +123,7 @@ discard block |
||
123 | 123 | if (NULL !== $mInfo) { |
124 | 124 | $info[] = $mInfo; |
125 | 125 | } |
126 | - } catch (Exception $e) { |
|
126 | + }catch (Exception $e) { |
|
127 | 127 | Logger::log($e->getMessage(), LOG_ERR); |
128 | 128 | } |
129 | 129 | } |
@@ -241,7 +241,7 @@ discard block |
||
241 | 241 | $payload = $this->extractModelFields($namespace); |
242 | 242 | $reflector = new ReflectionClass($namespace); |
243 | 243 | $shortName = $reflector->getShortName(); |
244 | - } else { |
|
244 | + }else { |
|
245 | 245 | $namespace = $model; |
246 | 246 | $shortName = $model; |
247 | 247 | } |
@@ -341,7 +341,7 @@ discard block |
||
341 | 341 | } elseif (null !== $reflector && $reflector->isSubclassOf(self::DTO_INTERFACE)) { |
342 | 342 | $payload = $this->extractDtoProperties($namespace); |
343 | 343 | } |
344 | - } catch (Exception $e) { |
|
344 | + }catch (Exception $e) { |
|
345 | 345 | Logger::log($e->getMessage(), LOG_ERR); |
346 | 346 | } |
347 | 347 | |
@@ -372,7 +372,7 @@ discard block |
||
372 | 372 | $return = $this->extractReturn($modelNamespace, $docComments); |
373 | 373 | $url = array_pop($route); |
374 | 374 | $methodInfo = [ |
375 | - 'url' => str_replace('/' . $module . '/api', '', $url), |
|
375 | + 'url' => str_replace('/'.$module.'/api', '', $url), |
|
376 | 376 | 'method' => $info['http'], |
377 | 377 | 'description' => $info['label'], |
378 | 378 | 'return' => $return, |
@@ -383,7 +383,7 @@ discard block |
||
383 | 383 | $this->setRequestParams($method, $methodInfo, $modelNamespace, $docComments); |
384 | 384 | $this->setQueryParams($method, $methodInfo); |
385 | 385 | $this->setRequestHeaders($reflection, $methodInfo); |
386 | - } catch (Exception $e) { |
|
386 | + }catch (Exception $e) { |
|
387 | 387 | Logger::log($e->getMessage(), LOG_ERR); |
388 | 388 | } |
389 | 389 | } |
@@ -455,10 +455,10 @@ discard block |
||
455 | 455 | $formatted = [ |
456 | 456 | "swagger" => "2.0", |
457 | 457 | "host" => preg_replace('/^(http|https)\:\/\/(.*)\/$/i', '$2', Router::getInstance()->getRoute('', true)), |
458 | - "basePath" => '/' . $module['name'] . '/api', |
|
458 | + "basePath" => '/'.$module['name'].'/api', |
|
459 | 459 | "schemes" => [Request::getInstance()->getServer('HTTPS') === 'on' ? 'https' : 'http'], |
460 | 460 | "info" => [ |
461 | - "title" => t('Documentación API módulo ') . $module['name'], |
|
461 | + "title" => t('Documentación API módulo ').$module['name'], |
|
462 | 462 | "version" => Config::getParam('api.version', '1.0.0'), |
463 | 463 | "contact" => [ |
464 | 464 | "name" => Config::getParam("author", "Fran López"), |
@@ -471,7 +471,7 @@ discard block |
||
471 | 471 | foreach ($endpoints as $model) { |
472 | 472 | foreach ($model as $endpoint) { |
473 | 473 | if (!preg_match('/^\/(admin|api)\//i', $endpoint['url']) && strlen($endpoint['url'])) { |
474 | - $url = preg_replace('/\/' . $module['name'] . '\/api/i', '', $endpoint['url']); |
|
474 | + $url = preg_replace('/\/'.$module['name'].'\/api/i', '', $endpoint['url']); |
|
475 | 475 | $description = $endpoint['description']; |
476 | 476 | $method = strtolower($endpoint['method']); |
477 | 477 | $paths[$url][$method] = [ |
@@ -512,7 +512,7 @@ discard block |
||
512 | 512 | } |
513 | 513 | } |
514 | 514 | ksort($dtos); |
515 | - uasort($paths, function ($path1, $path2) { |
|
515 | + uasort($paths, function($path1, $path2) { |
|
516 | 516 | $key1 = array_keys($path1)[0]; |
517 | 517 | $key2 = array_keys($path2)[0]; |
518 | 518 | return strcmp($path1[$key1]['tags'][0], $path2[$key2]['tags'][0]); |
@@ -532,7 +532,7 @@ discard block |
||
532 | 532 | protected function extractDtoName($dto, $isArray = false) |
533 | 533 | { |
534 | 534 | $dto = explode('\\', $dto); |
535 | - $modelDto = array_pop($dto) . "Dto"; |
|
535 | + $modelDto = array_pop($dto)."Dto"; |
|
536 | 536 | if ($isArray) { |
537 | 537 | $modelDto .= "List"; |
538 | 538 | } |
@@ -631,7 +631,7 @@ discard block |
||
631 | 631 | foreach ($method->getParameters() as $parameter) { |
632 | 632 | $parameterName = $parameter->getName(); |
633 | 633 | $types = []; |
634 | - preg_match_all('/\@param\ (.*)\ \$' . $parameterName . '$/im', $docComments, $types); |
|
634 | + preg_match_all('/\@param\ (.*)\ \$'.$parameterName.'$/im', $docComments, $types); |
|
635 | 635 | if (count($types) > 1 && count($types[1]) > 0) { |
636 | 636 | $methodInfo['parameters'][$parameterName] = $types[1][0]; |
637 | 637 | } |
@@ -653,13 +653,13 @@ discard block |
||
653 | 653 | $modelDto['objects'][$dtoName][$param] = [ |
654 | 654 | 'type' => 'array', |
655 | 655 | 'items' => [ |
656 | - '$ref' => '#/definitions/' . $info['type'], |
|
656 | + '$ref' => '#/definitions/'.$info['type'], |
|
657 | 657 | ] |
658 | 658 | ]; |
659 | - } else { |
|
659 | + }else { |
|
660 | 660 | $modelDto['objects'][$dtoName][$param] = [ |
661 | 661 | 'type' => 'object', |
662 | - '$ref' => '#/definitions/' . $info['type'], |
|
662 | + '$ref' => '#/definitions/'.$info['type'], |
|
663 | 663 | ]; |
664 | 664 | } |
665 | 665 | $modelDto['objects'][$info['class']] = $info['properties']; |
@@ -667,7 +667,7 @@ discard block |
||
667 | 667 | if (array_key_exists('objects', $paramDto)) { |
668 | 668 | $modelDto['objects'] = array_merge($modelDto['objects'], $paramDto['objects']); |
669 | 669 | } |
670 | - } else { |
|
670 | + }else { |
|
671 | 671 | $modelDto['objects'][$dtoName][$param] = $info; |
672 | 672 | } |
673 | 673 | } |
@@ -57,7 +57,7 @@ |
||
57 | 57 | $router->simpatize(); |
58 | 58 | Security::getInstance()->setFlash("callback_message", t("Rutas generadas correctamente")); |
59 | 59 | Security::getInstance()->setFlash("callback_route", $this->getRoute("admin-routes", true)); |
60 | - } catch (Exception $e) { |
|
60 | + }catch (Exception $e) { |
|
61 | 61 | Logger::log($e->getMessage(), LOG_ERR); |
62 | 62 | Security::getInstance()->setFlash("callback_message", t("Algo no ha salido bien, revisa los logs")); |
63 | 63 | Security::getInstance()->setFlash("callback_route", $this->getRoute("admin-routes", true)); |
@@ -33,7 +33,7 @@ discard block |
||
33 | 33 | foreach ($domains as $domain => $routes) { |
34 | 34 | $pDomain = str_replace('@', '', $domain); |
35 | 35 | $pDomain = str_replace('/', '', $pDomain); |
36 | - $response[] = strtolower($pDomain) . '.api.secret'; |
|
36 | + $response[] = strtolower($pDomain).'.api.secret'; |
|
37 | 37 | } |
38 | 38 | return $this->json($response); |
39 | 39 | } |
@@ -49,7 +49,7 @@ discard block |
||
49 | 49 | */ |
50 | 50 | public function config() |
51 | 51 | { |
52 | - Logger::log("Config loaded executed by " . $this->getRequest()->getRequestUri()); |
|
52 | + Logger::log("Config loaded executed by ".$this->getRequest()->getRequestUri()); |
|
53 | 53 | /* @var $form ConfigForm */ |
54 | 54 | $form = new ConfigForm(Router::getInstance()->getRoute('admin-config'), Config::$required, Config::$optional, Config::getInstance()->dumpConfig()); |
55 | 55 | $form->build(); |
@@ -86,7 +86,7 @@ discard block |
||
86 | 86 | } |
87 | 87 | Security::getInstance()->setFlash("callback_message", t("Configuración actualizada correctamente")); |
88 | 88 | Security::getInstance()->setFlash("callback_route", $this->getRoute("admin-config", true)); |
89 | - } else { |
|
89 | + }else { |
|
90 | 90 | throw new HttpException(t('Error al guardar la configuración, prueba a cambiar los permisos'), 403); |
91 | 91 | } |
92 | 92 | } |
@@ -34,7 +34,7 @@ discard block |
||
34 | 34 | */ |
35 | 35 | public function generateModule() |
36 | 36 | { |
37 | - Logger::log("Arranque generador de módulos al solicitar " . $this->getRequest()->getRequestUri()); |
|
37 | + Logger::log("Arranque generador de módulos al solicitar ".$this->getRequest()->getRequestUri()); |
|
38 | 38 | /* @var $form ConfigForm */ |
39 | 39 | $form = new ModuleForm(); |
40 | 40 | $form->build(); |
@@ -66,8 +66,8 @@ discard block |
||
66 | 66 | $this->gen->createStructureModule($module, false, $type, $apiClass); |
67 | 67 | Security::getInstance()->setFlash("callback_message", str_replace("%s", $module, t("Módulo %s generado correctamente"))); |
68 | 68 | // Security::getInstance()->setFlash("callback_route", $this->getRoute("admin-module", true)); |
69 | - } catch (Exception $e) { |
|
70 | - Logger::log($e->getMessage() . " [" . $e->getFile() . ":" . $e->getLine() . "]"); |
|
69 | + }catch (Exception $e) { |
|
70 | + Logger::log($e->getMessage()." [".$e->getFile().":".$e->getLine()."]"); |
|
71 | 71 | Security::getInstance()->setFlash("callback_message", htmlentities($e->getMessage())); |
72 | 72 | } |
73 | 73 | } |
@@ -26,7 +26,7 @@ discard block |
||
26 | 26 | */ |
27 | 27 | public function __construct() |
28 | 28 | { |
29 | - Logger::log(static::class . ' constructor invoked'); |
|
29 | + Logger::log(static::class.' constructor invoked'); |
|
30 | 30 | $this->init(); |
31 | 31 | } |
32 | 32 | |
@@ -85,14 +85,14 @@ discard block |
||
85 | 85 | $calledClass = static::class; |
86 | 86 | try { |
87 | 87 | $instance = InjectorHelper::constructInjectableInstance($variable, $singleton, $classNameSpace, $calledClass); |
88 | - $setter = 'set' . ucfirst($variable); |
|
88 | + $setter = 'set'.ucfirst($variable); |
|
89 | 89 | if (method_exists($calledClass, $setter)) { |
90 | 90 | $this->$setter($instance); |
91 | - } else { |
|
91 | + }else { |
|
92 | 92 | $this->$variable = $instance; |
93 | 93 | } |
94 | - } catch (Exception $e) { |
|
95 | - Logger::log($e->getMessage() . ': ' . $e->getFile() . ' [' . $e->getLine() . ']', LOG_ERR); |
|
94 | + }catch (Exception $e) { |
|
95 | + Logger::log($e->getMessage().': '.$e->getFile().' ['.$e->getLine().']', LOG_ERR); |
|
96 | 96 | throw $e; |
97 | 97 | } |
98 | 98 | return $this; |
@@ -107,7 +107,7 @@ discard block |
||
107 | 107 | { |
108 | 108 | if (!$this->isLoaded()) { |
109 | 109 | $filename = sha1(get_class($this)); |
110 | - $cacheFilename = 'reflections' . DIRECTORY_SEPARATOR . substr($filename, 0, 2) . DIRECTORY_SEPARATOR . substr($filename, 2, 2) . DIRECTORY_SEPARATOR . $filename . '.json'; |
|
110 | + $cacheFilename = 'reflections'.DIRECTORY_SEPARATOR.substr($filename, 0, 2).DIRECTORY_SEPARATOR.substr($filename, 2, 2).DIRECTORY_SEPARATOR.$filename.'.json'; |
|
111 | 111 | /** @var Cache $cacheService */ |
112 | 112 | $cacheService = Cache::getInstance(); |
113 | 113 | /** @var Config $configService */ |
@@ -125,8 +125,8 @@ discard block |
||
125 | 125 | } |
126 | 126 | } |
127 | 127 | $this->setLoaded(); |
128 | - } else { |
|
129 | - Logger::log(get_class($this) . ' already loaded', LOG_INFO); |
|
128 | + }else { |
|
129 | + Logger::log(get_class($this).' already loaded', LOG_INFO); |
|
130 | 130 | } |
131 | 131 | } |
132 | 132 | } |
@@ -122,7 +122,7 @@ discard block |
||
122 | 122 | */ |
123 | 123 | public static function header($name, $default = null) |
124 | 124 | { |
125 | - return self::getInstance()->getHeader($name, $default); |
|
125 | + return self::getInstance()->getHeader($name, $default); |
|
126 | 126 | } |
127 | 127 | |
128 | 128 | /** |
@@ -135,10 +135,10 @@ discard block |
||
135 | 135 | $header = null; |
136 | 136 | if ($this->hasHeader($name)) { |
137 | 137 | $header = $this->header[$name]; |
138 | - } else if(array_key_exists('h_' . strtolower($name), $this->query)) { |
|
139 | - $header = $this->query['h_' . strtolower($name)]; |
|
140 | - } else if(array_key_exists('HTTP_' . strtoupper(str_replace('-', '_', $name)), $this->server)) { |
|
141 | - $header = $this->getServer('HTTP_' . strtoupper(str_replace('-', '_', $name))); |
|
138 | + }else if (array_key_exists('h_'.strtolower($name), $this->query)) { |
|
139 | + $header = $this->query['h_'.strtolower($name)]; |
|
140 | + }else if (array_key_exists('HTTP_'.strtoupper(str_replace('-', '_', $name)), $this->server)) { |
|
141 | + $header = $this->getServer('HTTP_'.strtoupper(str_replace('-', '_', $name))); |
|
142 | 142 | } |
143 | 143 | return $header ?: $default; |
144 | 144 | } |
@@ -242,7 +242,7 @@ discard block |
||
242 | 242 | $url = $this->getServer('HTTP_ORIGIN'); |
243 | 243 | } |
244 | 244 | ob_start(); |
245 | - header('Location: ' . $url); |
|
245 | + header('Location: '.$url); |
|
246 | 246 | ob_end_clean(); |
247 | 247 | Security::getInstance()->updateSession(); |
248 | 248 | exit(t('Redirect...')); |
@@ -258,7 +258,7 @@ discard block |
||
258 | 258 | $url = $this->getServerName(); |
259 | 259 | $protocol = $hasProtocol ? $this->getProtocol() : ''; |
260 | 260 | if (!empty($protocol)) { |
261 | - $url = $protocol . $url; |
|
261 | + $url = $protocol.$url; |
|
262 | 262 | } |
263 | 263 | $url = $this->checkServerPort($url); |
264 | 264 | return $url; |
@@ -272,15 +272,15 @@ discard block |
||
272 | 272 | { |
273 | 273 | $port = (integer)$this->getServer('SERVER_PORT'); |
274 | 274 | $host = $this->getServer('HTTP_HOST'); |
275 | - if(!empty($host)) { |
|
275 | + if (!empty($host)) { |
|
276 | 276 | $parts = explode(':', $host); |
277 | 277 | $hostPort = (integer)end($parts); |
278 | - if(count($parts) > 1 && $hostPort !== $port) { |
|
278 | + if (count($parts) > 1 && $hostPort !== $port) { |
|
279 | 279 | $port = $hostPort; |
280 | 280 | } |
281 | 281 | } |
282 | 282 | if (!in_array($port, [80, 443], true)) { |
283 | - $url .= ':' . $port; |
|
283 | + $url .= ':'.$port; |
|
284 | 284 | } |
285 | 285 | return $url; |
286 | 286 | } |
@@ -84,11 +84,11 @@ discard block |
||
84 | 84 | */ |
85 | 85 | public function init() |
86 | 86 | { |
87 | - list($this->routing, $this->slugs) = $this->cache->getDataFromFile(CONFIG_DIR . DIRECTORY_SEPARATOR . 'urls.json', $this->cacheType, TRUE); |
|
87 | + list($this->routing, $this->slugs) = $this->cache->getDataFromFile(CONFIG_DIR.DIRECTORY_SEPARATOR.'urls.json', $this->cacheType, TRUE); |
|
88 | 88 | if (empty($this->routing) || Config::getParam('debug', true)) { |
89 | 89 | $this->debugLoad(); |
90 | - } else { |
|
91 | - $this->domains = $this->cache->getDataFromFile(CONFIG_DIR . DIRECTORY_SEPARATOR . 'domains.json', $this->cacheType, TRUE); |
|
90 | + }else { |
|
91 | + $this->domains = $this->cache->getDataFromFile(CONFIG_DIR.DIRECTORY_SEPARATOR.'domains.json', $this->cacheType, TRUE); |
|
92 | 92 | } |
93 | 93 | $this->checkExternalModules(false); |
94 | 94 | $this->setLoaded(); |
@@ -128,9 +128,9 @@ discard block |
||
128 | 128 | } |
129 | 129 | |
130 | 130 | $notFoundRoute = Config::getParam('route.404'); |
131 | - if(null !== $notFoundRoute) { |
|
131 | + if (null !== $notFoundRoute) { |
|
132 | 132 | Request::getInstance()->redirect($this->getRoute($notFoundRoute, true)); |
133 | - } else { |
|
133 | + }else { |
|
134 | 134 | return $template->render('error.html.twig', array( |
135 | 135 | 'exception' => $exception, |
136 | 136 | 'trace' => $exception->getTraceAsString(), |
@@ -181,12 +181,12 @@ discard block |
||
181 | 181 | try { |
182 | 182 | //Search action and execute |
183 | 183 | return $this->searchAction($route); |
184 | - } catch (AccessDeniedException $e) { |
|
185 | - Logger::log(t('Solicitamos credenciales de acceso a zona restringida'), LOG_WARNING, ['file' => $e->getFile() . '[' . $e->getLine() . ']']); |
|
184 | + }catch (AccessDeniedException $e) { |
|
185 | + Logger::log(t('Solicitamos credenciales de acceso a zona restringida'), LOG_WARNING, ['file' => $e->getFile().'['.$e->getLine().']']); |
|
186 | 186 | return Admin::staticAdminLogon($route); |
187 | - } catch (RouterException $r) { |
|
187 | + }catch (RouterException $r) { |
|
188 | 188 | Logger::log($r->getMessage(), LOG_WARNING); |
189 | - } catch (Exception $e) { |
|
189 | + }catch (Exception $e) { |
|
190 | 190 | Logger::log($e->getMessage(), LOG_ERR); |
191 | 191 | throw $e; |
192 | 192 | } |
@@ -204,7 +204,7 @@ discard block |
||
204 | 204 | */ |
205 | 205 | protected function searchAction($route) |
206 | 206 | { |
207 | - Inspector::stats('[Router] Searching action to execute: ' . $route, Inspector::SCOPE_DEBUG); |
|
207 | + Inspector::stats('[Router] Searching action to execute: '.$route, Inspector::SCOPE_DEBUG); |
|
208 | 208 | //Revisamos si tenemos la ruta registrada |
209 | 209 | $parts = parse_url($route); |
210 | 210 | $path = array_key_exists('path', $parts) ? $parts['path'] : $route; |
@@ -219,12 +219,12 @@ discard block |
||
219 | 219 | /** @var $class Controller */ |
220 | 220 | $class = RouterHelper::getClassToCall($action); |
221 | 221 | try { |
222 | - if($this->checkRequirements($action, $get)) { |
|
222 | + if ($this->checkRequirements($action, $get)) { |
|
223 | 223 | return $this->executeCachedRoute($route, $action, $class, $get); |
224 | - } else { |
|
224 | + }else { |
|
225 | 225 | throw new RouterException(t('La ruta no es válida'), 400); |
226 | 226 | } |
227 | - } catch (Exception $e) { |
|
227 | + }catch (Exception $e) { |
|
228 | 228 | Logger::log($e->getMessage(), LOG_ERR); |
229 | 229 | throw $e; |
230 | 230 | } |
@@ -240,15 +240,15 @@ discard block |
||
240 | 240 | */ |
241 | 241 | private function checkRequirements(array $action, $params = []) { |
242 | 242 | Inspector::stats('[Router] Checking request requirements', Inspector::SCOPE_DEBUG); |
243 | - if(!empty($params) && !empty($action['requirements'])) { |
|
243 | + if (!empty($params) && !empty($action['requirements'])) { |
|
244 | 244 | $checked = 0; |
245 | - foreach(array_keys($params) as $key) { |
|
246 | - if(in_array($key, $action['requirements'], true)) { |
|
245 | + foreach (array_keys($params) as $key) { |
|
246 | + if (in_array($key, $action['requirements'], true)) { |
|
247 | 247 | $checked++; |
248 | 248 | } |
249 | 249 | } |
250 | 250 | $valid = count($action['requirements']) === $checked; |
251 | - } else { |
|
251 | + }else { |
|
252 | 252 | $valid = true; |
253 | 253 | } |
254 | 254 | return $valid; |
@@ -299,14 +299,14 @@ discard block |
||
299 | 299 | $this->checkExternalModules(); |
300 | 300 | if (file_exists($modulesPath)) { |
301 | 301 | $modules = $this->finder->directories()->in($modulesPath)->depth(0); |
302 | - if($modules->hasResults()) { |
|
302 | + if ($modules->hasResults()) { |
|
303 | 303 | foreach ($modules->getIterator() as $modulePath) { |
304 | 304 | $module = $modulePath->getBasename(); |
305 | - $this->routing = $this->inspectDir($modulesPath . DIRECTORY_SEPARATOR . $module, $module, $this->routing); |
|
305 | + $this->routing = $this->inspectDir($modulesPath.DIRECTORY_SEPARATOR.$module, $module, $this->routing); |
|
306 | 306 | } |
307 | 307 | } |
308 | 308 | } |
309 | - $this->cache->storeData(CONFIG_DIR . DIRECTORY_SEPARATOR . 'domains.json', $this->domains, Cache::JSON, TRUE); |
|
309 | + $this->cache->storeData(CONFIG_DIR.DIRECTORY_SEPARATOR.'domains.json', $this->domains, Cache::JSON, TRUE); |
|
310 | 310 | } |
311 | 311 | |
312 | 312 | /** |
@@ -323,7 +323,7 @@ discard block |
||
323 | 323 | $homeParams = NULL; |
324 | 324 | foreach ($this->routing as $pattern => $params) { |
325 | 325 | list($method, $route) = RouterHelper::extractHttpRoute($pattern); |
326 | - if (preg_match('/' . preg_quote($route, '/') . '$/i', '/' . $home)) { |
|
326 | + if (preg_match('/'.preg_quote($route, '/').'$/i', '/'.$home)) { |
|
327 | 327 | $homeParams = $params; |
328 | 328 | } |
329 | 329 | unset($method); |
@@ -346,14 +346,14 @@ discard block |
||
346 | 346 | private function inspectDir($origen, $namespace = 'PSFS', $routing = []) |
347 | 347 | { |
348 | 348 | $files = $this->finder->files()->in($origen)->path('/(controller|api)/i')->depth('< 3')->name('*.php'); |
349 | - if($files->hasResults()) { |
|
349 | + if ($files->hasResults()) { |
|
350 | 350 | foreach ($files->getIterator() as $file) { |
351 | - if($namespace !== 'PSFS' && method_exists($file, 'getRelativePathname')) { |
|
352 | - $filename = '\\' . str_replace('/', '\\', str_replace($origen, '', $file->getRelativePathname())); |
|
353 | - } else { |
|
351 | + if ($namespace !== 'PSFS' && method_exists($file, 'getRelativePathname')) { |
|
352 | + $filename = '\\'.str_replace('/', '\\', str_replace($origen, '', $file->getRelativePathname())); |
|
353 | + }else { |
|
354 | 354 | $filename = str_replace('/', '\\', str_replace($origen, '', $file->getPathname())); |
355 | 355 | } |
356 | - $routing = $this->addRouting($namespace . str_replace('.php', '', $filename), $routing, $namespace); |
|
356 | + $routing = $this->addRouting($namespace.str_replace('.php', '', $filename), $routing, $namespace); |
|
357 | 357 | } |
358 | 358 | } |
359 | 359 | $this->finder = new Finder(); |
@@ -380,7 +380,7 @@ discard block |
||
380 | 380 | private function addRouting($namespace, &$routing, $module = 'PSFS') |
381 | 381 | { |
382 | 382 | if (self::exists($namespace)) { |
383 | - if(I18nHelper::checkI18Class($namespace)) { |
|
383 | + if (I18nHelper::checkI18Class($namespace)) { |
|
384 | 384 | return $routing; |
385 | 385 | } |
386 | 386 | $reflection = new ReflectionClass($namespace); |
@@ -419,7 +419,7 @@ discard block |
||
419 | 419 | if (!$this->domains) { |
420 | 420 | $this->domains = []; |
421 | 421 | } |
422 | - $domain = '@' . $class->getConstant('DOMAIN') . '/'; |
|
422 | + $domain = '@'.$class->getConstant('DOMAIN').'/'; |
|
423 | 423 | if (!array_key_exists($domain, $this->domains)) { |
424 | 424 | $this->domains[$domain] = RouterHelper::extractDomainInfo($class, $domain); |
425 | 425 | } |
@@ -435,11 +435,11 @@ discard block |
||
435 | 435 | */ |
436 | 436 | public function simpatize() |
437 | 437 | { |
438 | - $translationFileName = 'translations' . DIRECTORY_SEPARATOR . 'routes_translations.php'; |
|
439 | - $absoluteTranslationFileName = CACHE_DIR . DIRECTORY_SEPARATOR . $translationFileName; |
|
438 | + $translationFileName = 'translations'.DIRECTORY_SEPARATOR.'routes_translations.php'; |
|
439 | + $absoluteTranslationFileName = CACHE_DIR.DIRECTORY_SEPARATOR.$translationFileName; |
|
440 | 440 | $this->generateSlugs($absoluteTranslationFileName); |
441 | 441 | GeneratorHelper::createDir(CONFIG_DIR); |
442 | - Cache::getInstance()->storeData(CONFIG_DIR . DIRECTORY_SEPARATOR . 'urls.json', array($this->routing, $this->slugs), Cache::JSON, TRUE); |
|
442 | + Cache::getInstance()->storeData(CONFIG_DIR.DIRECTORY_SEPARATOR.'urls.json', array($this->routing, $this->slugs), Cache::JSON, TRUE); |
|
443 | 443 | |
444 | 444 | return $this; |
445 | 445 | } |
@@ -455,18 +455,18 @@ discard block |
||
455 | 455 | public function getRoute($slug = '', $absolute = FALSE, array $params = []) |
456 | 456 | { |
457 | 457 | if ('' === $slug) { |
458 | - return $absolute ? Request::getInstance()->getRootUrl() . '/' : '/'; |
|
458 | + return $absolute ? Request::getInstance()->getRootUrl().'/' : '/'; |
|
459 | 459 | } |
460 | 460 | if (!is_array($this->slugs) || !array_key_exists($slug, $this->slugs)) { |
461 | 461 | throw new RouterException(t('No existe la ruta especificada')); |
462 | 462 | } |
463 | - $url = $absolute ? Request::getInstance()->getRootUrl() . $this->slugs[$slug] : $this->slugs[$slug]; |
|
463 | + $url = $absolute ? Request::getInstance()->getRootUrl().$this->slugs[$slug] : $this->slugs[$slug]; |
|
464 | 464 | if (!empty($params)) { |
465 | 465 | foreach ($params as $key => $value) { |
466 | - $url = str_replace('{' . $key . '}', $value, $url); |
|
466 | + $url = str_replace('{'.$key.'}', $value, $url); |
|
467 | 467 | } |
468 | 468 | } elseif (!empty($this->routing[$this->slugs[$slug]]['default'])) { |
469 | - $url = $absolute ? Request::getInstance()->getRootUrl() . $this->routing[$this->slugs[$slug]]['default'] : $this->routing[$this->slugs[$slug]]['default']; |
|
469 | + $url = $absolute ? Request::getInstance()->getRootUrl().$this->routing[$this->slugs[$slug]]['default'] : $this->routing[$this->slugs[$slug]]['default']; |
|
470 | 470 | } |
471 | 471 | |
472 | 472 | return preg_replace('/(GET|POST|PUT|DELETE|ALL)\#\|\#/', '', $url); |
@@ -485,15 +485,15 @@ discard block |
||
485 | 485 | * @param string $method |
486 | 486 | */ |
487 | 487 | private function checkPreActions($class, $method) { |
488 | - $preAction = 'pre' . ucfirst($method); |
|
489 | - if(method_exists($class, $preAction)) { |
|
488 | + $preAction = 'pre'.ucfirst($method); |
|
489 | + if (method_exists($class, $preAction)) { |
|
490 | 490 | Inspector::stats('[Router] Pre action invoked', Inspector::SCOPE_DEBUG); |
491 | 491 | try { |
492 | - if(false === call_user_func_array([$class, $preAction])) { |
|
492 | + if (false === call_user_func_array([$class, $preAction])) { |
|
493 | 493 | Logger::log(t('Pre action failed'), LOG_ERR, [error_get_last()]); |
494 | 494 | error_clear_last(); |
495 | 495 | } |
496 | - } catch (Exception $e) { |
|
496 | + }catch (Exception $e) { |
|
497 | 497 | Logger::log($e->getMessage(), LOG_ERR, [$class, $method]); |
498 | 498 | } |
499 | 499 | } |
@@ -510,7 +510,7 @@ discard block |
||
510 | 510 | */ |
511 | 511 | protected function executeCachedRoute($route, $action, $class, $params = NULL) |
512 | 512 | { |
513 | - Inspector::stats('[Router] Executing route ' . $route, Inspector::SCOPE_DEBUG); |
|
513 | + Inspector::stats('[Router] Executing route '.$route, Inspector::SCOPE_DEBUG); |
|
514 | 514 | $action['params'] = array_merge($action['params'], $params, Request::getInstance()->getQueryParams()); |
515 | 515 | Security::getInstance()->setSessionKey(Cache::CACHE_SESSION_VAR, $action); |
516 | 516 | $cache = Cache::needCache(); |
@@ -518,15 +518,15 @@ discard block |
||
518 | 518 | $return = null; |
519 | 519 | if (FALSE !== $cache && $action['http'] === 'GET' && Config::getParam('debug') === FALSE) { |
520 | 520 | list($path, $cacheDataName) = $this->cache->getRequestCacheHash(); |
521 | - $cachedData = $this->cache->readFromCache('json' . DIRECTORY_SEPARATOR . $path . $cacheDataName, $cache); |
|
521 | + $cachedData = $this->cache->readFromCache('json'.DIRECTORY_SEPARATOR.$path.$cacheDataName, $cache); |
|
522 | 522 | if (NULL !== $cachedData) { |
523 | - $headers = $this->cache->readFromCache('json' . DIRECTORY_SEPARATOR . $path . $cacheDataName . '.headers', $cache, null, Cache::JSON); |
|
523 | + $headers = $this->cache->readFromCache('json'.DIRECTORY_SEPARATOR.$path.$cacheDataName.'.headers', $cache, null, Cache::JSON); |
|
524 | 524 | Template::getInstance()->renderCache($cachedData, $headers); |
525 | 525 | $execute = FALSE; |
526 | 526 | } |
527 | 527 | } |
528 | 528 | if ($execute) { |
529 | - Inspector::stats('[Router] Start executing action ' . $route, Inspector::SCOPE_DEBUG); |
|
529 | + Inspector::stats('[Router] Start executing action '.$route, Inspector::SCOPE_DEBUG); |
|
530 | 530 | $this->checkPreActions($class, $action['method']); |
531 | 531 | $return = call_user_func_array([$class, $action['method']], $params); |
532 | 532 | if (false === $return) { |
@@ -565,11 +565,11 @@ discard block |
||
565 | 565 | private function loadExternalAutoloader($hydrateRoute, SplFileInfo $modulePath, $externalModulePath) |
566 | 566 | { |
567 | 567 | $extModule = $modulePath->getBasename(); |
568 | - $moduleAutoloader = realpath($externalModulePath . DIRECTORY_SEPARATOR . $extModule . DIRECTORY_SEPARATOR . 'autoload.php'); |
|
569 | - if(file_exists($moduleAutoloader)) { |
|
568 | + $moduleAutoloader = realpath($externalModulePath.DIRECTORY_SEPARATOR.$extModule.DIRECTORY_SEPARATOR.'autoload.php'); |
|
569 | + if (file_exists($moduleAutoloader)) { |
|
570 | 570 | include_once $moduleAutoloader; |
571 | 571 | if ($hydrateRoute) { |
572 | - $this->routing = $this->inspectDir($externalModulePath . DIRECTORY_SEPARATOR . $extModule, '\\' . $extModule, $this->routing); |
|
572 | + $this->routing = $this->inspectDir($externalModulePath.DIRECTORY_SEPARATOR.$extModule, '\\'.$extModule, $this->routing); |
|
573 | 573 | } |
574 | 574 | } |
575 | 575 | } |
@@ -583,16 +583,16 @@ discard block |
||
583 | 583 | { |
584 | 584 | try { |
585 | 585 | $module = preg_replace('/(\\\|\/)/', DIRECTORY_SEPARATOR, $module); |
586 | - $externalModulePath = VENDOR_DIR . DIRECTORY_SEPARATOR . $module . DIRECTORY_SEPARATOR . 'src'; |
|
587 | - if(file_exists($externalModulePath)) { |
|
586 | + $externalModulePath = VENDOR_DIR.DIRECTORY_SEPARATOR.$module.DIRECTORY_SEPARATOR.'src'; |
|
587 | + if (file_exists($externalModulePath)) { |
|
588 | 588 | $externalModule = $this->finder->directories()->in($externalModulePath)->depth(0); |
589 | - if($externalModule->hasResults()) { |
|
589 | + if ($externalModule->hasResults()) { |
|
590 | 590 | foreach ($externalModule->getIterator() as $modulePath) { |
591 | 591 | $this->loadExternalAutoloader($hydrateRoute, $modulePath, $externalModulePath); |
592 | 592 | } |
593 | 593 | } |
594 | 594 | } |
595 | - } catch (Exception $e) { |
|
595 | + }catch (Exception $e) { |
|
596 | 596 | Logger::log($e->getMessage(), LOG_WARNING); |
597 | 597 | $module = null; |
598 | 598 | } |