@@ -18,7 +18,7 @@ |
||
| 18 | 18 | * @param mixed $response |
| 19 | 19 | * @param int $statusCode |
| 20 | 20 | * |
| 21 | - * @return mixed JSON |
|
| 21 | + * @return string|null JSON |
|
| 22 | 22 | */ |
| 23 | 23 | public function json($response, $statusCode = 200) |
| 24 | 24 | { |
@@ -23,10 +23,10 @@ discard block |
||
| 23 | 23 | */ |
| 24 | 24 | public function json($response, $statusCode = 200) |
| 25 | 25 | { |
| 26 | - if(Config::getParam('profiling.enable')) { |
|
| 27 | - if(is_array($response)) { |
|
| 26 | + if (Config::getParam('profiling.enable')) { |
|
| 27 | + if (is_array($response)) { |
|
| 28 | 28 | $response['profiling'] = Inspector::getStats(); |
| 29 | - } elseif($response instanceof JsonResponse) { |
|
| 29 | + } elseif ($response instanceof JsonResponse) { |
|
| 30 | 30 | $response = ProfilingJsonResponse::createFromPrevious($response, Inspector::getStats()); |
| 31 | 31 | } |
| 32 | 32 | } |
@@ -34,13 +34,13 @@ discard block |
||
| 34 | 34 | $this->decodeJsonReponse($response); |
| 35 | 35 | |
| 36 | 36 | $mask = JSON_UNESCAPED_UNICODE | JSON_BIGINT_AS_STRING; |
| 37 | - if(Config::getParam('output.json.strict_numbers')) { |
|
| 37 | + if (Config::getParam('output.json.strict_numbers')) { |
|
| 38 | 38 | $mask = JSON_UNESCAPED_UNICODE | JSON_BIGINT_AS_STRING | JSON_NUMERIC_CHECK; |
| 39 | 39 | } |
| 40 | 40 | |
| 41 | 41 | $data = json_encode($response, $mask); |
| 42 | - if(Config::getParam('angular.protection', false)) { |
|
| 43 | - $data = ")]}',\n" . $data; |
|
| 42 | + if (Config::getParam('angular.protection', false)) { |
|
| 43 | + $data = ")]}',\n".$data; |
|
| 44 | 44 | } |
| 45 | 45 | $this->setStatus($statusCode); |
| 46 | 46 | ResponseHelper::setDebugHeaders([]); |
@@ -3,17 +3,17 @@ |
||
| 3 | 3 | |
| 4 | 4 | if (!defined('SOURCE_DIR')) define('SOURCE_DIR', __DIR__); |
| 5 | 5 | if (preg_match('/vendor/', SOURCE_DIR)) { |
| 6 | - if (!defined('BASE_DIR')) define('BASE_DIR', SOURCE_DIR . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . '..'); |
|
| 7 | - if (!defined('CORE_DIR')) define('CORE_DIR', BASE_DIR . DIRECTORY_SEPARATOR . 'src'); |
|
| 8 | -} else { |
|
| 9 | - if (!defined('BASE_DIR')) define('BASE_DIR', SOURCE_DIR . DIRECTORY_SEPARATOR . '..'); |
|
| 10 | - if (!defined('CORE_DIR')) define('CORE_DIR', BASE_DIR . DIRECTORY_SEPARATOR . 'modules'); |
|
| 6 | + if (!defined('BASE_DIR')) define('BASE_DIR', SOURCE_DIR.DIRECTORY_SEPARATOR.'..'.DIRECTORY_SEPARATOR.'..'.DIRECTORY_SEPARATOR.'..'.DIRECTORY_SEPARATOR.'..'); |
|
| 7 | + if (!defined('CORE_DIR')) define('CORE_DIR', BASE_DIR.DIRECTORY_SEPARATOR.'src'); |
|
| 8 | +}else { |
|
| 9 | + if (!defined('BASE_DIR')) define('BASE_DIR', SOURCE_DIR.DIRECTORY_SEPARATOR.'..'); |
|
| 10 | + if (!defined('CORE_DIR')) define('CORE_DIR', BASE_DIR.DIRECTORY_SEPARATOR.'modules'); |
|
| 11 | 11 | } |
| 12 | -if (!defined('VENDOR_DIR')) define('VENDOR_DIR', BASE_DIR . DIRECTORY_SEPARATOR . 'vendor'); |
|
| 13 | -if (!defined('LOG_DIR')) define('LOG_DIR', BASE_DIR . DIRECTORY_SEPARATOR . 'logs'); |
|
| 14 | -if (!defined('CACHE_DIR')) define('CACHE_DIR', BASE_DIR . DIRECTORY_SEPARATOR . 'cache'); |
|
| 15 | -if (!defined('CONFIG_DIR')) define('CONFIG_DIR', BASE_DIR . DIRECTORY_SEPARATOR . 'config'); |
|
| 16 | -if (!defined('WEB_DIR')) define('WEB_DIR', BASE_DIR . DIRECTORY_SEPARATOR . 'html'); |
|
| 12 | +if (!defined('VENDOR_DIR')) define('VENDOR_DIR', BASE_DIR.DIRECTORY_SEPARATOR.'vendor'); |
|
| 13 | +if (!defined('LOG_DIR')) define('LOG_DIR', BASE_DIR.DIRECTORY_SEPARATOR.'logs'); |
|
| 14 | +if (!defined('CACHE_DIR')) define('CACHE_DIR', BASE_DIR.DIRECTORY_SEPARATOR.'cache'); |
|
| 15 | +if (!defined('CONFIG_DIR')) define('CONFIG_DIR', BASE_DIR.DIRECTORY_SEPARATOR.'config'); |
|
| 16 | +if (!defined('WEB_DIR')) define('WEB_DIR', BASE_DIR.DIRECTORY_SEPARATOR.'html'); |
|
| 17 | 17 | |
| 18 | 18 | |
| 19 | 19 | /** |
@@ -4,19 +4,39 @@ |
||
| 4 | 4 | defined('PSFS_START_MEM') or define('PSFS_START_MEM', memory_get_usage()); |
| 5 | 5 | defined('PSFS_START_TS') or define('PSFS_START_TS', microtime(true)); |
| 6 | 6 | |
| 7 | -if (!defined('SOURCE_DIR')) define('SOURCE_DIR', __DIR__); |
|
| 7 | +if (!defined('SOURCE_DIR')) { |
|
| 8 | + define('SOURCE_DIR', __DIR__); |
|
| 9 | +} |
|
| 8 | 10 | if (preg_match('/vendor/', SOURCE_DIR)) { |
| 9 | - if (!defined('BASE_DIR')) define('BASE_DIR', SOURCE_DIR . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . '..'); |
|
| 10 | - if (!defined('CORE_DIR')) define('CORE_DIR', BASE_DIR . DIRECTORY_SEPARATOR . 'src'); |
|
| 11 | -} else { |
|
| 12 | - if (!defined('BASE_DIR')) define('BASE_DIR', SOURCE_DIR . DIRECTORY_SEPARATOR . '..'); |
|
| 13 | - if (!defined('CORE_DIR')) define('CORE_DIR', BASE_DIR . DIRECTORY_SEPARATOR . 'modules'); |
|
| 11 | + if (!defined('BASE_DIR')) { |
|
| 12 | + define('BASE_DIR', SOURCE_DIR . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . '..'); |
|
| 13 | + } |
|
| 14 | + if (!defined('CORE_DIR')) { |
|
| 15 | + define('CORE_DIR', BASE_DIR . DIRECTORY_SEPARATOR . 'src'); |
|
| 16 | + } |
|
| 17 | + } else { |
|
| 18 | + if (!defined('BASE_DIR')) { |
|
| 19 | + define('BASE_DIR', SOURCE_DIR . DIRECTORY_SEPARATOR . '..'); |
|
| 20 | + } |
|
| 21 | + if (!defined('CORE_DIR')) { |
|
| 22 | + define('CORE_DIR', BASE_DIR . DIRECTORY_SEPARATOR . 'modules'); |
|
| 23 | + } |
|
| 24 | + } |
|
| 25 | +if (!defined('VENDOR_DIR')) { |
|
| 26 | + define('VENDOR_DIR', BASE_DIR . DIRECTORY_SEPARATOR . 'vendor'); |
|
| 27 | +} |
|
| 28 | +if (!defined('LOG_DIR')) { |
|
| 29 | + define('LOG_DIR', BASE_DIR . DIRECTORY_SEPARATOR . 'logs'); |
|
| 30 | +} |
|
| 31 | +if (!defined('CACHE_DIR')) { |
|
| 32 | + define('CACHE_DIR', BASE_DIR . DIRECTORY_SEPARATOR . 'cache'); |
|
| 33 | +} |
|
| 34 | +if (!defined('CONFIG_DIR')) { |
|
| 35 | + define('CONFIG_DIR', BASE_DIR . DIRECTORY_SEPARATOR . 'config'); |
|
| 36 | +} |
|
| 37 | +if (!defined('WEB_DIR')) { |
|
| 38 | + define('WEB_DIR', BASE_DIR . DIRECTORY_SEPARATOR . 'html'); |
|
| 14 | 39 | } |
| 15 | -if (!defined('VENDOR_DIR')) define('VENDOR_DIR', BASE_DIR . DIRECTORY_SEPARATOR . 'vendor'); |
|
| 16 | -if (!defined('LOG_DIR')) define('LOG_DIR', BASE_DIR . DIRECTORY_SEPARATOR . 'logs'); |
|
| 17 | -if (!defined('CACHE_DIR')) define('CACHE_DIR', BASE_DIR . DIRECTORY_SEPARATOR . 'cache'); |
|
| 18 | -if (!defined('CONFIG_DIR')) define('CONFIG_DIR', BASE_DIR . DIRECTORY_SEPARATOR . 'config'); |
|
| 19 | -if (!defined('WEB_DIR')) define('WEB_DIR', BASE_DIR . DIRECTORY_SEPARATOR . 'html'); |
|
| 20 | 40 | |
| 21 | 41 | |
| 22 | 42 | /** |
@@ -8,7 +8,7 @@ discard block |
||
| 8 | 8 | */ |
| 9 | 9 | class FileHelper { |
| 10 | 10 | /** |
| 11 | - * @param mixed $data |
|
| 11 | + * @param string $data |
|
| 12 | 12 | * @param string $path |
| 13 | 13 | * @return int |
| 14 | 14 | */ |
@@ -18,7 +18,7 @@ discard block |
||
| 18 | 18 | |
| 19 | 19 | /** |
| 20 | 20 | * @param string $path |
| 21 | - * @return mixed|bool |
|
| 21 | + * @return string|false |
|
| 22 | 22 | */ |
| 23 | 23 | public static function readFile($path) { |
| 24 | 24 | $data = false; |
@@ -51,8 +51,8 @@ discard block |
||
| 51 | 51 | } |
| 52 | 52 | |
| 53 | 53 | /** |
| 54 | - * @param $path |
|
| 55 | - * @return bool |
|
| 54 | + * @param string $path |
|
| 55 | + * @return boolean|null |
|
| 56 | 56 | */ |
| 57 | 57 | public static function deleteDir($path) { |
| 58 | 58 | (new Filesystem())->remove($path); |
@@ -22,7 +22,7 @@ discard block |
||
| 22 | 22 | */ |
| 23 | 23 | public static function readFile($path) { |
| 24 | 24 | $data = false; |
| 25 | - if(file_exists($path)) { |
|
| 25 | + if (file_exists($path)) { |
|
| 26 | 26 | $data = file_get_contents($path); |
| 27 | 27 | } |
| 28 | 28 | return $data; |
@@ -35,7 +35,7 @@ discard block |
||
| 35 | 35 | * @return string |
| 36 | 36 | */ |
| 37 | 37 | public static function generateHashFilename($verb, $slug, array $query = []) { |
| 38 | - return sha1(strtolower($verb) . " " . $slug . " " . strtolower(http_build_query($query))); |
|
| 38 | + return sha1(strtolower($verb)." ".$slug." ".strtolower(http_build_query($query))); |
|
| 39 | 39 | } |
| 40 | 40 | |
| 41 | 41 | /** |
@@ -46,8 +46,8 @@ discard block |
||
| 46 | 46 | public static function generateCachePath(array $action, array $query = []) { |
| 47 | 47 | $class = GeneratorHelper::extractClassFromNamespace($action['class']); |
| 48 | 48 | $filename = self::generateHashFilename($action["http"], $action["slug"], $query); |
| 49 | - $subPath = substr($filename, 0, 2) . DIRECTORY_SEPARATOR . substr($filename, 2, 2); |
|
| 50 | - return $action['module'] . DIRECTORY_SEPARATOR . $class . DIRECTORY_SEPARATOR . $action['method'] . DIRECTORY_SEPARATOR . $subPath . DIRECTORY_SEPARATOR; |
|
| 49 | + $subPath = substr($filename, 0, 2).DIRECTORY_SEPARATOR.substr($filename, 2, 2); |
|
| 50 | + return $action['module'].DIRECTORY_SEPARATOR.$class.DIRECTORY_SEPARATOR.$action['method'].DIRECTORY_SEPARATOR.$subPath.DIRECTORY_SEPARATOR; |
|
| 51 | 51 | } |
| 52 | 52 | |
| 53 | 53 | /** |
@@ -196,7 +196,7 @@ |
||
| 196 | 196 | /** |
| 197 | 197 | * Method that returns a config value |
| 198 | 198 | * @param string $param |
| 199 | - * @param mixed $defaultValue |
|
| 199 | + * @param string $defaultValue |
|
| 200 | 200 | * |
| 201 | 201 | * @return mixed|null |
| 202 | 202 | */ |
@@ -72,7 +72,7 @@ discard block |
||
| 72 | 72 | */ |
| 73 | 73 | protected function init() |
| 74 | 74 | { |
| 75 | - if (file_exists(CONFIG_DIR . DIRECTORY_SEPARATOR . self::CONFIG_FILE)) { |
|
| 75 | + if (file_exists(CONFIG_DIR.DIRECTORY_SEPARATOR.self::CONFIG_FILE)) { |
|
| 76 | 76 | $this->loadConfigData(); |
| 77 | 77 | } |
| 78 | 78 | return $this; |
@@ -188,10 +188,10 @@ discard block |
||
| 188 | 188 | $final_data = array_filter($final_data, function($key, $value) { |
| 189 | 189 | return in_array($key, Config::$required) || !empty($value); |
| 190 | 190 | }, ARRAY_FILTER_USE_BOTH); |
| 191 | - $saved = (false !== file_put_contents(CONFIG_DIR . DIRECTORY_SEPARATOR . self::CONFIG_FILE, json_encode($final_data, JSON_PRETTY_PRINT))); |
|
| 191 | + $saved = (false !== file_put_contents(CONFIG_DIR.DIRECTORY_SEPARATOR.self::CONFIG_FILE, json_encode($final_data, JSON_PRETTY_PRINT))); |
|
| 192 | 192 | Config::getInstance()->loadConfigData(); |
| 193 | 193 | $saved = true; |
| 194 | - } catch (ConfigException $e) { |
|
| 194 | + }catch (ConfigException $e) { |
|
| 195 | 195 | Logger::log($e->getMessage(), LOG_ERR); |
| 196 | 196 | } |
| 197 | 197 | return $saved; |
@@ -223,7 +223,7 @@ discard block |
||
| 223 | 223 | */ |
| 224 | 224 | public function loadConfigData() |
| 225 | 225 | { |
| 226 | - $this->config = json_decode(file_get_contents(CONFIG_DIR . DIRECTORY_SEPARATOR . self::CONFIG_FILE), true) ?: []; |
|
| 226 | + $this->config = json_decode(file_get_contents(CONFIG_DIR.DIRECTORY_SEPARATOR.self::CONFIG_FILE), true) ?: []; |
|
| 227 | 227 | $this->debug = (array_key_exists('debug', $this->config)) ? (bool)$this->config['debug'] : FALSE; |
| 228 | 228 | } |
| 229 | 229 | |
@@ -244,9 +244,9 @@ discard block |
||
| 244 | 244 | */ |
| 245 | 245 | public static function getParam($key, $defaultValue = null, $module = null) |
| 246 | 246 | { |
| 247 | - if(null !== $module) { |
|
| 248 | - return self::getParam(strtolower($module) . '.' . $key, self::getParam($key, $defaultValue)); |
|
| 249 | - } else { |
|
| 247 | + if (null !== $module) { |
|
| 248 | + return self::getParam(strtolower($module).'.'.$key, self::getParam($key, $defaultValue)); |
|
| 249 | + }else { |
|
| 250 | 250 | $param = Config::getInstance()->get($key); |
| 251 | 251 | return (null !== $param) ? $param : $defaultValue; |
| 252 | 252 | } |
@@ -18,7 +18,7 @@ |
||
| 18 | 18 | |
| 19 | 19 | /** |
| 20 | 20 | * @param string $default |
| 21 | - * @return array|mixed|string |
|
| 21 | + * @return string |
|
| 22 | 22 | */ |
| 23 | 23 | private static function extractLocale($default = null) |
| 24 | 24 | { |
@@ -30,21 +30,21 @@ discard block |
||
| 30 | 30 | list($BrowserLocales[$i]) = explode(";", $BrowserLocales[$i]); //trick for "en;q=0.8" |
| 31 | 31 | } |
| 32 | 32 | $locale = array_shift($BrowserLocales); |
| 33 | - } else { |
|
| 33 | + }else { |
|
| 34 | 34 | $locale = strtolower($locale); |
| 35 | 35 | } |
| 36 | 36 | if (false !== strpos($locale, '_')) { |
| 37 | 37 | $locale = explode('_', $locale); |
| 38 | 38 | if ($locale[0] == 'en') { |
| 39 | - $locale = $locale[0] . '_GB'; |
|
| 40 | - } else { |
|
| 41 | - $locale = $locale[0] . '_' . strtoupper($locale[1]); |
|
| 39 | + $locale = $locale[0].'_GB'; |
|
| 40 | + }else { |
|
| 41 | + $locale = $locale[0].'_'.strtoupper($locale[1]); |
|
| 42 | 42 | } |
| 43 | - } else { |
|
| 43 | + }else { |
|
| 44 | 44 | if (strtolower($locale) === 'en') { |
| 45 | 45 | $locale = 'en_GB'; |
| 46 | - } else { |
|
| 47 | - $locale = $locale . '_' . strtoupper($locale); |
|
| 46 | + }else { |
|
| 47 | + $locale = $locale.'_'.strtoupper($locale); |
|
| 48 | 48 | } |
| 49 | 49 | } |
| 50 | 50 | if (!in_array($locale, self::$langs)) { |
@@ -65,7 +65,7 @@ discard block |
||
| 65 | 65 | $translations = array(); |
| 66 | 66 | if (file_exists($absoluteTranslationFileName)) { |
| 67 | 67 | @include($absoluteTranslationFileName); |
| 68 | - } else { |
|
| 68 | + }else { |
|
| 69 | 69 | Cache::getInstance()->storeData($absoluteTranslationFileName, "<?php \$translations = array();\n", Cache::TEXT, TRUE); |
| 70 | 70 | } |
| 71 | 71 | |
@@ -78,13 +78,13 @@ discard block |
||
| 78 | 78 | public static function setLocale() |
| 79 | 79 | { |
| 80 | 80 | $locale = self::extractLocale('es_ES'); |
| 81 | - Logger::log('Set locale to project [' . $locale . ']'); |
|
| 81 | + Logger::log('Set locale to project ['.$locale.']'); |
|
| 82 | 82 | // Load translations |
| 83 | - putenv("LC_ALL=" . $locale); |
|
| 83 | + putenv("LC_ALL=".$locale); |
|
| 84 | 84 | setlocale(LC_ALL, $locale); |
| 85 | 85 | // Load the locale path |
| 86 | - $locale_path = BASE_DIR . DIRECTORY_SEPARATOR . 'locale'; |
|
| 87 | - Logger::log('Set locale dir ' . $locale_path); |
|
| 86 | + $locale_path = BASE_DIR.DIRECTORY_SEPARATOR.'locale'; |
|
| 87 | + Logger::log('Set locale dir '.$locale_path); |
|
| 88 | 88 | GeneratorHelper::createDir($locale_path); |
| 89 | 89 | bindtextdomain('translations', $locale_path); |
| 90 | 90 | textdomain('translations'); |
@@ -119,9 +119,9 @@ discard block |
||
| 119 | 119 | */ |
| 120 | 120 | public static function checkI18Class($namespace) { |
| 121 | 121 | $isI18n = false; |
| 122 | - if(preg_match('/I18n$/i', $namespace)) { |
|
| 122 | + if (preg_match('/I18n$/i', $namespace)) { |
|
| 123 | 123 | $parentClass = preg_replace('/I18n$/i', '', $namespace); |
| 124 | - if(Router::exists($parentClass)) { |
|
| 124 | + if (Router::exists($parentClass)) { |
|
| 125 | 125 | $isI18n = true; |
| 126 | 126 | } |
| 127 | 127 | } |
@@ -113,7 +113,7 @@ discard block |
||
| 113 | 113 | $dump = ''; |
| 114 | 114 | try { |
| 115 | 115 | $dump = $this->tpl->render($tpl, $vars); |
| 116 | - } catch (\Exception $e) { |
|
| 116 | + }catch (\Exception $e) { |
|
| 117 | 117 | Logger::log($e->getMessage(), LOG_ERR); |
| 118 | 118 | } |
| 119 | 119 | return $dump; |
@@ -140,7 +140,7 @@ discard block |
||
| 140 | 140 | public function regenerateTemplates() |
| 141 | 141 | { |
| 142 | 142 | $this->generateTemplatesCache(); |
| 143 | - $domains = Cache::getInstance()->getDataFromFile(CONFIG_DIR . DIRECTORY_SEPARATOR . "domains.json", Cache::JSON, true); |
|
| 143 | + $domains = Cache::getInstance()->getDataFromFile(CONFIG_DIR.DIRECTORY_SEPARATOR."domains.json", Cache::JSON, true); |
|
| 144 | 144 | $translations = []; |
| 145 | 145 | if (is_array($domains)) { |
| 146 | 146 | $translations = $this->parsePathTranslations($domains); |
@@ -162,8 +162,8 @@ discard block |
||
| 162 | 162 | // force compilation |
| 163 | 163 | if ($file->isFile()) { |
| 164 | 164 | try { |
| 165 | - $this->tpl->load(str_replace($tplDir . '/', '', $file)); |
|
| 166 | - } catch (\Exception $e) { |
|
| 165 | + $this->tpl->load(str_replace($tplDir.'/', '', $file)); |
|
| 166 | + }catch (\Exception $e) { |
|
| 167 | 167 | Logger::log($e->getMessage(), LOG_ERR, ['file' => $e->getFile(), 'line' => $e->getLine()]); |
| 168 | 168 | } |
| 169 | 169 | } |
@@ -224,7 +224,7 @@ discard block |
||
| 224 | 224 | 'getFlash' => TemplateFunctions::GET_FLASH_FUNCTION, |
| 225 | 225 | 'getQuery' => TemplateFunctions::GET_QUERY_FUNCTION, |
| 226 | 226 | ]; |
| 227 | - foreach($functions as $name => $function) { |
|
| 227 | + foreach ($functions as $name => $function) { |
|
| 228 | 228 | $this->addTemplateFunction($name, $function); |
| 229 | 229 | } |
| 230 | 230 | } |
@@ -243,7 +243,7 @@ discard block |
||
| 243 | 243 | */ |
| 244 | 244 | private function loadDomains() |
| 245 | 245 | { |
| 246 | - $domains = Cache::getInstance()->getDataFromFile(CONFIG_DIR . DIRECTORY_SEPARATOR . 'domains.json', Cache::JSON, true); |
|
| 246 | + $domains = Cache::getInstance()->getDataFromFile(CONFIG_DIR.DIRECTORY_SEPARATOR.'domains.json', Cache::JSON, true); |
|
| 247 | 247 | if (null !== $domains) { |
| 248 | 248 | foreach ($domains as $domain => $paths) { |
| 249 | 249 | $this->addPath($paths['template'], preg_replace('/(@|\/)/', '', $domain)); |
@@ -258,7 +258,7 @@ discard block |
||
| 258 | 258 | { |
| 259 | 259 | $loader = new \Twig_Loader_Filesystem(GeneratorHelper::getTemplatePath()); |
| 260 | 260 | $this->tpl = new \Twig_Environment($loader, array( |
| 261 | - 'cache' => CACHE_DIR . DIRECTORY_SEPARATOR . 'twig', |
|
| 261 | + 'cache' => CACHE_DIR.DIRECTORY_SEPARATOR.'twig', |
|
| 262 | 262 | 'debug' => (bool)$this->debug, |
| 263 | 263 | 'auto_reload' => Config::getParam('twig.autoreload', TRUE), |
| 264 | 264 | )); |
@@ -82,9 +82,9 @@ |
||
| 82 | 82 | "class" => "btn-warning md-default", |
| 83 | 83 | "icon" => "fa-plus", |
| 84 | 84 | ]; |
| 85 | - if(Config::getParam('admin.version', 'v1') === 'v1') { |
|
| 86 | - $add["onclick"] = "javascript:addNewField(document.getElementById('" . $this->getName() . "'));"; |
|
| 87 | - } else { |
|
| 85 | + if (Config::getParam('admin.version', 'v1') === 'v1') { |
|
| 86 | + $add["onclick"] = "javascript:addNewField(document.getElementById('".$this->getName()."'));"; |
|
| 87 | + }else { |
|
| 88 | 88 | $add["ng-click"] = "addNewField()"; |
| 89 | 89 | } |
| 90 | 90 | $this->addButton('submit', _("Guardar configuración"), "submit", array( |
@@ -65,21 +65,21 @@ discard block |
||
| 65 | 65 | if (count($pks) == 1) { |
| 66 | 66 | $pks = array_keys($pks); |
| 67 | 67 | return [ |
| 68 | - $tableMap::TABLE_NAME . '.' . $pks[0] => Api::API_MODEL_KEY_FIELD |
|
| 68 | + $tableMap::TABLE_NAME.'.'.$pks[0] => Api::API_MODEL_KEY_FIELD |
|
| 69 | 69 | ]; |
| 70 | 70 | } elseif (count($pks) > 1) { |
| 71 | 71 | $apiPks = []; |
| 72 | 72 | $principal = ''; |
| 73 | 73 | $sep = 'CONCAT('; |
| 74 | 74 | foreach ($pks as $pk) { |
| 75 | - $apiPks[$tableMap::TABLE_NAME . '.' . $pk->getName()] = $pk->getPhpName(); |
|
| 76 | - $principal .= $sep . $tableMap::TABLE_NAME . '.' . $pk->getName(); |
|
| 77 | - $sep = ', "' . Api::API_PK_SEPARATOR . '", '; |
|
| 75 | + $apiPks[$tableMap::TABLE_NAME.'.'.$pk->getName()] = $pk->getPhpName(); |
|
| 76 | + $principal .= $sep.$tableMap::TABLE_NAME.'.'.$pk->getName(); |
|
| 77 | + $sep = ', "'.Api::API_PK_SEPARATOR.'", '; |
|
| 78 | 78 | } |
| 79 | 79 | $principal .= ')'; |
| 80 | 80 | $apiPks[$principal] = Api::API_MODEL_KEY_FIELD; |
| 81 | 81 | return $apiPks; |
| 82 | - } else { |
|
| 82 | + }else { |
|
| 83 | 83 | throw new ApiException(_('El modelo de la API no está debidamente mapeado, no hay Primary Key o es compuesta')); |
| 84 | 84 | } |
| 85 | 85 | } |
@@ -102,10 +102,10 @@ discard block |
||
| 102 | 102 | $pks = ''; |
| 103 | 103 | $sep = ''; |
| 104 | 104 | foreach ($tableMap->getPrimaryKeys() as $pk) { |
| 105 | - $pks .= $sep . $pk->getFullyQualifiedName(); |
|
| 105 | + $pks .= $sep.$pk->getFullyQualifiedName(); |
|
| 106 | 106 | $sep = ', "|", '; |
| 107 | 107 | } |
| 108 | - $this->extraColumns['CONCAT("' . $tableMap->getPhpName() . ' #", ' . $pks . ')'] = Api::API_LIST_NAME_FIELD; |
|
| 108 | + $this->extraColumns['CONCAT("'.$tableMap->getPhpName().' #", '.$pks.')'] = Api::API_LIST_NAME_FIELD; |
|
| 109 | 109 | } |
| 110 | 110 | |
| 111 | 111 | /** |
@@ -127,7 +127,7 @@ discard block |
||
| 127 | 127 | } |
| 128 | 128 | if (null !== $column) { |
| 129 | 129 | $this->extraColumns[$column->getFullyQualifiedName()] = Api::API_LIST_NAME_FIELD; |
| 130 | - } else { |
|
| 130 | + }else { |
|
| 131 | 131 | $this->addClassListName($tableMap); |
| 132 | 132 | } |
| 133 | 133 | } |
@@ -139,22 +139,22 @@ discard block |
||
| 139 | 139 | * @param ModelCriteria $query |
| 140 | 140 | * @param string $action |
| 141 | 141 | */ |
| 142 | - private function addExtraColumns(ModelCriteria &$query, $action) |
|
| 142 | + private function addExtraColumns(ModelCriteria & $query, $action) |
|
| 143 | 143 | { |
| 144 | 144 | if (Api::API_ACTION_LIST === $action) { |
| 145 | 145 | $this->addDefaultListField(); |
| 146 | 146 | $this->addPkToList(); |
| 147 | 147 | } |
| 148 | 148 | if (!empty($this->extraColumns)) { |
| 149 | - if(Config::getParam('api.extrafields.compat', true)) { |
|
| 149 | + if (Config::getParam('api.extrafields.compat', true)) { |
|
| 150 | 150 | $fields = array_values($this->extraColumns); |
| 151 | - } else { |
|
| 151 | + }else { |
|
| 152 | 152 | $returnFields = Request::getInstance()->getQuery(Api::API_FIELDS_RESULT_FIELD); |
| 153 | 153 | $fields = explode(',', $returnFields ?: ''); |
| 154 | 154 | $fields[] = self::API_MODEL_KEY_FIELD; |
| 155 | 155 | } |
| 156 | 156 | foreach ($this->extraColumns as $expression => $columnName) { |
| 157 | - if(empty($fields) || in_array($columnName, $fields)) { |
|
| 157 | + if (empty($fields) || in_array($columnName, $fields)) { |
|
| 158 | 158 | $query->withColumn($expression, $columnName); |
| 159 | 159 | } |
| 160 | 160 | } |
@@ -182,21 +182,21 @@ discard block |
||
| 182 | 182 | /** |
| 183 | 183 | * @param ModelCriteria $query |
| 184 | 184 | */ |
| 185 | - protected function checkI18n(ModelCriteria &$query) |
|
| 185 | + protected function checkI18n(ModelCriteria & $query) |
|
| 186 | 186 | { |
| 187 | 187 | $this->extractApiLang(); |
| 188 | 188 | $model = $this->getModelNamespace(); |
| 189 | - $modelI18n = $model . 'I18n'; |
|
| 189 | + $modelI18n = $model.'I18n'; |
|
| 190 | 190 | if (method_exists($query, 'useI18nQuery')) { |
| 191 | 191 | $query->useI18nQuery($this->lang); |
| 192 | - $modelI18nTableMapClass = str_replace('\\Models\\', '\\Models\\Map\\', $modelI18n) . 'TableMap'; |
|
| 192 | + $modelI18nTableMapClass = str_replace('\\Models\\', '\\Models\\Map\\', $modelI18n).'TableMap'; |
|
| 193 | 193 | /** @var TableMap $modelI18nTableMap */ |
| 194 | 194 | $modelI18nTableMap = $modelI18nTableMapClass::getTableMap(); |
| 195 | - foreach($modelI18nTableMap->getColumns() as $columnMap) { |
|
| 196 | - if(!$columnMap->isPrimaryKey()) { |
|
| 197 | - $query->withColumn($modelI18nTableMapClass::TABLE_NAME . '.' . $columnMap->getName(), $columnMap->getPhpName()); |
|
| 198 | - } elseif(!$columnMap->isForeignKey()) { |
|
| 199 | - $query->withColumn('IFNULL(' . $modelI18nTableMapClass::TABLE_NAME . '.' . $columnMap->getName() . ', "'.$this->lang.'")', $columnMap->getPhpName()); |
|
| 195 | + foreach ($modelI18nTableMap->getColumns() as $columnMap) { |
|
| 196 | + if (!$columnMap->isPrimaryKey()) { |
|
| 197 | + $query->withColumn($modelI18nTableMapClass::TABLE_NAME.'.'.$columnMap->getName(), $columnMap->getPhpName()); |
|
| 198 | + } elseif (!$columnMap->isForeignKey()) { |
|
| 199 | + $query->withColumn('IFNULL('.$modelI18nTableMapClass::TABLE_NAME.'.'.$columnMap->getName().', "'.$this->lang.'")', $columnMap->getPhpName()); |
|
| 200 | 200 | } |
| 201 | 201 | } |
| 202 | 202 | } |
@@ -206,23 +206,23 @@ discard block |
||
| 206 | 206 | * @param ActiveRecordInterface $model |
| 207 | 207 | * @param array $data |
| 208 | 208 | */ |
| 209 | - protected function hydrateModelFromRequest(ActiveRecordInterface &$model, array $data = []) { |
|
| 209 | + protected function hydrateModelFromRequest(ActiveRecordInterface & $model, array $data = []) { |
|
| 210 | 210 | $model->fromArray($data); |
| 211 | 211 | $tableMap = $this->getTableMap(); |
| 212 | 212 | try { |
| 213 | - $relateI18n = $tableMap->getRelation($tableMap->getPhpName() . 'I18n'); |
|
| 214 | - if(null !== $relateI18n) { |
|
| 213 | + $relateI18n = $tableMap->getRelation($tableMap->getPhpName().'I18n'); |
|
| 214 | + if (null !== $relateI18n) { |
|
| 215 | 215 | $i18NTableMap = $relateI18n->getLocalTable(); |
| 216 | - foreach($i18NTableMap->getColumns() as $columnMap) { |
|
| 217 | - $method = 'set' . $columnMap->getPhpName(); |
|
| 218 | - if(!($columnMap->isPrimaryKey() && $columnMap->isForeignKey()) |
|
| 216 | + foreach ($i18NTableMap->getColumns() as $columnMap) { |
|
| 217 | + $method = 'set'.$columnMap->getPhpName(); |
|
| 218 | + if (!($columnMap->isPrimaryKey() && $columnMap->isForeignKey()) |
|
| 219 | 219 | &&array_key_exists($columnMap->getPhpName(), $data) |
| 220 | 220 | && method_exists($model, $method)) { |
| 221 | 221 | $model->$method($data[$columnMap->getPhpName()]); |
| 222 | 222 | } |
| 223 | 223 | } |
| 224 | 224 | } |
| 225 | - } catch(\Exception $e) { |
|
| 225 | + }catch (\Exception $e) { |
|
| 226 | 226 | Logger::log($e->getMessage(), LOG_WARNING); |
| 227 | 227 | } |
| 228 | 228 | } |
@@ -44,7 +44,7 @@ discard block |
||
| 44 | 44 | header("Access-Control-Allow-Credentials: true"); |
| 45 | 45 | header("Access-Control-Allow-Origin: *"); |
| 46 | 46 | header("Access-Control-Allow-Methods: GET, POST, DELETE, PUT, PATCH, OPTIONS"); |
| 47 | - header("Access-Control-Allow-Headers: " . implode(', ', self::getCorsHeaders())); |
|
| 47 | + header("Access-Control-Allow-Headers: ".implode(', ', self::getCorsHeaders())); |
|
| 48 | 48 | } |
| 49 | 49 | if (Request::getInstance()->getMethod() == 'OPTIONS') { |
| 50 | 50 | Logger::log('Returning OPTIONS header confirmation for CORS pre flight requests', LOG_DEBUG); |
@@ -73,7 +73,7 @@ discard block |
||
| 73 | 73 | if (self::validateIpAddress($ip)) |
| 74 | 74 | return $ip; |
| 75 | 75 | } |
| 76 | - } else { |
|
| 76 | + }else { |
|
| 77 | 77 | if (self::validateIpAddress($_SERVER['HTTP_X_FORWARDED_FOR'])) |
| 78 | 78 | return $_SERVER['HTTP_X_FORWARDED_FOR']; |
| 79 | 79 | } |
@@ -70,22 +70,28 @@ discard block |
||
| 70 | 70 | if (strpos($_SERVER['HTTP_X_FORWARDED_FOR'], ',') !== false) { |
| 71 | 71 | $iplist = explode(',', $_SERVER['HTTP_X_FORWARDED_FOR']); |
| 72 | 72 | foreach ($iplist as $ip) { |
| 73 | - if (self::validateIpAddress($ip)) |
|
| 74 | - return $ip; |
|
| 73 | + if (self::validateIpAddress($ip)) { |
|
| 74 | + return $ip; |
|
| 75 | + } |
|
| 75 | 76 | } |
| 76 | 77 | } else { |
| 77 | - if (self::validateIpAddress($_SERVER['HTTP_X_FORWARDED_FOR'])) |
|
| 78 | - return $_SERVER['HTTP_X_FORWARDED_FOR']; |
|
| 78 | + if (self::validateIpAddress($_SERVER['HTTP_X_FORWARDED_FOR'])) { |
|
| 79 | + return $_SERVER['HTTP_X_FORWARDED_FOR']; |
|
| 80 | + } |
|
| 79 | 81 | } |
| 80 | 82 | } |
| 81 | - if (!empty($_SERVER['HTTP_X_FORWARDED']) && self::validateIpAddress($_SERVER['HTTP_X_FORWARDED'])) |
|
| 82 | - return $_SERVER['HTTP_X_FORWARDED']; |
|
| 83 | - if (!empty($_SERVER['HTTP_X_CLUSTER_CLIENT_IP']) && self::validateIpAddress($_SERVER['HTTP_X_CLUSTER_CLIENT_IP'])) |
|
| 84 | - return $_SERVER['HTTP_X_CLUSTER_CLIENT_IP']; |
|
| 85 | - if (!empty($_SERVER['HTTP_FORWARDED_FOR']) && self::validateIpAddress($_SERVER['HTTP_FORWARDED_FOR'])) |
|
| 86 | - return $_SERVER['HTTP_FORWARDED_FOR']; |
|
| 87 | - if (!empty($_SERVER['HTTP_FORWARDED']) && self::validateIpAddress($_SERVER['HTTP_FORWARDED'])) |
|
| 88 | - return $_SERVER['HTTP_FORWARDED']; |
|
| 83 | + if (!empty($_SERVER['HTTP_X_FORWARDED']) && self::validateIpAddress($_SERVER['HTTP_X_FORWARDED'])) { |
|
| 84 | + return $_SERVER['HTTP_X_FORWARDED']; |
|
| 85 | + } |
|
| 86 | + if (!empty($_SERVER['HTTP_X_CLUSTER_CLIENT_IP']) && self::validateIpAddress($_SERVER['HTTP_X_CLUSTER_CLIENT_IP'])) { |
|
| 87 | + return $_SERVER['HTTP_X_CLUSTER_CLIENT_IP']; |
|
| 88 | + } |
|
| 89 | + if (!empty($_SERVER['HTTP_FORWARDED_FOR']) && self::validateIpAddress($_SERVER['HTTP_FORWARDED_FOR'])) { |
|
| 90 | + return $_SERVER['HTTP_FORWARDED_FOR']; |
|
| 91 | + } |
|
| 92 | + if (!empty($_SERVER['HTTP_FORWARDED']) && self::validateIpAddress($_SERVER['HTTP_FORWARDED'])) { |
|
| 93 | + return $_SERVER['HTTP_FORWARDED']; |
|
| 94 | + } |
|
| 89 | 95 | |
| 90 | 96 | // return unreliable ip since all else failed |
| 91 | 97 | return $_SERVER['REMOTE_ADDR']; |
@@ -96,8 +102,9 @@ discard block |
||
| 96 | 102 | * a private network range. |
| 97 | 103 | */ |
| 98 | 104 | public static function validateIpAddress($ip) { |
| 99 | - if (strtolower($ip) === 'unknown') |
|
| 100 | - return false; |
|
| 105 | + if (strtolower($ip) === 'unknown') { |
|
| 106 | + return false; |
|
| 107 | + } |
|
| 101 | 108 | |
| 102 | 109 | // generate ipv4 network address |
| 103 | 110 | $ip = ip2long($ip); |
@@ -109,14 +116,30 @@ discard block |
||
| 109 | 116 | // signed numbers (ints default to signed in PHP) |
| 110 | 117 | $ip = sprintf('%u', $ip); |
| 111 | 118 | // do private network range checking |
| 112 | - if ($ip >= 0 && $ip <= 50331647) return false; |
|
| 113 | - if ($ip >= 167772160 && $ip <= 184549375) return false; |
|
| 114 | - if ($ip >= 2130706432 && $ip <= 2147483647) return false; |
|
| 115 | - if ($ip >= 2851995648 && $ip <= 2852061183) return false; |
|
| 116 | - if ($ip >= 2886729728 && $ip <= 2887778303) return false; |
|
| 117 | - if ($ip >= 3221225984 && $ip <= 3221226239) return false; |
|
| 118 | - if ($ip >= 3232235520 && $ip <= 3232301055) return false; |
|
| 119 | - if ($ip >= 4294967040) return false; |
|
| 119 | + if ($ip >= 0 && $ip <= 50331647) { |
|
| 120 | + return false; |
|
| 121 | + } |
|
| 122 | + if ($ip >= 167772160 && $ip <= 184549375) { |
|
| 123 | + return false; |
|
| 124 | + } |
|
| 125 | + if ($ip >= 2130706432 && $ip <= 2147483647) { |
|
| 126 | + return false; |
|
| 127 | + } |
|
| 128 | + if ($ip >= 2851995648 && $ip <= 2852061183) { |
|
| 129 | + return false; |
|
| 130 | + } |
|
| 131 | + if ($ip >= 2886729728 && $ip <= 2887778303) { |
|
| 132 | + return false; |
|
| 133 | + } |
|
| 134 | + if ($ip >= 3221225984 && $ip <= 3221226239) { |
|
| 135 | + return false; |
|
| 136 | + } |
|
| 137 | + if ($ip >= 3232235520 && $ip <= 3232301055) { |
|
| 138 | + return false; |
|
| 139 | + } |
|
| 140 | + if ($ip >= 4294967040) { |
|
| 141 | + return false; |
|
| 142 | + } |
|
| 120 | 143 | } |
| 121 | 144 | return true; |
| 122 | 145 | } |