@@ -41,7 +41,7 @@ |
||
41 | 41 | * |
42 | 42 | * @param string $data Serialized data |
43 | 43 | * |
44 | - * @return Routes $this |
|
44 | + * @return boolean $this |
|
45 | 45 | */ |
46 | 46 | public function unserialize($data) { |
47 | 47 |
@@ -62,7 +62,7 @@ discard block |
||
62 | 62 | $output_class_name = "\\Comodojo\\Dispatcher\\Response\\Preprocessor\\Status".$status; |
63 | 63 | |
64 | 64 | // @TODO: this condition will be removed when all preprocessors ready |
65 | - if ( class_exists($output_class_name) ) { |
|
65 | + if (class_exists($output_class_name)) { |
|
66 | 66 | $output = new $output_class_name($this); |
67 | 67 | } else { |
68 | 68 | $output = new \Comodojo\Dispatcher\Response\Preprocessor\Status200($this); |
@@ -70,13 +70,13 @@ discard block |
||
70 | 70 | |
71 | 71 | $output->consolidate(); |
72 | 72 | |
73 | - if ( $route != null ) { |
|
73 | + if ($route != null) { |
|
74 | 74 | $this->setClientCache($request, $route); |
75 | 75 | } |
76 | 76 | |
77 | 77 | // extra checks |
78 | 78 | |
79 | - if ( $request->method->get() == 'HEAD' && !in_array($status, array(100,101,102,204,304)) ) { |
|
79 | + if ($request->method->get() == 'HEAD' && !in_array($status, array(100, 101, 102, 204, 304))) { |
|
80 | 80 | $length = $this->content->length(); |
81 | 81 | $this->content->set(null); |
82 | 82 | if ($length) $this->headers->set('Content-Length', $length); |
@@ -86,7 +86,7 @@ discard block |
||
86 | 86 | $this->headers->delete('Content-Length'); |
87 | 87 | } |
88 | 88 | |
89 | - if ( $request->version->get() == '1.0' && false !== strpos($this->headers->get('Cache-Control'), 'no-cache')) { |
|
89 | + if ($request->version->get() == '1.0' && false !== strpos($this->headers->get('Cache-Control'), 'no-cache')) { |
|
90 | 90 | $this->headers->set('pragma', 'no-cache'); |
91 | 91 | $this->headers->set('expires', -1); |
92 | 92 | } |
@@ -106,15 +106,15 @@ discard block |
||
106 | 106 | // the cache layer will be improoved in future versions. |
107 | 107 | ) { |
108 | 108 | |
109 | - if ( $ttl > 0 ) { |
|
109 | + if ($ttl > 0) { |
|
110 | 110 | |
111 | - $this->headers->set("Cache-Control","max-age=".$ttl.", must-revalidate"); |
|
112 | - $this->headers->set("Expires",gmdate("D, d M Y H:i:s", (int)$this->getTimestamp() + $ttl)." GMT"); |
|
111 | + $this->headers->set("Cache-Control", "max-age=".$ttl.", must-revalidate"); |
|
112 | + $this->headers->set("Expires", gmdate("D, d M Y H:i:s", (int)$this->getTimestamp()+$ttl)." GMT"); |
|
113 | 113 | |
114 | 114 | } else { |
115 | 115 | |
116 | - $this->headers->set("Cache-Control","no-cache, must-revalidate"); |
|
117 | - $this->headers->set("Expires","Mon, 26 Jul 1997 05:00:00 GMT"); |
|
116 | + $this->headers->set("Cache-Control", "no-cache, must-revalidate"); |
|
117 | + $this->headers->set("Expires", "Mon, 26 Jul 1997 05:00:00 GMT"); |
|
118 | 118 | |
119 | 119 | } |
120 | 120 |
@@ -79,7 +79,9 @@ |
||
79 | 79 | if ( $request->method->get() == 'HEAD' && !in_array($status, array(100,101,102,204,304)) ) { |
80 | 80 | $length = $this->content->length(); |
81 | 81 | $this->content->set(null); |
82 | - if ($length) $this->headers->set('Content-Length', $length); |
|
82 | + if ($length) { |
|
83 | + $this->headers->set('Content-Length', $length); |
|
84 | + } |
|
83 | 85 | } |
84 | 86 | |
85 | 87 | if ($this->headers->get('Transfer-Encoding') != null) { |
@@ -48,7 +48,7 @@ discard block |
||
48 | 48 | |
49 | 49 | public function set($code) { |
50 | 50 | |
51 | - if ( !$this->codes->exists($code) ) { |
|
51 | + if (!$this->codes->exists($code)) { |
|
52 | 52 | |
53 | 53 | throw new Exception("Invalid HTTP Status Code $code"); |
54 | 54 | |
@@ -60,9 +60,9 @@ discard block |
||
60 | 60 | |
61 | 61 | } |
62 | 62 | |
63 | - public function description($code=null) { |
|
63 | + public function description($code = null) { |
|
64 | 64 | |
65 | - if ( is_null($code) ) return $this->codes->getMessage($this->status_code); |
|
65 | + if (is_null($code)) return $this->codes->getMessage($this->status_code); |
|
66 | 66 | |
67 | 67 | return $this->codes->getMessage($code); |
68 | 68 |
@@ -62,7 +62,9 @@ |
||
62 | 62 | |
63 | 63 | public function description($code=null) { |
64 | 64 | |
65 | - if ( is_null($code) ) return $this->codes->getMessage($this->status_code); |
|
65 | + if ( is_null($code) ) { |
|
66 | + return $this->codes->getMessage($this->status_code); |
|
67 | + } |
|
66 | 68 | |
67 | 69 | return $this->codes->getMessage($code); |
68 | 70 |
@@ -30,7 +30,7 @@ |
||
30 | 30 | |
31 | 31 | $location = $this->response->location->get(); |
32 | 32 | |
33 | - if ( $location != null ) $this->response->headers->set("Location: ".$location); |
|
33 | + if ($location != null) $this->response->headers->set("Location: ".$location); |
|
34 | 34 | |
35 | 35 | parent::consolidate(); |
36 | 36 |
@@ -30,7 +30,9 @@ |
||
30 | 30 | |
31 | 31 | $location = $this->response->location->get(); |
32 | 32 | |
33 | - if ( $location != null ) $this->response->headers->set("Location: ".$location); |
|
33 | + if ( $location != null ) { |
|
34 | + $this->response->headers->set("Location: ".$location); |
|
35 | + } |
|
34 | 36 | |
35 | 37 | parent::consolidate(); |
36 | 38 |
@@ -61,7 +61,7 @@ |
||
61 | 61 | |
62 | 62 | $status = $this->response->status->get(); |
63 | 63 | |
64 | - if ( !$this->codes->exists($status) ) throw new Exception("Invalid HTTP status code in response"); |
|
64 | + if (!$this->codes->exists($status)) throw new Exception("Invalid HTTP status code in response"); |
|
65 | 65 | |
66 | 66 | $message = $this->codes->getMessage($status); |
67 | 67 |
@@ -61,7 +61,9 @@ |
||
61 | 61 | |
62 | 62 | $status = $this->response->status->get(); |
63 | 63 | |
64 | - if ( !$this->codes->exists($status) ) throw new Exception("Invalid HTTP status code in response"); |
|
64 | + if ( !$this->codes->exists($status) ) { |
|
65 | + throw new Exception("Invalid HTTP status code in response"); |
|
66 | + } |
|
65 | 67 | |
66 | 68 | $message = $this->codes->getMessage($status); |
67 | 69 |
@@ -29,7 +29,7 @@ |
||
29 | 29 | |
30 | 30 | public function __get($name) { |
31 | 31 | |
32 | - if ( array_key_exists($name, $this->data) ) { |
|
32 | + if (array_key_exists($name, $this->data)) { |
|
33 | 33 | |
34 | 34 | return $this->data[$name]; |
35 | 35 |
@@ -62,7 +62,7 @@ discard block |
||
62 | 62 | public function getLocalName() { |
63 | 63 | |
64 | 64 | if (!empty($this->path)) |
65 | - return $this->path . "/" . $this->slug; |
|
65 | + return $this->path."/".$this->slug; |
|
66 | 66 | else |
67 | 67 | return ''; |
68 | 68 | |
@@ -117,7 +117,7 @@ discard block |
||
117 | 117 | !empty($this->path) && |
118 | 118 | !empty($this->slug) && |
119 | 119 | file_exists($this->getLocalName()) && |
120 | - file_exists($this->getLocalName() . ".data") |
|
120 | + file_exists($this->getLocalName().".data") |
|
121 | 121 | ); |
122 | 122 | |
123 | 123 | } |
@@ -202,7 +202,7 @@ discard block |
||
202 | 202 | |
203 | 203 | private function loadFileInfo() { |
204 | 204 | |
205 | - $info = $this->getLocalName() . ".data"; |
|
205 | + $info = $this->getLocalName().".data"; |
|
206 | 206 | |
207 | 207 | if (file_exists($info)) { |
208 | 208 | |
@@ -223,7 +223,7 @@ discard block |
||
223 | 223 | |
224 | 224 | private function saveFileInfo() { |
225 | 225 | |
226 | - $info = $this->getLocalName() . ".data"; |
|
226 | + $info = $this->getLocalName().".data"; |
|
227 | 227 | |
228 | 228 | if (!empty($this->path) && file_exists($this->path)) { |
229 | 229 | |
@@ -248,17 +248,17 @@ discard block |
||
248 | 248 | |
249 | 249 | preg_match_all("/[a-z0-9]+/", iconv("UTF-8", "ASCII//TRANSLIT", strtolower(preg_replace('/\..*?$/', '', $this->fname))), $matches); |
250 | 250 | |
251 | - $this->slug = implode('-', $matches[0]); |
|
251 | + $this->slug = implode('-', $matches[0]); |
|
252 | 252 | |
253 | 253 | if (!empty($this->path)) { |
254 | 254 | |
255 | - $files = glob($this->path . "/" . $slug . "*"); |
|
255 | + $files = glob($this->path."/".$slug."*"); |
|
256 | 256 | |
257 | - $count = count ($files); |
|
257 | + $count = count($files); |
|
258 | 258 | |
259 | 259 | if ($count > 0) { |
260 | 260 | |
261 | - $this->slug .= "-" . $count; |
|
261 | + $this->slug .= "-".$count; |
|
262 | 262 | |
263 | 263 | } |
264 | 264 |
@@ -61,10 +61,11 @@ discard block |
||
61 | 61 | |
62 | 62 | public function getLocalName() { |
63 | 63 | |
64 | - if (!empty($this->path)) |
|
65 | - return $this->path . "/" . $this->slug; |
|
66 | - else |
|
67 | - return ''; |
|
64 | + if (!empty($this->path)) { |
|
65 | + return $this->path . "/" . $this->slug; |
|
66 | + } else { |
|
67 | + return ''; |
|
68 | + } |
|
68 | 69 | |
69 | 70 | } |
70 | 71 | |
@@ -101,11 +102,13 @@ discard block |
||
101 | 102 | public function getFileData() { |
102 | 103 | |
103 | 104 | $file = $this->getTemporaryName(); |
104 | - if (empty($file)) |
|
105 | - $file = $this->getLocalName(); |
|
105 | + if (empty($file)) { |
|
106 | + $file = $this->getLocalName(); |
|
107 | + } |
|
106 | 108 | |
107 | - if (file_exists($file)) |
|
108 | - return file_get_contents($file); |
|
109 | + if (file_exists($file)) { |
|
110 | + return file_get_contents($file); |
|
111 | + } |
|
109 | 112 | |
110 | 113 | throw new DispatcherException("File does not exists"); |
111 | 114 |
@@ -121,9 +121,9 @@ discard block |
||
121 | 121 | |
122 | 122 | public function load($routes) { |
123 | 123 | |
124 | - if ( !empty($routes) ) { |
|
124 | + if (!empty($routes)) { |
|
125 | 125 | |
126 | - foreach( $routes as $name => $route ) { |
|
126 | + foreach ($routes as $name => $route) { |
|
127 | 127 | |
128 | 128 | $this->add($route['route'], $route['type'], $route['class'], $route['parameters']); |
129 | 129 | |
@@ -139,7 +139,7 @@ discard block |
||
139 | 139 | |
140 | 140 | private function readCache() { |
141 | 141 | |
142 | - if ( $this->configuration->get('routing-table-cache') !== true ) return; |
|
142 | + if ($this->configuration->get('routing-table-cache') !== true) return; |
|
143 | 143 | |
144 | 144 | $this->routes = $this->cache->setNamespace('dispatcherinternals')->get("dispatcher-routes"); |
145 | 145 | |
@@ -151,7 +151,7 @@ discard block |
||
151 | 151 | |
152 | 152 | private function dumpCache() { |
153 | 153 | |
154 | - if ( $this->configuration->get('routing-table-cache') !== true ) return; |
|
154 | + if ($this->configuration->get('routing-table-cache') !== true) return; |
|
155 | 155 | |
156 | 156 | $ttl = $this->configuration->get('routing-table-ttl'); |
157 | 157 | |
@@ -170,14 +170,14 @@ discard block |
||
170 | 170 | ->setClassName($class) // Class to be invoked |
171 | 171 | ->setParameters($parameters); // Parameters passed via the composer.json configuration (cache, ttl, etc...) |
172 | 172 | |
173 | - $this->logger->debug("ROUTE: " . implode("/", $folders)); |
|
173 | + $this->logger->debug("ROUTE: ".implode("/", $folders)); |
|
174 | 174 | |
175 | 175 | //$this->logger->debug("PARAMETERS: " . var_export($value, true)); |
176 | 176 | |
177 | 177 | // This method generate a global regular expression which will be able to match all the URI supported by the route |
178 | 178 | $regex = $this->parser->read($folders, $route); |
179 | 179 | |
180 | - $this->logger->debug("ROUTE: " . $regex); |
|
180 | + $this->logger->debug("ROUTE: ".$regex); |
|
181 | 181 | |
182 | 182 | //$this->logger->debug("PARAMETERS: " . var_export($value, true)); |
183 | 183 |
@@ -78,10 +78,11 @@ discard block |
||
78 | 78 | |
79 | 79 | $regex = $this->regex($route); |
80 | 80 | |
81 | - if (isset($this->routes[$regex])) |
|
82 | - return $this->routes[$regex]; |
|
83 | - else |
|
84 | - return null; |
|
81 | + if (isset($this->routes[$regex])) { |
|
82 | + return $this->routes[$regex]; |
|
83 | + } else { |
|
84 | + return null; |
|
85 | + } |
|
85 | 86 | |
86 | 87 | } |
87 | 88 | |
@@ -139,11 +140,15 @@ discard block |
||
139 | 140 | |
140 | 141 | private function readCache() { |
141 | 142 | |
142 | - if ( $this->configuration->get('routing-table-cache') !== true ) return; |
|
143 | + if ( $this->configuration->get('routing-table-cache') !== true ) { |
|
144 | + return; |
|
145 | + } |
|
143 | 146 | |
144 | 147 | $this->routes = $this->cache->setNamespace('dispatcherinternals')->get("dispatcher-routes"); |
145 | 148 | |
146 | - if (is_null($routes)) return; |
|
149 | + if (is_null($routes)) { |
|
150 | + return; |
|
151 | + } |
|
147 | 152 | |
148 | 153 | $this->logger->debug("Routing table loaded from cache"); |
149 | 154 | |
@@ -151,7 +156,9 @@ discard block |
||
151 | 156 | |
152 | 157 | private function dumpCache() { |
153 | 158 | |
154 | - if ( $this->configuration->get('routing-table-cache') !== true ) return; |
|
159 | + if ( $this->configuration->get('routing-table-cache') !== true ) { |
|
160 | + return; |
|
161 | + } |
|
155 | 162 | |
156 | 163 | $ttl = $this->configuration->get('routing-table-ttl'); |
157 | 164 |
@@ -102,7 +102,7 @@ |
||
102 | 102 | |
103 | 103 | public function getMessage($code) { |
104 | 104 | |
105 | - if ( $this->exists($code) ) return $this->codes[$code]; |
|
105 | + if ($this->exists($code)) return $this->codes[$code]; |
|
106 | 106 | |
107 | 107 | throw new Exception("Invalid HTTP status code $code"); |
108 | 108 |
@@ -102,7 +102,9 @@ |
||
102 | 102 | |
103 | 103 | public function getMessage($code) { |
104 | 104 | |
105 | - if ( $this->exists($code) ) return $this->codes[$code]; |
|
105 | + if ( $this->exists($code) ) { |
|
106 | + return $this->codes[$code]; |
|
107 | + } |
|
106 | 108 | |
107 | 109 | throw new Exception("Invalid HTTP status code $code"); |
108 | 110 |