@@ -135,9 +135,11 @@ |
||
135 | 135 | $cacheService->storeData($cacheFilename, $properties, Cache::JSON); |
136 | 136 | } |
137 | 137 | /** @var \ReflectionProperty $property */ |
138 | - if (!empty($properties) && is_array($properties)) foreach ($properties as $property => $class) { |
|
138 | + if (!empty($properties) && is_array($properties)) { |
|
139 | + foreach ($properties as $property => $class) { |
|
139 | 140 | $this->load($property, true, $class); |
140 | 141 | } |
142 | + } |
|
141 | 143 | $this->setLoaded(); |
142 | 144 | } else { |
143 | 145 | Logger::log(get_class($this) . ' already loaded', LOG_INFO); |
@@ -20,7 +20,7 @@ discard block |
||
20 | 20 | |
21 | 21 | public function __construct() |
22 | 22 | { |
23 | - Logger::log(get_class($this) . ' constructor invoked'); |
|
23 | + Logger::log(get_class($this).' constructor invoked'); |
|
24 | 24 | $this->init(); |
25 | 25 | } |
26 | 26 | |
@@ -90,14 +90,14 @@ discard block |
||
90 | 90 | $calledClass = get_called_class(); |
91 | 91 | try { |
92 | 92 | $instance = InjectorHelper::constructInyectableInstance($variable, $singleton, $classNameSpace, $calledClass); |
93 | - $setter = "set" . ucfirst($variable); |
|
93 | + $setter = "set".ucfirst($variable); |
|
94 | 94 | if (method_exists($calledClass, $setter)) { |
95 | 95 | $this->$setter($instance); |
96 | - } else { |
|
96 | + }else { |
|
97 | 97 | $this->$variable = $instance; |
98 | 98 | } |
99 | - } catch (\Exception $e) { |
|
100 | - Logger::log($e->getMessage() . ': ' . $e->getFile() . ' [' . $e->getLine() . ']', LOG_ERR); |
|
99 | + }catch (\Exception $e) { |
|
100 | + Logger::log($e->getMessage().': '.$e->getFile().' ['.$e->getLine().']', LOG_ERR); |
|
101 | 101 | } |
102 | 102 | return $this; |
103 | 103 | } |
@@ -109,7 +109,7 @@ discard block |
||
109 | 109 | { |
110 | 110 | if (!$this->isLoaded()) { |
111 | 111 | $filename = sha1(get_class($this)); |
112 | - $cacheFilename = "reflections" . DIRECTORY_SEPARATOR . substr($filename, 0, 2) . DIRECTORY_SEPARATOR . substr($filename, 2, 2) . DIRECTORY_SEPARATOR . $filename . ".json"; |
|
112 | + $cacheFilename = "reflections".DIRECTORY_SEPARATOR.substr($filename, 0, 2).DIRECTORY_SEPARATOR.substr($filename, 2, 2).DIRECTORY_SEPARATOR.$filename.".json"; |
|
113 | 113 | /** @var \PSFS\base\Cache $cacheService */ |
114 | 114 | $cacheService = Cache::getInstance(); |
115 | 115 | /** @var \PSFS\base\config\Config $configService */ |
@@ -124,8 +124,8 @@ discard block |
||
124 | 124 | $this->load($property, true, $class); |
125 | 125 | } |
126 | 126 | $this->setLoaded(); |
127 | - } else { |
|
128 | - Logger::log(get_class($this) . ' already loaded', LOG_INFO); |
|
127 | + }else { |
|
128 | + Logger::log(get_class($this).' already loaded', LOG_INFO); |
|
129 | 129 | } |
130 | 130 | } |
131 | 131 | } |
@@ -21,11 +21,11 @@ |
||
21 | 21 | $path = str_replace("\\", DIRECTORY_SEPARATOR, $class); |
22 | 22 | |
23 | 23 | // filepath |
24 | - $abs_path = SOURCE_DIR . DIRECTORY_SEPARATOR . $path . ".php"; |
|
24 | + $abs_path = SOURCE_DIR.DIRECTORY_SEPARATOR.$path.".php"; |
|
25 | 25 | if (!file_exists($abs_path)) { |
26 | - pre('→ ' . $class); |
|
27 | - pre('→ ' . $path); |
|
28 | - pre('→ ' . $abs_path); |
|
26 | + pre('→ '.$class); |
|
27 | + pre('→ '.$path); |
|
28 | + pre('→ '.$abs_path); |
|
29 | 29 | } |
30 | 30 | |
31 | 31 | // require the file |
@@ -121,7 +121,7 @@ discard block |
||
121 | 121 | |
122 | 122 | /** |
123 | 123 | * Método que guarda en fichero los datos pasados |
124 | - * @param $path |
|
124 | + * @param string $path |
|
125 | 125 | * @param $data |
126 | 126 | * @param int $transform |
127 | 127 | * @param boolean $absolutePath |
@@ -156,7 +156,7 @@ discard block |
||
156 | 156 | |
157 | 157 | /** |
158 | 158 | * Método estático que revisa si se necesita cachear la respuesta de un servicio o no |
159 | - * @return integer|boolean |
|
159 | + * @return integer |
|
160 | 160 | */ |
161 | 161 | public static function needCache() |
162 | 162 | { |
@@ -1,10 +1,8 @@ |
||
1 | 1 | <?php |
2 | 2 | namespace PSFS\base; |
3 | 3 | |
4 | -use PSFS\base\config\Config; |
|
5 | 4 | use PSFS\base\exception\ConfigException; |
6 | 5 | use PSFS\base\types\helpers\GeneratorHelper; |
7 | -use PSFS\base\types\helpers\RequestHelper; |
|
8 | 6 | use PSFS\base\types\SingletonTrait; |
9 | 7 | |
10 | 8 | /** |
@@ -31,7 +31,7 @@ discard block |
||
31 | 31 | */ |
32 | 32 | private function saveTextToFile($data, $path, $absolute = false) |
33 | 33 | { |
34 | - $absolutePath = ($absolute) ? $path : CACHE_DIR . DIRECTORY_SEPARATOR . $path; |
|
34 | + $absolutePath = ($absolute) ? $path : CACHE_DIR.DIRECTORY_SEPARATOR.$path; |
|
35 | 35 | $filename = basename($absolutePath); |
36 | 36 | GeneratorHelper::createDir(str_replace($filename, "", $absolutePath)); |
37 | 37 | if (false === file_put_contents($absolutePath, $data)) { |
@@ -50,7 +50,7 @@ discard block |
||
50 | 50 | public function getDataFromFile($path, $transform = Cache::TEXT, $absolute = false) |
51 | 51 | { |
52 | 52 | $data = null; |
53 | - $absolutePath = ($absolute) ? $path : CACHE_DIR . DIRECTORY_SEPARATOR . $path; |
|
53 | + $absolutePath = ($absolute) ? $path : CACHE_DIR.DIRECTORY_SEPARATOR.$path; |
|
54 | 54 | if (file_exists($absolutePath)) { |
55 | 55 | $data = file_get_contents($absolutePath); |
56 | 56 | } |
@@ -66,7 +66,7 @@ discard block |
||
66 | 66 | */ |
67 | 67 | private function hasExpiredCache($path, $expires = 300, $absolute = false) |
68 | 68 | { |
69 | - $absolutePath = ($absolute) ? $path : CACHE_DIR . DIRECTORY_SEPARATOR . $path; |
|
69 | + $absolutePath = ($absolute) ? $path : CACHE_DIR.DIRECTORY_SEPARATOR.$path; |
|
70 | 70 | $lasModificationDate = filemtime($absolutePath); |
71 | 71 | return ($lasModificationDate + $expires <= time()); |
72 | 72 | } |
@@ -89,7 +89,7 @@ discard block |
||
89 | 89 | break; |
90 | 90 | case Cache::GZIP: |
91 | 91 | // TODO implementar |
92 | - if(function_exists('gzuncompress')) { |
|
92 | + if (function_exists('gzuncompress')) { |
|
93 | 93 | $data = gzuncompress($data ?: ''); |
94 | 94 | } |
95 | 95 | break; |
@@ -114,7 +114,7 @@ discard block |
||
114 | 114 | $data = Cache::transformData($data, Cache::GZIP); |
115 | 115 | break; |
116 | 116 | case Cache::GZIP: |
117 | - if(function_exists('gzcompress')) { |
|
117 | + if (function_exists('gzcompress')) { |
|
118 | 118 | $data = gzcompress($data ?: ''); |
119 | 119 | } |
120 | 120 | break; |
@@ -146,11 +146,11 @@ discard block |
||
146 | 146 | public function readFromCache($path, $expires = 300, callable $function, $transform = Cache::TEXT) |
147 | 147 | { |
148 | 148 | $data = null; |
149 | - if (file_exists(CACHE_DIR . DIRECTORY_SEPARATOR . $path)) { |
|
149 | + if (file_exists(CACHE_DIR.DIRECTORY_SEPARATOR.$path)) { |
|
150 | 150 | if (null !== $function && $this->hasExpiredCache($path, $expires)) { |
151 | 151 | $data = call_user_func($function); |
152 | 152 | $this->storeData($path, $data, $transform); |
153 | - } else { |
|
153 | + }else { |
|
154 | 154 | $data = $this->getDataFromFile($path, $transform); |
155 | 155 | } |
156 | 156 | } |
@@ -163,7 +163,7 @@ discard block |
||
163 | 163 | private static function checkAdminSite() { |
164 | 164 | $isAdminRequest = false; |
165 | 165 | $lastRequest = Security::getInstance()->getSessionKey("lastRequest"); |
166 | - if(null !== $lastRequest) { |
|
166 | + if (null !== $lastRequest) { |
|
167 | 167 | $url = str_replace(Request::getInstance()->getRootUrl(true), '', $lastRequest['url']); |
168 | 168 | $isAdminRequest = preg_match('/^\/admin\//i', $url); |
169 | 169 | } |
@@ -177,7 +177,7 @@ discard block |
||
177 | 177 | public static function needCache() |
178 | 178 | { |
179 | 179 | $needCache = false; |
180 | - if(!self::checkAdminSite()) { |
|
180 | + if (!self::checkAdminSite()) { |
|
181 | 181 | $action = Security::getInstance()->getSessionKey("__CACHE__"); |
182 | 182 | if (null !== $action && array_key_exists("cache", $action) && $action["cache"] > 0) { |
183 | 183 | $needCache = $action["cache"]; |
@@ -195,7 +195,7 @@ discard block |
||
195 | 195 | $hash = ""; |
196 | 196 | $action = Security::getInstance()->getSessionKey("__CACHE__"); |
197 | 197 | if (null !== $action && $action["cache"] > 0) { |
198 | - $hash = $action["http"] . " " . $action["slug"]; |
|
198 | + $hash = $action["http"]." ".$action["slug"]; |
|
199 | 199 | } |
200 | 200 | return sha1($hash); |
201 | 201 | } |
@@ -38,8 +38,8 @@ |
||
38 | 38 | //Generating the templates translations |
39 | 39 | $translations = $this->tpl->regenerateTemplates(); |
40 | 40 | |
41 | - $locale_path = realpath(BASE_DIR . DIRECTORY_SEPARATOR . 'locale'); |
|
42 | - $locale_path .= DIRECTORY_SEPARATOR . $locale . DIRECTORY_SEPARATOR . 'LC_MESSAGES' . DIRECTORY_SEPARATOR; |
|
41 | + $locale_path = realpath(BASE_DIR.DIRECTORY_SEPARATOR.'locale'); |
|
42 | + $locale_path .= DIRECTORY_SEPARATOR.$locale.DIRECTORY_SEPARATOR.'LC_MESSAGES'.DIRECTORY_SEPARATOR; |
|
43 | 43 | |
44 | 44 | //xgettext localizations |
45 | 45 | $translations = array_merge($translations, GeneratorService::findTranslations(SOURCE_DIR, $locale)); |
@@ -33,7 +33,9 @@ |
||
33 | 33 | public function getTranslations($locale) |
34 | 34 | { |
35 | 35 | //Default locale |
36 | - if (null === $locale) $locale = $this->config->get("default_language"); |
|
36 | + if (null === $locale) { |
|
37 | + $locale = $this->config->get("default_language"); |
|
38 | + } |
|
37 | 39 | |
38 | 40 | //Generating the templates translations |
39 | 41 | $translations = $this->tpl->regenerateTemplates(); |
@@ -51,7 +51,7 @@ |
||
51 | 51 | $router->simpatize(); |
52 | 52 | Security::getInstance()->setFlash("callback_message", _("Rutas generadas correctamente")); |
53 | 53 | Security::getInstance()->setFlash("callback_route", $this->getRoute("admin-routes", true)); |
54 | - } catch(\Exception $e) { |
|
54 | + }catch (\Exception $e) { |
|
55 | 55 | Logger::log($e->getMessage(), LOG_ERR); |
56 | 56 | Security::getInstance()->setFlash("callback_message", _("Algo no ha salido bien, revisa los logs")); |
57 | 57 | Security::getInstance()->setFlash("callback_route", $this->getRoute("admin-routes", true)); |
@@ -30,7 +30,7 @@ |
||
30 | 30 | * @route /admin/routes/show |
31 | 31 | * @label Servicio de rutas del sistema |
32 | 32 | * @visible false |
33 | - * @return mixed |
|
33 | + * @return string|null |
|
34 | 34 | */ |
35 | 35 | public function getRouting() |
36 | 36 | { |
@@ -88,7 +88,7 @@ discard block |
||
88 | 88 | * @param string $msg |
89 | 89 | * @param array $context |
90 | 90 | * |
91 | - * @return bool |
|
91 | + * @return boolean|null |
|
92 | 92 | */ |
93 | 93 | public function debugLog($msg = '', $context = []) |
94 | 94 | { |
@@ -97,7 +97,7 @@ discard block |
||
97 | 97 | |
98 | 98 | /** |
99 | 99 | * Método que escribe un log de Error |
100 | - * @param $msg |
|
100 | + * @param string $msg |
|
101 | 101 | * @param array $context |
102 | 102 | * |
103 | 103 | * @return bool |
@@ -109,7 +109,7 @@ discard block |
||
109 | 109 | |
110 | 110 | /** |
111 | 111 | * Método que escribe un log de Warning |
112 | - * @param $msg |
|
112 | + * @param string $msg |
|
113 | 113 | * @param array $context |
114 | 114 | * @return bool |
115 | 115 | */ |
@@ -14,8 +14,8 @@ discard block |
||
14 | 14 | |
15 | 15 | |
16 | 16 | if (!defined("LOG_DIR")) { |
17 | - GeneratorHelper::createDir(BASE_DIR . DIRECTORY_SEPARATOR . 'logs'); |
|
18 | - define("LOG_DIR", BASE_DIR . DIRECTORY_SEPARATOR . 'logs'); |
|
17 | + GeneratorHelper::createDir(BASE_DIR.DIRECTORY_SEPARATOR.'logs'); |
|
18 | + define("LOG_DIR", BASE_DIR.DIRECTORY_SEPARATOR.'logs'); |
|
19 | 19 | } |
20 | 20 | |
21 | 21 | /** |
@@ -48,7 +48,7 @@ discard block |
||
48 | 48 | $config = Config::getInstance(); |
49 | 49 | $args = func_get_args(); |
50 | 50 | list($logger, $debug, $path) = $this->setup($config, $args); |
51 | - $this->stream = fopen($path . DIRECTORY_SEPARATOR . date("Ymd") . ".log", "a+"); |
|
51 | + $this->stream = fopen($path.DIRECTORY_SEPARATOR.date("Ymd").".log", "a+"); |
|
52 | 52 | $this->addPushLogger($logger, $debug, $config); |
53 | 53 | $this->log_level = Config::getInstance()->get('log.level') ?: 'info'; |
54 | 54 | } |
@@ -202,7 +202,7 @@ discard block |
||
202 | 202 | private function createLoggerPath(Config $config) |
203 | 203 | { |
204 | 204 | $logger = $this->setLoggerName($config); |
205 | - $path = LOG_DIR . DIRECTORY_SEPARATOR . $logger . DIRECTORY_SEPARATOR . date('Y') . DIRECTORY_SEPARATOR . date('m'); |
|
205 | + $path = LOG_DIR.DIRECTORY_SEPARATOR.$logger.DIRECTORY_SEPARATOR.date('Y').DIRECTORY_SEPARATOR.date('m'); |
|
206 | 206 | GeneratorHelper::createDir($path); |
207 | 207 | |
208 | 208 | return $path; |
@@ -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 | } |
@@ -60,12 +60,12 @@ discard block |
||
60 | 60 | */ |
61 | 61 | public function init() |
62 | 62 | { |
63 | - if (!file_exists(CONFIG_DIR . DIRECTORY_SEPARATOR . "urls.json") || Config::getInstance()->getDebugMode()) { |
|
63 | + if (!file_exists(CONFIG_DIR.DIRECTORY_SEPARATOR."urls.json") || Config::getInstance()->getDebugMode()) { |
|
64 | 64 | $this->hydrateRouting(); |
65 | 65 | $this->simpatize(); |
66 | - } else { |
|
67 | - list($this->routing, $this->slugs) = $this->cache->getDataFromFile(CONFIG_DIR . DIRECTORY_SEPARATOR . "urls.json", Cache::JSON, TRUE); |
|
68 | - $this->domains = $this->cache->getDataFromFile(CONFIG_DIR . DIRECTORY_SEPARATOR . "domains.json", Cache::JSON, TRUE); |
|
66 | + }else { |
|
67 | + list($this->routing, $this->slugs) = $this->cache->getDataFromFile(CONFIG_DIR.DIRECTORY_SEPARATOR."urls.json", Cache::JSON, TRUE); |
|
68 | + $this->domains = $this->cache->getDataFromFile(CONFIG_DIR.DIRECTORY_SEPARATOR."domains.json", Cache::JSON, TRUE); |
|
69 | 69 | } |
70 | 70 | } |
71 | 71 | |
@@ -89,7 +89,7 @@ discard block |
||
89 | 89 | "success" => FALSE, |
90 | 90 | "error" => $e->getMessage(), |
91 | 91 | )), 'application/json'); |
92 | - } else { |
|
92 | + }else { |
|
93 | 93 | return $template->render('error.html.twig', array( |
94 | 94 | 'exception' => $e, |
95 | 95 | 'trace' => $e->getTraceAsString(), |
@@ -140,12 +140,12 @@ discard block |
||
140 | 140 | SecurityHelper::checkRestrictedAccess($route); |
141 | 141 | //Search action and execute |
142 | 142 | $this->searchAction($route); |
143 | - } catch (AccessDeniedException $e) { |
|
143 | + }catch (AccessDeniedException $e) { |
|
144 | 144 | Logger::log(_('Solicitamos credenciales de acceso a zona restringida')); |
145 | 145 | return Admin::staticAdminLogon($route); |
146 | - } catch (RouterException $r) { |
|
146 | + }catch (RouterException $r) { |
|
147 | 147 | Logger::log($r->getMessage(), LOG_WARNING); |
148 | - } catch (\Exception $e) { |
|
148 | + }catch (\Exception $e) { |
|
149 | 149 | Logger::log($e->getMessage(), LOG_ERR); |
150 | 150 | throw $e; |
151 | 151 | } |
@@ -162,7 +162,7 @@ discard block |
||
162 | 162 | */ |
163 | 163 | protected function searchAction($route) |
164 | 164 | { |
165 | - Logger::log('Searching action to execute: ' . $route, LOG_INFO); |
|
165 | + Logger::log('Searching action to execute: '.$route, LOG_INFO); |
|
166 | 166 | //Revisamos si tenemos la ruta registrada |
167 | 167 | $parts = parse_url($route); |
168 | 168 | $path = (array_key_exists('path', $parts)) ? $parts['path'] : $route; |
@@ -176,7 +176,7 @@ discard block |
||
176 | 176 | $class = RouterHelper::getClassToCall($action); |
177 | 177 | try { |
178 | 178 | $this->executeCachedRoute($route, $action, $class, $get); |
179 | - } catch (\Exception $e) { |
|
179 | + }catch (\Exception $e) { |
|
180 | 180 | Logger::log($e->getMessage(), LOG_ERR); |
181 | 181 | throw new RouterException($e->getMessage(), 404, $e); |
182 | 182 | } |
@@ -201,16 +201,16 @@ discard block |
||
201 | 201 | $externalModules = explode(',', $externalModules); |
202 | 202 | foreach ($externalModules as &$module) { |
203 | 203 | $module = preg_replace('/(\\\|\/)/', DIRECTORY_SEPARATOR, $module); |
204 | - $externalModulePath = VENDOR_DIR . DIRECTORY_SEPARATOR . $module . DIRECTORY_SEPARATOR . 'src'; |
|
204 | + $externalModulePath = VENDOR_DIR.DIRECTORY_SEPARATOR.$module.DIRECTORY_SEPARATOR.'src'; |
|
205 | 205 | if (file_exists($externalModulePath)) { |
206 | 206 | $externalModule = $this->finder->directories()->in($externalModulePath)->depth(0); |
207 | 207 | if (!empty($externalModule)) { |
208 | 208 | foreach ($externalModule as $modulePath) { |
209 | 209 | $extModule = $modulePath->getBasename(); |
210 | - $moduleAutoloader = realpath($externalModulePath . DIRECTORY_SEPARATOR . $extModule . DIRECTORY_SEPARATOR . 'autoload.php'); |
|
210 | + $moduleAutoloader = realpath($externalModulePath.DIRECTORY_SEPARATOR.$extModule.DIRECTORY_SEPARATOR.'autoload.php'); |
|
211 | 211 | if (file_exists($moduleAutoloader)) { |
212 | 212 | @include $moduleAutoloader; |
213 | - $this->routing = $this->inspectDir($externalModulePath . DIRECTORY_SEPARATOR . $extModule, $extModule, $this->routing); |
|
213 | + $this->routing = $this->inspectDir($externalModulePath.DIRECTORY_SEPARATOR.$extModule, $extModule, $this->routing); |
|
214 | 214 | } |
215 | 215 | } |
216 | 216 | } |
@@ -231,11 +231,11 @@ discard block |
||
231 | 231 | $modules = $this->finder->directories()->in($modulesPath)->depth(0); |
232 | 232 | foreach ($modules as $modulePath) { |
233 | 233 | $module = $modulePath->getBasename(); |
234 | - $this->routing = $this->inspectDir($modulesPath . DIRECTORY_SEPARATOR . $module, $module, $this->routing); |
|
234 | + $this->routing = $this->inspectDir($modulesPath.DIRECTORY_SEPARATOR.$module, $module, $this->routing); |
|
235 | 235 | } |
236 | 236 | } |
237 | 237 | $this->checkExternalModules(); |
238 | - $this->cache->storeData(CONFIG_DIR . DIRECTORY_SEPARATOR . "domains.json", $this->domains, Cache::JSON, TRUE); |
|
238 | + $this->cache->storeData(CONFIG_DIR.DIRECTORY_SEPARATOR."domains.json", $this->domains, Cache::JSON, TRUE); |
|
239 | 239 | } |
240 | 240 | |
241 | 241 | /** |
@@ -250,7 +250,7 @@ discard block |
||
250 | 250 | $home_params = NULL; |
251 | 251 | foreach ($this->routing as $pattern => $params) { |
252 | 252 | list($method, $route) = RouterHelper::extractHttpRoute($pattern); |
253 | - if (preg_match("/" . preg_quote($route, "/") . "$/i", "/" . $home)) { |
|
253 | + if (preg_match("/".preg_quote($route, "/")."$/i", "/".$home)) { |
|
254 | 254 | $home_params = $params; |
255 | 255 | } |
256 | 256 | } |
@@ -275,7 +275,7 @@ discard block |
||
275 | 275 | $files = $this->finder->files()->in($origen)->path('/(controller|api)/i')->depth(1)->name("*.php"); |
276 | 276 | foreach ($files as $file) { |
277 | 277 | $filename = str_replace("/", '\\', str_replace($origen, '', $file->getPathname())); |
278 | - $routing = $this->addRouting($namespace . str_replace('.php', '', $filename), $routing, $namespace); |
|
278 | + $routing = $this->addRouting($namespace.str_replace('.php', '', $filename), $routing, $namespace); |
|
279 | 279 | } |
280 | 280 | $this->finder = new Finder(); |
281 | 281 | |
@@ -344,7 +344,7 @@ discard block |
||
344 | 344 | if (!$this->domains) { |
345 | 345 | $this->domains = []; |
346 | 346 | } |
347 | - $domain = "@" . $class->getConstant("DOMAIN") . "/"; |
|
347 | + $domain = "@".$class->getConstant("DOMAIN")."/"; |
|
348 | 348 | if (!array_key_exists($domain, $this->domains)) { |
349 | 349 | $this->domains[$domain] = RouterHelper::extractDomainInfo($class, $domain); |
350 | 350 | } |
@@ -359,11 +359,11 @@ discard block |
||
359 | 359 | */ |
360 | 360 | public function simpatize() |
361 | 361 | { |
362 | - $translationFileName = "translations" . DIRECTORY_SEPARATOR . "routes_translations.php"; |
|
363 | - $absoluteTranslationFileName = CACHE_DIR . DIRECTORY_SEPARATOR . $translationFileName; |
|
362 | + $translationFileName = "translations".DIRECTORY_SEPARATOR."routes_translations.php"; |
|
363 | + $absoluteTranslationFileName = CACHE_DIR.DIRECTORY_SEPARATOR.$translationFileName; |
|
364 | 364 | $this->generateSlugs($absoluteTranslationFileName); |
365 | 365 | GeneratorHelper::createDir(CONFIG_DIR); |
366 | - Cache::getInstance()->storeData(CONFIG_DIR . DIRECTORY_SEPARATOR . "urls.json", array($this->routing, $this->slugs), Cache::JSON, TRUE); |
|
366 | + Cache::getInstance()->storeData(CONFIG_DIR.DIRECTORY_SEPARATOR."urls.json", array($this->routing, $this->slugs), Cache::JSON, TRUE); |
|
367 | 367 | |
368 | 368 | return $this; |
369 | 369 | } |
@@ -381,16 +381,16 @@ discard block |
||
381 | 381 | public function getRoute($slug = '', $absolute = FALSE, $params = []) |
382 | 382 | { |
383 | 383 | if (strlen($slug) === 0) { |
384 | - return ($absolute) ? Request::getInstance()->getRootUrl() . '/' : '/'; |
|
384 | + return ($absolute) ? Request::getInstance()->getRootUrl().'/' : '/'; |
|
385 | 385 | } |
386 | 386 | if (NULL === $slug || !array_key_exists($slug, $this->slugs)) { |
387 | 387 | throw new RouterException(_("No existe la ruta especificada")); |
388 | 388 | } |
389 | - $url = ($absolute) ? Request::getInstance()->getRootUrl() . $this->slugs[$slug] : $this->slugs[$slug]; |
|
389 | + $url = ($absolute) ? Request::getInstance()->getRootUrl().$this->slugs[$slug] : $this->slugs[$slug]; |
|
390 | 390 | if (!empty($params)) foreach ($params as $key => $value) { |
391 | - $url = str_replace("{" . $key . "}", $value, $url); |
|
391 | + $url = str_replace("{".$key."}", $value, $url); |
|
392 | 392 | } elseif (!empty($this->routing[$this->slugs[$slug]]["default"])) { |
393 | - $url = ($absolute) ? Request::getInstance()->getRootUrl() . $this->routing[$this->slugs[$slug]]["default"] : $this->routing[$this->slugs[$slug]]["default"]; |
|
393 | + $url = ($absolute) ? Request::getInstance()->getRootUrl().$this->routing[$this->slugs[$slug]]["default"] : $this->routing[$this->slugs[$slug]]["default"]; |
|
394 | 394 | } |
395 | 395 | |
396 | 396 | return preg_replace('/(GET|POST|PUT|DELETE|ALL)\#\|\#/', '', $url); |
@@ -451,19 +451,19 @@ discard block |
||
451 | 451 | */ |
452 | 452 | protected function executeCachedRoute($route, $action, $class, $params = NULL) |
453 | 453 | { |
454 | - Logger::log('Executing route ' . $route, LOG_INFO); |
|
454 | + Logger::log('Executing route '.$route, LOG_INFO); |
|
455 | 455 | Security::getInstance()->setSessionKey("__CACHE__", $action); |
456 | 456 | $cache = Cache::needCache(); |
457 | 457 | $execute = TRUE; |
458 | 458 | if (FALSE !== $cache && Config::getInstance()->getDebugMode() === FALSE) { |
459 | 459 | $cacheDataName = $this->cache->getRequestCacheHash(); |
460 | - $tmpDir = substr($cacheDataName, 0, 2) . DIRECTORY_SEPARATOR . substr($cacheDataName, 2, 2) . DIRECTORY_SEPARATOR; |
|
461 | - $cachedData = $this->cache->readFromCache("json" . DIRECTORY_SEPARATOR . $tmpDir . $cacheDataName, |
|
462 | - $cache, function () { |
|
460 | + $tmpDir = substr($cacheDataName, 0, 2).DIRECTORY_SEPARATOR.substr($cacheDataName, 2, 2).DIRECTORY_SEPARATOR; |
|
461 | + $cachedData = $this->cache->readFromCache("json".DIRECTORY_SEPARATOR.$tmpDir.$cacheDataName, |
|
462 | + $cache, function() { |
|
463 | 463 | }); |
464 | 464 | if (NULL !== $cachedData) { |
465 | - $headers = $this->cache->readFromCache("json" . DIRECTORY_SEPARATOR . $tmpDir . $cacheDataName . ".headers", |
|
466 | - $cache, function () { |
|
465 | + $headers = $this->cache->readFromCache("json".DIRECTORY_SEPARATOR.$tmpDir.$cacheDataName.".headers", |
|
466 | + $cache, function() { |
|
467 | 467 | }, Cache::JSON); |
468 | 468 | Template::getInstance()->renderCache($cachedData, $headers); |
469 | 469 | $execute = FALSE; |
@@ -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,13 +128,13 @@ 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 | 134 | "base" => $path, |
135 | - "template" => $path . $tpl_path, |
|
136 | - "model" => $path . $model_path, |
|
137 | - "public" => $path . $public_path, |
|
135 | + "template" => $path.$tpl_path, |
|
136 | + "model" => $path.$model_path, |
|
137 | + "public" => $path.$public_path, |
|
138 | 138 | ]; |
139 | 139 | } |
140 | 140 | |
@@ -156,9 +156,9 @@ discard block |
||
156 | 156 | if (count($parameters) > 0) foreach ($parameters as $param) { |
157 | 157 | if ($param->isOptional() && !is_array($param->getDefaultValue())) { |
158 | 158 | $params[$param->getName()] = $param->getDefaultValue(); |
159 | - $default = str_replace('{' . $param->getName() . '}', $param->getDefaultValue(), $regex); |
|
159 | + $default = str_replace('{'.$param->getName().'}', $param->getDefaultValue(), $regex); |
|
160 | 160 | } |
161 | - } else $default = $regex; |
|
161 | + }else $default = $regex; |
|
162 | 162 | |
163 | 163 | return array($regex, $default, $params); |
164 | 164 | } |
@@ -238,7 +238,7 @@ discard block |
||
238 | 238 | $default = str_replace('{__DOMAIN__}', $module, $default); |
239 | 239 | $httpMethod = RouterHelper::extractReflectionHttpMethod($docComments); |
240 | 240 | $label = RouterHelper::extractReflectionLabel(str_replace('{__API__}', $api, $docComments)); |
241 | - $route = $httpMethod . "#|#" . $regex; |
|
241 | + $route = $httpMethod."#|#".$regex; |
|
242 | 242 | $info = [ |
243 | 243 | "method" => $method->getName(), |
244 | 244 | "params" => $params, |
@@ -265,7 +265,7 @@ discard block |
||
265 | 265 | $default = Config::getInstance()->get('admin_action') ?: 'admin-login'; |
266 | 266 | |
267 | 267 | } |
268 | - if(null !== $default) { |
|
268 | + if (null !== $default) { |
|
269 | 269 | return Router::getInstance()->execute(Router::getInstance()->getRoute($default)); |
270 | 270 | } |
271 | 271 | return null; |