@@ -14,12 +14,10 @@ |
||
14 | 14 | use PSFS\base\Request; |
15 | 15 | use PSFS\base\Router; |
16 | 16 | use PSFS\base\Singleton; |
17 | -use PSFS\base\Template; |
|
18 | 17 | use PSFS\base\types\helpers\ApiFormHelper; |
19 | 18 | use PSFS\base\types\helpers\ApiHelper; |
20 | 19 | use PSFS\base\types\traits\JsonTrait; |
21 | 20 | use PSFS\base\types\traits\RouteTrait; |
22 | -use PSFS\base\types\traits\SingletonTrait; |
|
23 | 21 | |
24 | 22 | /** |
25 | 23 | * Class Api |
@@ -1,14 +1,10 @@ |
||
1 | 1 | <?php |
2 | 2 | namespace PSFS\base\types; |
3 | 3 | |
4 | -use PSFS\base\exception\RouterException; |
|
5 | -use PSFS\base\Request; |
|
6 | -use PSFS\base\Router; |
|
7 | 4 | use PSFS\base\Singleton; |
8 | 5 | use PSFS\base\types\helpers\GeneratorHelper; |
9 | 6 | use PSFS\base\types\interfaces\ControllerInterface; |
10 | 7 | use PSFS\base\types\traits\JsonTrait; |
11 | -use PSFS\base\types\traits\OutputTrait; |
|
12 | 8 | use PSFS\base\types\traits\RouteTrait; |
13 | 9 | |
14 | 10 | /** |
@@ -40,7 +40,7 @@ discard block |
||
40 | 40 | { |
41 | 41 | $vars['__menu__'] = $this->getMenu(); |
42 | 42 | $domain = (null === $domain) ? $this->getDomain() : $domain; |
43 | - return $this->tpl->render($domain . $template, $vars, $cookies); |
|
43 | + return $this->tpl->render($domain.$template, $vars, $cookies); |
|
44 | 44 | } |
45 | 45 | |
46 | 46 | /** |
@@ -71,7 +71,7 @@ discard block |
||
71 | 71 | { |
72 | 72 | $vars['__menu__'] = $this->getMenu(); |
73 | 73 | $domain = $domain ?: $this->getDomain(); |
74 | - return $this->tpl->dump($domain . $template, $vars); |
|
74 | + return $this->tpl->dump($domain.$template, $vars); |
|
75 | 75 | } |
76 | 76 | |
77 | 77 | /** |
@@ -31,9 +31,10 @@ |
||
31 | 31 | function getallheaders() |
32 | 32 | { |
33 | 33 | $headers = array(); |
34 | - foreach ($_SERVER as $h => $v) |
|
35 | - if (preg_match('/HTTP_(.+)/', $h, $hp)) |
|
34 | + foreach ($_SERVER as $h => $v) { |
|
35 | + if (preg_match('/HTTP_(.+)/', $h, $hp)) |
|
36 | 36 | $headers[$hp[1]] = $v; |
37 | + } |
|
37 | 38 | return $headers; |
38 | 39 | } |
39 | 40 | } |
@@ -7,4 +7,4 @@ |
||
7 | 7 | */ |
8 | 8 | Trait BoostrapTrait {} |
9 | 9 | |
10 | -require_once __DIR__ . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'bootstrap.php'; |
|
11 | 10 | \ No newline at end of file |
11 | +require_once __DIR__.DIRECTORY_SEPARATOR.'..'.DIRECTORY_SEPARATOR.'..'.DIRECTORY_SEPARATOR.'..'.DIRECTORY_SEPARATOR.'bootstrap.php'; |
|
12 | 12 | \ No newline at end of file |
@@ -82,7 +82,7 @@ discard block |
||
82 | 82 | ResponseHelper::setStatusHeader($this->status_code); |
83 | 83 | ResponseHelper::setAuthHeaders($this->public_zone); |
84 | 84 | ResponseHelper::setCookieHeaders($cookies); |
85 | - header('Content-type: ' . $contentType); |
|
85 | + header('Content-type: '.$contentType); |
|
86 | 86 | |
87 | 87 | } |
88 | 88 | |
@@ -98,16 +98,16 @@ discard block |
||
98 | 98 | Logger::log('Start output response'); |
99 | 99 | ob_start(); |
100 | 100 | $this->setReponseHeaders($contentType, $cookies); |
101 | - header('Content-length: ' . strlen($output)); |
|
101 | + header('Content-length: '.strlen($output)); |
|
102 | 102 | |
103 | 103 | $needCache = Cache::needCache(); |
104 | 104 | if (false !== $needCache && $this->status_code === Template::STATUS_OK && $this->debug === false) { |
105 | 105 | $cache = Cache::getInstance(); |
106 | 106 | Logger::log('Saving output response into cache'); |
107 | 107 | $cacheName = $cache->getRequestCacheHash(); |
108 | - $tmpDir = substr($cacheName, 0, 2) . DIRECTORY_SEPARATOR . substr($cacheName, 2, 2) . DIRECTORY_SEPARATOR; |
|
109 | - $cache->storeData("json" . DIRECTORY_SEPARATOR . $tmpDir . $cacheName, $output); |
|
110 | - $cache->storeData("json" . DIRECTORY_SEPARATOR . $tmpDir . $cacheName . ".headers", headers_list(), Cache::JSON); |
|
108 | + $tmpDir = substr($cacheName, 0, 2).DIRECTORY_SEPARATOR.substr($cacheName, 2, 2).DIRECTORY_SEPARATOR; |
|
109 | + $cache->storeData("json".DIRECTORY_SEPARATOR.$tmpDir.$cacheName, $output); |
|
110 | + $cache->storeData("json".DIRECTORY_SEPARATOR.$tmpDir.$cacheName.".headers", headers_list(), Cache::JSON); |
|
111 | 111 | } |
112 | 112 | echo $output; |
113 | 113 | |
@@ -125,11 +125,11 @@ discard block |
||
125 | 125 | Logger::log('Close template render'); |
126 | 126 | $uri = Request::requestUri(); |
127 | 127 | Security::getInstance()->setSessionKey("lastRequest", array( |
128 | - "url" => Request::getInstance()->getRootUrl() . $uri, |
|
128 | + "url" => Request::getInstance()->getRootUrl().$uri, |
|
129 | 129 | "ts" => microtime(true), |
130 | 130 | )); |
131 | 131 | Security::getInstance()->updateSession(); |
132 | - Logger::log('End request: ' . $uri, LOG_INFO); |
|
132 | + Logger::log('End request: '.$uri, LOG_INFO); |
|
133 | 133 | exit; |
134 | 134 | } |
135 | 135 | |
@@ -167,15 +167,15 @@ discard block |
||
167 | 167 | ///////////////////////////////////////////////////////////// |
168 | 168 | // Date in the past sets the value to already have been expired. |
169 | 169 | header("Expires: Sat, 26 Jul 1997 05:00:00 GMT"); |
170 | - header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT'); |
|
170 | + header('Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT'); |
|
171 | 171 | header('Cache-Control: no-store, no-cache, must-revalidate'); // HTTP/1.1 |
172 | 172 | header('Cache-Control: pre-check=0, post-check=0, max-age=0'); // HTTP/1.1 |
173 | 173 | header("Pragma: no-cache"); |
174 | 174 | header("Expires: 0"); |
175 | 175 | header('Content-Transfer-Encoding: none'); |
176 | - header("Content-type: " . $content); |
|
177 | - header("Content-length: " . strlen($data)); |
|
178 | - header('Content-Disposition: attachment; filename="' . $filename . '"'); |
|
176 | + header("Content-type: ".$content); |
|
177 | + header("Content-length: ".strlen($data)); |
|
178 | + header('Content-Disposition: attachment; filename="'.$filename.'"'); |
|
179 | 179 | echo $data; |
180 | 180 | ob_flush(); |
181 | 181 | ob_end_clean(); |
@@ -35,7 +35,7 @@ discard block |
||
35 | 35 | $use /= 1024; |
36 | 36 | break; |
37 | 37 | case "MBytes": |
38 | - $use /= (1024 * 1024); |
|
38 | + $use /= (1024*1024); |
|
39 | 39 | break; |
40 | 40 | case "Bytes": |
41 | 41 | default: |
@@ -60,7 +60,7 @@ discard block |
||
60 | 60 | { |
61 | 61 | Logger::log('Added handlers for errors'); |
62 | 62 | //Warning & Notice handler |
63 | - set_error_handler(function ($errno, $errstr, $errfile, $errline) { |
|
63 | + set_error_handler(function($errno, $errstr, $errfile, $errline) { |
|
64 | 64 | Logger::log($errstr, LOG_CRIT, ['file' => $errfile, 'line' => $errline, 'errno' => $errno]); |
65 | 65 | return true; |
66 | 66 | }, E_ALL | E_STRICT); |
@@ -74,7 +74,7 @@ discard block |
||
74 | 74 | Logger::log('Initializing stats (mem + ts)'); |
75 | 75 | if (null !== $_SERVER && array_key_exists('REQUEST_TIME_FLOAT', $_SERVER)) { |
76 | 76 | $this->ts = (float)$_SERVER['REQUEST_TIME_FLOAT']; |
77 | - } else { |
|
77 | + }else { |
|
78 | 78 | $this->ts = Request::getInstance()->getTs(); |
79 | 79 | } |
80 | 80 | $this->mem = memory_get_usage(); |
@@ -34,7 +34,7 @@ |
||
34 | 34 | */ |
35 | 35 | public static function dropInstance() { |
36 | 36 | $class = get_called_class(); |
37 | - if(isset(self::$instance[$class])) { |
|
37 | + if (isset(self::$instance[$class])) { |
|
38 | 38 | self::$instance[$class] = null; |
39 | 39 | } |
40 | 40 | } |
@@ -212,7 +212,9 @@ discard block |
||
212 | 212 | */ |
213 | 213 | public function redirect($url = null) |
214 | 214 | { |
215 | - if (null === $url) $url = $this->getServer('HTTP_ORIGIN'); |
|
215 | + if (null === $url) { |
|
216 | + $url = $this->getServer('HTTP_ORIGIN'); |
|
217 | + } |
|
216 | 218 | ob_start(); |
217 | 219 | header('Location: ' . $url); |
218 | 220 | ob_end_clean(); |
@@ -259,7 +261,9 @@ discard block |
||
259 | 261 | $host = $this->getServerName(); |
260 | 262 | $protocol = $protocol ? $this->getProtocol() : ''; |
261 | 263 | $url = ''; |
262 | - if (!empty($host) && !empty($protocol)) $url = $protocol . $host; |
|
264 | + if (!empty($host) && !empty($protocol)) { |
|
265 | + $url = $protocol . $host; |
|
266 | + } |
|
263 | 267 | if (!in_array($this->getServer('SERVER_PORT'), [80, 443])) { |
264 | 268 | $url .= ':' . $this->getServer('SERVER_PORT'); |
265 | 269 | } |
@@ -104,7 +104,7 @@ discard block |
||
104 | 104 | $dump = ''; |
105 | 105 | try { |
106 | 106 | $dump = $this->tpl->render($tpl, $vars); |
107 | - } catch (\Exception $e) { |
|
107 | + }catch (\Exception $e) { |
|
108 | 108 | Logger::log($e->getMessage(), LOG_ERR); |
109 | 109 | } |
110 | 110 | return $dump; |
@@ -218,7 +218,7 @@ discard block |
||
218 | 218 | public function regenerateTemplates() |
219 | 219 | { |
220 | 220 | $this->generateTemplatesCache(); |
221 | - $domains = Cache::getInstance()->getDataFromFile(CONFIG_DIR . DIRECTORY_SEPARATOR . "domains.json", Cache::JSON, true); |
|
221 | + $domains = Cache::getInstance()->getDataFromFile(CONFIG_DIR.DIRECTORY_SEPARATOR."domains.json", Cache::JSON, true); |
|
222 | 222 | $translations = []; |
223 | 223 | if (is_array($domains)) { |
224 | 224 | $translations = $this->parsePathTranslations($domains); |
@@ -240,8 +240,8 @@ discard block |
||
240 | 240 | // force compilation |
241 | 241 | if ($file->isFile()) { |
242 | 242 | try { |
243 | - $this->tpl->load(str_replace($tplDir . '/', '', $file)); |
|
244 | - } catch (\Exception $e) { |
|
243 | + $this->tpl->load(str_replace($tplDir.'/', '', $file)); |
|
244 | + }catch (\Exception $e) { |
|
245 | 245 | Logger::log($e->getMessage(), LOG_ERR, ['file' => $e->getFile(), 'line' => $e->getLine()]); |
246 | 246 | } |
247 | 247 | } |
@@ -315,7 +315,7 @@ discard block |
||
315 | 315 | */ |
316 | 316 | private function loadDomains() |
317 | 317 | { |
318 | - $domains = Cache::getInstance()->getDataFromFile(CONFIG_DIR . DIRECTORY_SEPARATOR . 'domains.json', Cache::JSON, true); |
|
318 | + $domains = Cache::getInstance()->getDataFromFile(CONFIG_DIR.DIRECTORY_SEPARATOR.'domains.json', Cache::JSON, true); |
|
319 | 319 | if (null !== $domains) { |
320 | 320 | foreach ($domains as $domain => $paths) { |
321 | 321 | $this->addPath($paths['template'], preg_replace('/(@|\/)/', '', $domain)); |
@@ -330,7 +330,7 @@ discard block |
||
330 | 330 | { |
331 | 331 | $loader = new \Twig_Loader_Filesystem(GeneratorHelper::getTemplatePath()); |
332 | 332 | $this->tpl = new \Twig_Environment($loader, array( |
333 | - 'cache' => CACHE_DIR . DIRECTORY_SEPARATOR . 'twig', |
|
333 | + 'cache' => CACHE_DIR.DIRECTORY_SEPARATOR.'twig', |
|
334 | 334 | 'debug' => (bool)$this->debug, |
335 | 335 | 'auto_reload' => Config::getParam('twig.auto_reload', TRUE), |
336 | 336 | )); |