@@ -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) { |