@@ -420,7 +420,7 @@ |
||
| 420 | 420 | } |
| 421 | 421 | |
| 422 | 422 | /** |
| 423 | - * @param $class |
|
| 423 | + * @param types\Controller $class |
|
| 424 | 424 | * @param $method |
| 425 | 425 | * @param array $params |
| 426 | 426 | * @return \ReflectionMethod |
@@ -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,18 +446,18 @@ 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 | } |
@@ -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,7 +30,7 @@ discard block |
||
| 30 | 30 | */ |
| 31 | 31 | public function generateModule() |
| 32 | 32 | { |
| 33 | - Logger::log("Arranque generador de módulos al solicitar " . $this->getRequest()->getRequestUri()); |
|
| 33 | + Logger::log("Arranque generador de módulos al solicitar ".$this->getRequest()->getRequestUri()); |
|
| 34 | 34 | /* @var $form \PSFS\base\config\ConfigForm */ |
| 35 | 35 | $form = new ModuleForm(); |
| 36 | 36 | $form->build(); |
@@ -60,8 +60,8 @@ discard block |
||
| 60 | 60 | $this->gen->createStructureModule($module, false, $type, (bool)$is_module); |
| 61 | 61 | Security::getInstance()->setFlash("callback_message", str_replace("%s", $module, _("Módulo %s generado correctamente"))); |
| 62 | 62 | Security::getInstance()->setFlash("callback_route", $this->getRoute("admin-module", true)); |
| 63 | - } catch (\Exception $e) { |
|
| 64 | - Logger::getInstance()->infoLog($e->getMessage() . " [" . $e->getFile() . ":" . $e->getLine() . "]"); |
|
| 63 | + }catch (\Exception $e) { |
|
| 64 | + Logger::getInstance()->infoLog($e->getMessage()." [".$e->getFile().":".$e->getLine()."]"); |
|
| 65 | 65 | throw new ConfigException('Error al generar el módulo, prueba a cambiar los permisos', 403); |
| 66 | 66 | } |
| 67 | 67 | } |