@@ -47,7 +47,7 @@ discard block |
||
47 | 47 | |
48 | 48 | $cache_object = $this->getCache()->setNamespace(self::$cache_namespace)->get($name); |
49 | 49 | |
50 | - if ( is_null($cache_object) ) return false; |
|
50 | + if (is_null($cache_object)) return false; |
|
51 | 51 | |
52 | 52 | $response->import($cache_object); |
53 | 53 | |
@@ -67,15 +67,15 @@ discard block |
||
67 | 67 | |
68 | 68 | $name = self::getCacheName($request); |
69 | 69 | |
70 | - $method = (string) $request->getMethod(); |
|
70 | + $method = (string)$request->getMethod(); |
|
71 | 71 | |
72 | 72 | $status = $response->getStatus()->get(); |
73 | 73 | |
74 | 74 | if ( |
75 | - ( $cache == 'SERVER' || $cache == 'BOTH' ) && |
|
75 | + ($cache == 'SERVER' || $cache == 'BOTH') && |
|
76 | 76 | in_array($method, self::$cachable_methods) && |
77 | 77 | in_array($status, self::$cachable_statuses) |
78 | - ){ |
|
78 | + ) { |
|
79 | 79 | |
80 | 80 | $this->getCache() |
81 | 81 | ->setNamespace(self::$cache_namespace) |
@@ -87,7 +87,7 @@ discard block |
||
87 | 87 | |
88 | 88 | private static function getCacheName(Request $request) { |
89 | 89 | |
90 | - return md5( (string) $request->getMethod() . (string) $request->getUri() ); |
|
90 | + return md5((string)$request->getMethod().(string)$request->getUri()); |
|
91 | 91 | |
92 | 92 | } |
93 | 93 |
@@ -47,7 +47,9 @@ |
||
47 | 47 | |
48 | 48 | $cache_object = $this->getCache()->setNamespace(self::$cache_namespace)->get($name); |
49 | 49 | |
50 | - if ( is_null($cache_object) ) return false; |
|
50 | + if ( is_null($cache_object) ) { |
|
51 | + return false; |
|
52 | + } |
|
51 | 53 | |
52 | 54 | $response->import($cache_object); |
53 | 55 |
@@ -48,7 +48,7 @@ discard block |
||
48 | 48 | use ResponseTrait; |
49 | 49 | use ExtraTrait; |
50 | 50 | |
51 | - protected static $supported_methods = ['GET','PUT','POST','DELETE','OPTIONS','HEAD','TRACE','CONNECT','PURGE']; |
|
51 | + protected static $supported_methods = ['GET', 'PUT', 'POST', 'DELETE', 'OPTIONS', 'HEAD', 'TRACE', 'CONNECT', 'PURGE']; |
|
52 | 52 | |
53 | 53 | public function __construct( |
54 | 54 | Configuration $configuration, |
@@ -81,9 +81,9 @@ discard block |
||
81 | 81 | |
82 | 82 | $supported_methods = $this->getConfiguration()->get('supported-http-methods'); |
83 | 83 | |
84 | - if ( is_null($supported_methods) ) $supported_methods = self::$supported_methods; |
|
84 | + if (is_null($supported_methods)) $supported_methods = self::$supported_methods; |
|
85 | 85 | |
86 | - if ( method_exists($this, 'any') ) { |
|
86 | + if (method_exists($this, 'any')) { |
|
87 | 87 | |
88 | 88 | return $supported_methods; |
89 | 89 | |
@@ -91,9 +91,9 @@ discard block |
||
91 | 91 | |
92 | 92 | $implemented_methods = []; |
93 | 93 | |
94 | - foreach ( $supported_methods as $method ) { |
|
94 | + foreach ($supported_methods as $method) { |
|
95 | 95 | |
96 | - if ( method_exists($this, strtolower($method)) ) array_push($implemented_methods, $method); |
|
96 | + if (method_exists($this, strtolower($method))) array_push($implemented_methods, $method); |
|
97 | 97 | |
98 | 98 | } |
99 | 99 | |
@@ -109,11 +109,11 @@ discard block |
||
109 | 109 | |
110 | 110 | $method = strtolower($method); |
111 | 111 | |
112 | - if ( method_exists($this, $method) ) { |
|
112 | + if (method_exists($this, $method)) { |
|
113 | 113 | |
114 | 114 | return $method; |
115 | 115 | |
116 | - } else if ( method_exists($this, 'any') ) { |
|
116 | + } else if (method_exists($this, 'any')) { |
|
117 | 117 | |
118 | 118 | return 'any'; |
119 | 119 |
@@ -81,7 +81,9 @@ discard block |
||
81 | 81 | |
82 | 82 | $supported_methods = $this->getConfiguration()->get('supported-http-methods'); |
83 | 83 | |
84 | - if ( is_null($supported_methods) ) $supported_methods = self::$supported_methods; |
|
84 | + if ( is_null($supported_methods) ) { |
|
85 | + $supported_methods = self::$supported_methods; |
|
86 | + } |
|
85 | 87 | |
86 | 88 | if ( method_exists($this, 'any') ) { |
87 | 89 | |
@@ -93,7 +95,9 @@ discard block |
||
93 | 95 | |
94 | 96 | foreach ( $supported_methods as $method ) { |
95 | 97 | |
96 | - if ( method_exists($this, strtolower($method)) ) array_push($implemented_methods, $method); |
|
98 | + if ( method_exists($this, strtolower($method)) ) { |
|
99 | + array_push($implemented_methods, $method); |
|
100 | + } |
|
97 | 101 | |
98 | 102 | } |
99 | 103 |
@@ -41,9 +41,9 @@ |
||
41 | 41 | |
42 | 42 | } |
43 | 43 | |
44 | - public function set($content=null) { |
|
44 | + public function set($content = null) { |
|
45 | 45 | |
46 | - if ( !is_scalar($content) && $content != null ) { |
|
46 | + if (!is_scalar($content) && $content != null) { |
|
47 | 47 | |
48 | 48 | throw new Exception("Invalid HTTP content"); |
49 | 49 |
@@ -35,7 +35,7 @@ discard block |
||
35 | 35 | |
36 | 36 | use TimingTrait; |
37 | 37 | |
38 | - protected static $no_content_statuses = [100,101,102,204,304]; |
|
38 | + protected static $no_content_statuses = [100, 101, 102, 204, 304]; |
|
39 | 39 | |
40 | 40 | protected static $cacheable_methods = ['GET', 'HEAD', 'POST', 'PUT']; |
41 | 41 | |
@@ -137,7 +137,7 @@ discard block |
||
137 | 137 | |
138 | 138 | public function export() { |
139 | 139 | |
140 | - return (object) [ |
|
140 | + return (object)[ |
|
141 | 141 | 'headers' => $this->getHeaders(), |
142 | 142 | 'cookies' => $this->getCookies()->getAll(), |
143 | 143 | 'status' => $this->getStatus(), |
@@ -149,12 +149,12 @@ discard block |
||
149 | 149 | |
150 | 150 | public function import($data) { |
151 | 151 | |
152 | - if ( isset($data->headers) ) $this->setHeaders($data->headers); |
|
153 | - if ( isset($data->status) ) $this->setStatus($data->status); |
|
154 | - if ( isset($data->content) ) $this->setContent($data->content); |
|
155 | - if ( isset($data->location) ) $this->setLocation($data->location); |
|
152 | + if (isset($data->headers)) $this->setHeaders($data->headers); |
|
153 | + if (isset($data->status)) $this->setStatus($data->status); |
|
154 | + if (isset($data->content)) $this->setContent($data->content); |
|
155 | + if (isset($data->location)) $this->setLocation($data->location); |
|
156 | 156 | |
157 | - if ( isset($data->cookies) && is_array($data->cookies) ) { |
|
157 | + if (isset($data->cookies) && is_array($data->cookies)) { |
|
158 | 158 | $cookies = $this->getCookies(); |
159 | 159 | foreach ($data->cookies as $name => $cookie) $cookies->add($cookie); |
160 | 160 | } |
@@ -168,7 +168,7 @@ discard block |
||
168 | 168 | $output_class_name = "\\Comodojo\\Dispatcher\\Response\\Preprocessor\\Status".$status; |
169 | 169 | |
170 | 170 | // @TODO: this condition will be removed when all preprocessors ready |
171 | - if ( class_exists($output_class_name) ) { |
|
171 | + if (class_exists($output_class_name)) { |
|
172 | 172 | $output = new $output_class_name($this); |
173 | 173 | } else { |
174 | 174 | $output = new \Comodojo\Dispatcher\Response\Preprocessor\Status200($this); |
@@ -176,7 +176,7 @@ discard block |
||
176 | 176 | |
177 | 177 | $output->consolidate(); |
178 | 178 | |
179 | - if ( $route != null ) { |
|
179 | + if ($route != null) { |
|
180 | 180 | $this->setClientCache($request, $route); |
181 | 181 | } |
182 | 182 | |
@@ -184,7 +184,7 @@ discard block |
||
184 | 184 | $content = $this->getContent(); |
185 | 185 | $headers = $this->getHeaders(); |
186 | 186 | |
187 | - if ( (string) $request->getMethod() == 'HEAD' && !in_array($status, self::$no_content_statuses) ) { |
|
187 | + if ((string)$request->getMethod() == 'HEAD' && !in_array($status, self::$no_content_statuses)) { |
|
188 | 188 | $length = $content->length(); |
189 | 189 | $content->set(null); |
190 | 190 | if ($length) $headers->set('Content-Length', $length); |
@@ -194,7 +194,7 @@ discard block |
||
194 | 194 | $headers->delete('Content-Length'); |
195 | 195 | } |
196 | 196 | |
197 | - if ( (string) $request->getVersion() == '1.0' && false !== strpos($headers->get('Cache-Control'), 'no-cache')) { |
|
197 | + if ((string)$request->getVersion() == '1.0' && false !== strpos($headers->get('Cache-Control'), 'no-cache')) { |
|
198 | 198 | $headers->set('pragma', 'no-cache'); |
199 | 199 | $headers->set('expires', -1); |
200 | 200 | } |
@@ -204,20 +204,20 @@ discard block |
||
204 | 204 | private function setClientCache(Request $request, Route $route) { |
205 | 205 | |
206 | 206 | $cache = strtoupper($route->getParameter('cache')); |
207 | - $ttl = (int) $route->getParameter('ttl'); |
|
207 | + $ttl = (int)$route->getParameter('ttl'); |
|
208 | 208 | |
209 | 209 | if ( |
210 | 210 | ($cache == 'CLIENT' || $cache == 'BOTH') && |
211 | - in_array((string) $request->getMethod(), self::$cacheable_methods) && |
|
211 | + in_array((string)$request->getMethod(), self::$cacheable_methods) && |
|
212 | 212 | in_array($this->getStatus()->get(), self::$cacheable_statuses) |
213 | 213 | // @TODO: here we should also check for Cache-Control no-store or private; |
214 | 214 | // the cache layer will be improoved in future versions. |
215 | 215 | ) { |
216 | 216 | |
217 | 217 | $headers = $this->getHeaders(); |
218 | - $timestamp = (int) $this->getTime()->format('U') + $ttl; |
|
218 | + $timestamp = (int)$this->getTime()->format('U')+$ttl; |
|
219 | 219 | |
220 | - if ( $ttl > 0 ) { |
|
220 | + if ($ttl > 0) { |
|
221 | 221 | |
222 | 222 | $headers->set("Cache-Control", "max-age=".$ttl.", must-revalidate"); |
223 | 223 | $headers->set("Expires", gmdate("D, d M Y H:i:s", $timestamp)." GMT"); |
@@ -149,14 +149,24 @@ discard block |
||
149 | 149 | |
150 | 150 | public function import($data) { |
151 | 151 | |
152 | - if ( isset($data->headers) ) $this->setHeaders($data->headers); |
|
153 | - if ( isset($data->status) ) $this->setStatus($data->status); |
|
154 | - if ( isset($data->content) ) $this->setContent($data->content); |
|
155 | - if ( isset($data->location) ) $this->setLocation($data->location); |
|
152 | + if ( isset($data->headers) ) { |
|
153 | + $this->setHeaders($data->headers); |
|
154 | + } |
|
155 | + if ( isset($data->status) ) { |
|
156 | + $this->setStatus($data->status); |
|
157 | + } |
|
158 | + if ( isset($data->content) ) { |
|
159 | + $this->setContent($data->content); |
|
160 | + } |
|
161 | + if ( isset($data->location) ) { |
|
162 | + $this->setLocation($data->location); |
|
163 | + } |
|
156 | 164 | |
157 | 165 | if ( isset($data->cookies) && is_array($data->cookies) ) { |
158 | 166 | $cookies = $this->getCookies(); |
159 | - foreach ($data->cookies as $name => $cookie) $cookies->add($cookie); |
|
167 | + foreach ($data->cookies as $name => $cookie) { |
|
168 | + $cookies->add($cookie); |
|
169 | + } |
|
160 | 170 | } |
161 | 171 | |
162 | 172 | } |
@@ -187,7 +197,9 @@ discard block |
||
187 | 197 | if ( (string) $request->getMethod() == 'HEAD' && !in_array($status, self::$no_content_statuses) ) { |
188 | 198 | $length = $content->length(); |
189 | 199 | $content->set(null); |
190 | - if ($length) $headers->set('Content-Length', $length); |
|
200 | + if ($length) { |
|
201 | + $headers->set('Content-Length', $length); |
|
202 | + } |
|
191 | 203 | } |
192 | 204 | |
193 | 205 | if ($headers->get('Transfer-Encoding') != null) { |