@@ -38,9 +38,9 @@ discard block |
||
38 | 38 | |
39 | 39 | } |
40 | 40 | |
41 | - public function set($content=null) { |
|
41 | + public function set($content = null) { |
|
42 | 42 | |
43 | - if ( !is_scalar($content) && $content != null ) { |
|
43 | + if (!is_scalar($content) && $content != null) { |
|
44 | 44 | |
45 | 45 | throw new Exception("Invalid HTTP content"); |
46 | 46 | |
@@ -54,7 +54,7 @@ discard block |
||
54 | 54 | |
55 | 55 | public function type($type = null) { |
56 | 56 | |
57 | - if ( is_null($type) ) { |
|
57 | + if (is_null($type)) { |
|
58 | 58 | |
59 | 59 | return $this->type; |
60 | 60 | |
@@ -68,7 +68,7 @@ discard block |
||
68 | 68 | |
69 | 69 | public function charset($charset = null) { |
70 | 70 | |
71 | - if ( is_null($charset) ) { |
|
71 | + if (is_null($charset)) { |
|
72 | 72 | |
73 | 73 | return $this->charset; |
74 | 74 |
@@ -96,9 +96,9 @@ discard block |
||
96 | 96 | |
97 | 97 | $supported_methods = $this->configuration()->get('supported-http-methods'); |
98 | 98 | |
99 | - if ( is_null($supported_methods) ) $supported_methods = array('GET','PUT','POST','DELETE','OPTIONS','HEAD','TRACE','CONNECT','PURGE'); |
|
99 | + if (is_null($supported_methods)) $supported_methods = array('GET', 'PUT', 'POST', 'DELETE', 'OPTIONS', 'HEAD', 'TRACE', 'CONNECT', 'PURGE'); |
|
100 | 100 | |
101 | - if ( method_exists($this, 'any') ) { |
|
101 | + if (method_exists($this, 'any')) { |
|
102 | 102 | |
103 | 103 | return $supported_methods; |
104 | 104 | |
@@ -106,9 +106,9 @@ discard block |
||
106 | 106 | |
107 | 107 | $implemented_methods = array(); |
108 | 108 | |
109 | - foreach ( $supported_methods as $method ) { |
|
109 | + foreach ($supported_methods as $method) { |
|
110 | 110 | |
111 | - if ( method_exists($this, strtolower($method)) ) array_push($implemented_methods,$method); |
|
111 | + if (method_exists($this, strtolower($method))) array_push($implemented_methods, $method); |
|
112 | 112 | |
113 | 113 | } |
114 | 114 | |
@@ -122,11 +122,11 @@ discard block |
||
122 | 122 | */ |
123 | 123 | public function getMethod($method) { |
124 | 124 | |
125 | - if ( method_exists($this, strtolower($method)) ) { |
|
125 | + if (method_exists($this, strtolower($method))) { |
|
126 | 126 | |
127 | 127 | return strtolower($method); |
128 | 128 | |
129 | - } else if ( method_exists($this, strtolower('any')) ) { |
|
129 | + } else if (method_exists($this, strtolower('any'))) { |
|
130 | 130 | |
131 | 131 | return 'any'; |
132 | 132 |
@@ -96,7 +96,9 @@ discard block |
||
96 | 96 | |
97 | 97 | $supported_methods = $this->configuration()->get('supported-http-methods'); |
98 | 98 | |
99 | - if ( is_null($supported_methods) ) $supported_methods = array('GET','PUT','POST','DELETE','OPTIONS','HEAD','TRACE','CONNECT','PURGE'); |
|
99 | + if ( is_null($supported_methods) ) { |
|
100 | + $supported_methods = array('GET','PUT','POST','DELETE','OPTIONS','HEAD','TRACE','CONNECT','PURGE'); |
|
101 | + } |
|
100 | 102 | |
101 | 103 | if ( method_exists($this, 'any') ) { |
102 | 104 | |
@@ -108,7 +110,9 @@ discard block |
||
108 | 110 | |
109 | 111 | foreach ( $supported_methods as $method ) { |
110 | 112 | |
111 | - if ( method_exists($this, strtolower($method)) ) array_push($implemented_methods,$method); |
|
113 | + if ( method_exists($this, strtolower($method)) ) { |
|
114 | + array_push($implemented_methods,$method); |
|
115 | + } |
|
112 | 116 | |
113 | 117 | } |
114 | 118 |
@@ -90,6 +90,11 @@ |
||
90 | 90 | |
91 | 91 | } |
92 | 92 | |
93 | + /** |
|
94 | + * @param string $key |
|
95 | + * |
|
96 | + * @return string |
|
97 | + */ |
|
93 | 98 | public function getParameter($key) { |
94 | 99 | |
95 | 100 | return (isset($this->parameters[$key]))?$this->parameters[$key]:null; |
@@ -223,7 +223,10 @@ |
||
223 | 223 | */ |
224 | 224 | if (preg_match('/^' . $value['regex'] . '$/', $bits[$key], $matches)) { |
225 | 225 | |
226 | - if (count($matches) == 1) $matches = $matches[0]; // This is the case where no backreferences are present or available. |
|
226 | + if (count($matches) == 1) { |
|
227 | + $matches = $matches[0]; |
|
228 | + } |
|
229 | + // This is the case where no backreferences are present or available. |
|
227 | 230 | |
228 | 231 | // The extracted value (with any backreference available) is added to the query parameters. |
229 | 232 | $this->request->query()->set($key, $matches); |
@@ -72,7 +72,7 @@ discard block |
||
72 | 72 | |
73 | 73 | public function getServiceName() { |
74 | 74 | |
75 | - return (empty($this->service))?"default":implode('.', $this->service); |
|
75 | + return (empty($this->service)) ? "default" : implode('.', $this->service); |
|
76 | 76 | |
77 | 77 | } |
78 | 78 | |
@@ -96,7 +96,7 @@ discard block |
||
96 | 96 | |
97 | 97 | $parameters = $this->parameters; |
98 | 98 | |
99 | - return (isset($parameters[$key]))?$parameters[$key]:null; |
|
99 | + return (isset($parameters[$key])) ? $parameters[$key] : null; |
|
100 | 100 | |
101 | 101 | } |
102 | 102 | |
@@ -126,7 +126,7 @@ discard block |
||
126 | 126 | |
127 | 127 | $parameters = $this->request; |
128 | 128 | |
129 | - return (isset($parameters[$key]))?$parameters[$key]:null; |
|
129 | + return (isset($parameters[$key])) ? $parameters[$key] : null; |
|
130 | 130 | |
131 | 131 | } |
132 | 132 | |
@@ -169,7 +169,7 @@ discard block |
||
169 | 169 | |
170 | 170 | $query = $this->query; |
171 | 171 | |
172 | - return isset($query[$key])?$query[$key]["required"]:false; |
|
172 | + return isset($query[$key]) ? $query[$key]["required"] : false; |
|
173 | 173 | |
174 | 174 | } |
175 | 175 | |
@@ -177,7 +177,7 @@ discard block |
||
177 | 177 | |
178 | 178 | $query = $this->query; |
179 | 179 | |
180 | - return isset($query[$key])?$query[$key]["regex"]:null; |
|
180 | + return isset($query[$key]) ? $query[$key]["regex"] : null; |
|
181 | 181 | |
182 | 182 | } |
183 | 183 | |
@@ -218,7 +218,7 @@ discard block |
||
218 | 218 | /* if it's available a bit associated with the parameter name, it is compared against |
219 | 219 | * it's regular expression in order to extrect backreferences |
220 | 220 | */ |
221 | - if (preg_match('/^' . $value['regex'] . '$/', $path[$key], $matches)) { |
|
221 | + if (preg_match('/^'.$value['regex'].'$/', $path[$key], $matches)) { |
|
222 | 222 | |
223 | 223 | if (count($matches) == 1) $matches = $matches[0]; // This is the case where no backreferences are present or available. |
224 | 224 |
@@ -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 |
@@ -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 |
@@ -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,7 +140,9 @@ 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 | |
@@ -157,7 +160,9 @@ discard block |
||
157 | 160 | |
158 | 161 | private function dumpCache() { |
159 | 162 | |
160 | - if ( $this->configuration->get('routing-table-cache') !== true ) return; |
|
163 | + if ( $this->configuration->get('routing-table-cache') !== true ) { |
|
164 | + return; |
|
165 | + } |
|
161 | 166 | |
162 | 167 | $ttl = $this->configuration->get('routing-table-ttl'); |
163 | 168 |
@@ -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,11 +139,11 @@ 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 | $data = $this->cache->read(); |
145 | 145 | |
146 | - if ( is_null($data) ) { |
|
146 | + if (is_null($data)) { |
|
147 | 147 | |
148 | 148 | $this->routes = []; |
149 | 149 | |
@@ -159,11 +159,11 @@ discard block |
||
159 | 159 | |
160 | 160 | private function dumpCache() { |
161 | 161 | |
162 | - if ( $this->configuration->get('routing-table-cache') !== true ) return; |
|
162 | + if ($this->configuration->get('routing-table-cache') !== true) return; |
|
163 | 163 | |
164 | 164 | $ttl = $this->configuration->get('routing-table-ttl'); |
165 | 165 | |
166 | - if ( $this->cache->dump($this->routes, $ttl) ) { |
|
166 | + if ($this->cache->dump($this->routes, $ttl)) { |
|
167 | 167 | $this->logger->debug("Routing table saved to cache"); |
168 | 168 | } else { |
169 | 169 | $this->logger->warning("Cannot save routing table to cache"); |
@@ -180,14 +180,14 @@ discard block |
||
180 | 180 | ->setClassName($class) // Class to be invoked |
181 | 181 | ->setParameters($parameters); // Parameters passed via the composer.json configuration (cache, ttl, etc...) |
182 | 182 | |
183 | - $this->logger->debug("ROUTE: " . implode("/", $folders)); |
|
183 | + $this->logger->debug("ROUTE: ".implode("/", $folders)); |
|
184 | 184 | |
185 | 185 | //$this->logger->debug("PARAMETERS: " . var_export($value, true)); |
186 | 186 | |
187 | 187 | // This method generate a global regular expression which will be able to match all the URI supported by the route |
188 | 188 | $regex = $this->parser->read($folders, $route); |
189 | 189 | |
190 | - $this->logger->debug("ROUTE: " . $regex); |
|
190 | + $this->logger->debug("ROUTE: ".$regex); |
|
191 | 191 | |
192 | 192 | //$this->logger->debug("PARAMETERS: " . var_export($value, true)); |
193 | 193 |