@@ -7,7 +7,7 @@ discard block |
||
| 7 | 7 | */ |
| 8 | 8 | class FileHelper { |
| 9 | 9 | /** |
| 10 | - * @param mixed $data |
|
| 10 | + * @param string $data |
|
| 11 | 11 | * @param string $path |
| 12 | 12 | * @return int |
| 13 | 13 | */ |
@@ -17,7 +17,7 @@ discard block |
||
| 17 | 17 | |
| 18 | 18 | /** |
| 19 | 19 | * @param string $path |
| 20 | - * @return mixed|bool |
|
| 20 | + * @return string|false |
|
| 21 | 21 | */ |
| 22 | 22 | public static function readFile($path) { |
| 23 | 23 | $data = false; |
@@ -21,7 +21,7 @@ |
||
| 21 | 21 | */ |
| 22 | 22 | public static function readFile($path) { |
| 23 | 23 | $data = false; |
| 24 | - if(file_exists($path)) { |
|
| 24 | + if (file_exists($path)) { |
|
| 25 | 25 | $data = file_get_contents($path); |
| 26 | 26 | } |
| 27 | 27 | return $data; |
@@ -45,7 +45,7 @@ discard block |
||
| 45 | 45 | { |
| 46 | 46 | GeneratorHelper::createDir(dirname($path)); |
| 47 | 47 | if (false === FileHelper::writeFile($path, $data)) { |
| 48 | - throw new ConfigException(_('No se tienen los permisos suficientes para escribir en el fichero ') . $path); |
|
| 48 | + throw new ConfigException(_('No se tienen los permisos suficientes para escribir en el fichero ').$path); |
|
| 49 | 49 | } |
| 50 | 50 | } |
| 51 | 51 | |
@@ -59,7 +59,7 @@ discard block |
||
| 59 | 59 | public function getDataFromFile($path, $transform = Cache::TEXT, $absolute = false) |
| 60 | 60 | { |
| 61 | 61 | $data = null; |
| 62 | - $absolutePath = ($absolute) ? $path : CACHE_DIR . DIRECTORY_SEPARATOR . $path; |
|
| 62 | + $absolutePath = ($absolute) ? $path : CACHE_DIR.DIRECTORY_SEPARATOR.$path; |
|
| 63 | 63 | if (file_exists($absolutePath)) { |
| 64 | 64 | $data = FileHelper::readFile($absolutePath); |
| 65 | 65 | } |
@@ -75,7 +75,7 @@ discard block |
||
| 75 | 75 | */ |
| 76 | 76 | private function hasExpiredCache($path, $expires = 300, $absolute = false) |
| 77 | 77 | { |
| 78 | - $absolutePath = ($absolute) ? $path : CACHE_DIR . DIRECTORY_SEPARATOR . $path; |
|
| 78 | + $absolutePath = ($absolute) ? $path : CACHE_DIR.DIRECTORY_SEPARATOR.$path; |
|
| 79 | 79 | $lasModificationDate = filemtime($absolutePath); |
| 80 | 80 | return ($lasModificationDate + $expires <= time()); |
| 81 | 81 | } |
@@ -141,7 +141,7 @@ discard block |
||
| 141 | 141 | public function storeData($path, $data, $transform = Cache::TEXT, $absolute = false, $expires = 600) |
| 142 | 142 | { |
| 143 | 143 | $data = Cache::transformData($data, $transform); |
| 144 | - $absolutePath = ($absolute) ? $path : CACHE_DIR . DIRECTORY_SEPARATOR . $path; |
|
| 144 | + $absolutePath = ($absolute) ? $path : CACHE_DIR.DIRECTORY_SEPARATOR.$path; |
|
| 145 | 145 | $this->saveTextToFile($data, $absolutePath); |
| 146 | 146 | } |
| 147 | 147 | |
@@ -156,11 +156,11 @@ discard block |
||
| 156 | 156 | public function readFromCache($path, $expires = 300, callable $function, $transform = Cache::TEXT) |
| 157 | 157 | { |
| 158 | 158 | $data = null; |
| 159 | - if (file_exists(CACHE_DIR . DIRECTORY_SEPARATOR . $path)) { |
|
| 159 | + if (file_exists(CACHE_DIR.DIRECTORY_SEPARATOR.$path)) { |
|
| 160 | 160 | if (null !== $function && $this->hasExpiredCache($path, $expires)) { |
| 161 | 161 | $data = call_user_func($function); |
| 162 | 162 | $this->storeData($path, $data, $transform, false, $expires); |
| 163 | - } else { |
|
| 163 | + }else { |
|
| 164 | 164 | $data = $this->getDataFromFile($path, $transform); |
| 165 | 165 | } |
| 166 | 166 | } |
@@ -202,9 +202,9 @@ discard block |
||
| 202 | 202 | $action = Security::getInstance()->getSessionKey("__CACHE__"); |
| 203 | 203 | if (null !== $action && $action["cache"] > 0) { |
| 204 | 204 | $class = GeneratorHelper::extractClassFromNamespace($action['class']); |
| 205 | - $filename = sha1($action["http"] . " " . $action["slug"]); |
|
| 206 | - $subPath = substr($filename, 0, 2) . DIRECTORY_SEPARATOR . substr($filename, 2, 2); |
|
| 207 | - $hashPath = $action['module'] . DIRECTORY_SEPARATOR . $class . DIRECTORY_SEPARATOR . $action['method'] . DIRECTORY_SEPARATOR . $subPath . DIRECTORY_SEPARATOR; |
|
| 205 | + $filename = sha1($action["http"]." ".$action["slug"]); |
|
| 206 | + $subPath = substr($filename, 0, 2).DIRECTORY_SEPARATOR.substr($filename, 2, 2); |
|
| 207 | + $hashPath = $action['module'].DIRECTORY_SEPARATOR.$class.DIRECTORY_SEPARATOR.$action['method'].DIRECTORY_SEPARATOR.$subPath.DIRECTORY_SEPARATOR; |
|
| 208 | 208 | } |
| 209 | 209 | return [$hashPath, $filename]; |
| 210 | 210 | } |
@@ -132,7 +132,7 @@ discard block |
||
| 132 | 132 | ResponseHelper::setStatusHeader($this->getStatusCode()); |
| 133 | 133 | ResponseHelper::setAuthHeaders($this->isPublicZone()); |
| 134 | 134 | ResponseHelper::setCookieHeaders($cookies); |
| 135 | - header('Content-type: ' . $contentType); |
|
| 135 | + header('Content-type: '.$contentType); |
|
| 136 | 136 | |
| 137 | 137 | } |
| 138 | 138 | |
@@ -148,15 +148,15 @@ discard block |
||
| 148 | 148 | Logger::log('Start output response'); |
| 149 | 149 | ob_start(); |
| 150 | 150 | $this->setReponseHeaders($contentType, $cookies); |
| 151 | - header('Content-length: ' . strlen($output)); |
|
| 151 | + header('Content-length: '.strlen($output)); |
|
| 152 | 152 | |
| 153 | 153 | $needCache = Cache::needCache(); |
| 154 | 154 | if (false !== $needCache && $this->getStatusCode() === Template::STATUS_OK) { |
| 155 | 155 | $cache = Cache::getInstance(); |
| 156 | 156 | Logger::log('Saving output response into cache'); |
| 157 | 157 | list($path, $cacheDataName) = $cache->getRequestCacheHash(); |
| 158 | - $cache->storeData("json" . DIRECTORY_SEPARATOR . $path . $cacheDataName, $output); |
|
| 159 | - $cache->storeData("json" . DIRECTORY_SEPARATOR . $path . $cacheDataName . ".headers", headers_list(), Cache::JSON); |
|
| 158 | + $cache->storeData("json".DIRECTORY_SEPARATOR.$path.$cacheDataName, $output); |
|
| 159 | + $cache->storeData("json".DIRECTORY_SEPARATOR.$path.$cacheDataName.".headers", headers_list(), Cache::JSON); |
|
| 160 | 160 | } |
| 161 | 161 | echo $output; |
| 162 | 162 | |
@@ -174,11 +174,11 @@ discard block |
||
| 174 | 174 | Logger::log('Close template render'); |
| 175 | 175 | $uri = Request::requestUri(); |
| 176 | 176 | Security::getInstance()->setSessionKey("lastRequest", array( |
| 177 | - "url" => Request::getInstance()->getRootUrl() . $uri, |
|
| 177 | + "url" => Request::getInstance()->getRootUrl().$uri, |
|
| 178 | 178 | "ts" => microtime(true), |
| 179 | 179 | )); |
| 180 | 180 | Security::getInstance()->updateSession(); |
| 181 | - Logger::log('End request: ' . $uri, LOG_INFO); |
|
| 181 | + Logger::log('End request: '.$uri, LOG_INFO); |
|
| 182 | 182 | exit; |
| 183 | 183 | } |
| 184 | 184 | |
@@ -216,15 +216,15 @@ discard block |
||
| 216 | 216 | ///////////////////////////////////////////////////////////// |
| 217 | 217 | // Date in the past sets the value to already have been expired. |
| 218 | 218 | header("Expires: Sat, 26 Jul 1997 05:00:00 GMT"); |
| 219 | - header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT'); |
|
| 219 | + header('Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT'); |
|
| 220 | 220 | header('Cache-Control: no-store, no-cache, must-revalidate'); // HTTP/1.1 |
| 221 | 221 | header('Cache-Control: pre-check=0, post-check=0, max-age=0'); // HTTP/1.1 |
| 222 | 222 | header("Pragma: no-cache"); |
| 223 | 223 | header("Expires: 0"); |
| 224 | 224 | header('Content-Transfer-Encoding: none'); |
| 225 | - header("Content-type: " . $content); |
|
| 226 | - header("Content-length: " . strlen($data)); |
|
| 227 | - header('Content-Disposition: attachment; filename="' . $filename . '"'); |
|
| 225 | + header("Content-type: ".$content); |
|
| 226 | + header("Content-length: ".strlen($data)); |
|
| 227 | + header('Content-Disposition: attachment; filename="'.$filename.'"'); |
|
| 228 | 228 | echo $data; |
| 229 | 229 | ob_flush(); |
| 230 | 230 | ob_end_clean(); |