@@ -80,8 +80,8 @@ |
||
80 | 80 | protected $error_message; |
81 | 81 | |
82 | 82 | /** |
83 | - * @var array |
|
84 | - */ |
|
83 | + * @var array |
|
84 | + */ |
|
85 | 85 | protected $parameters = []; |
86 | 86 | |
87 | 87 | /** |
@@ -357,13 +357,13 @@ discard block |
||
357 | 357 | public function path($path) { |
358 | 358 | |
359 | 359 | // Because of the nature of the global regular expression, all the bits of the matched route are associated with a parameter key |
360 | - foreach ($this->query as $key => $value) { |
|
360 | + foreach ( $this->query as $key => $value ) { |
|
361 | 361 | |
362 | 362 | if ( isset($path[$key]) ) { |
363 | 363 | /* if it's available a bit associated with the parameter name, it is compared against |
364 | 364 | * it's regular expression in order to extrect backreferences |
365 | 365 | */ |
366 | - if ( preg_match('/^' . $value['regex'] . '$/', $path[$key], $matches) ) { |
|
366 | + if ( preg_match('/^'.$value['regex'].'$/', $path[$key], $matches) ) { |
|
367 | 367 | |
368 | 368 | if ( count($matches) == 1 ) $matches = $matches[0]; // This is the case where no backreferences are present or available. |
369 | 369 | |
@@ -372,7 +372,7 @@ discard block |
||
372 | 372 | |
373 | 373 | } |
374 | 374 | |
375 | - } elseif ($value['required']) { |
|
375 | + } elseif ( $value['required'] ) { |
|
376 | 376 | |
377 | 377 | throw new DispatcherException(sprintf("Required parameter '%s' not specified.", $key), 1, null, 500); |
378 | 378 | |
@@ -391,7 +391,7 @@ discard block |
||
391 | 391 | */ |
392 | 392 | public function serialize() { |
393 | 393 | |
394 | - return serialize( (object) [ |
|
394 | + return serialize((object)[ |
|
395 | 395 | 'classname' => $this->classname, |
396 | 396 | 'type' => $this->type, |
397 | 397 | 'service' => $this->service, |
@@ -107,11 +107,11 @@ discard block |
||
107 | 107 | |
108 | 108 | public function route(Request $request) { |
109 | 109 | |
110 | - $method = (string) $request->getMethod(); |
|
110 | + $method = (string)$request->getMethod(); |
|
111 | 111 | |
112 | 112 | $methods = $this->configuration->get('allowed-http-methods'); |
113 | 113 | |
114 | - if (!empty($methods) && in_array($method, $methods) === false) { |
|
114 | + if ( !empty($methods) && in_array($method, $methods) === false ) { |
|
115 | 115 | |
116 | 116 | throw new DispatcherException("Method not allowed", 0, null, 405, array( |
117 | 117 | "Allow" => implode(",", $methods) |
@@ -121,9 +121,9 @@ discard block |
||
121 | 121 | |
122 | 122 | $this->setRequest($request); |
123 | 123 | |
124 | - if ($this->bypass_routing === false) { |
|
124 | + if ( $this->bypass_routing === false ) { |
|
125 | 125 | |
126 | - if (!$this->parse()) throw new DispatcherException("Unable to find a valid route for the specified uri", 0, null, 404); |
|
126 | + if ( !$this->parse() ) throw new DispatcherException("Unable to find a valid route for the specified uri", 0, null, 404); |
|
127 | 127 | |
128 | 128 | } |
129 | 129 | |
@@ -135,10 +135,10 @@ discard block |
||
135 | 135 | |
136 | 136 | $class = $this->route->getClassName(); |
137 | 137 | |
138 | - if (class_exists($class)) { |
|
138 | + if ( class_exists($class) ) { |
|
139 | 139 | |
140 | 140 | // All the route parameters are also added to the query parameters |
141 | - foreach ($this->route->getRequestParameters() as $parameter => $value) { |
|
141 | + foreach ( $this->route->getRequestParameters() as $parameter => $value ) { |
|
142 | 142 | $this->getRequest()->getQuery()->set($parameter, $value); |
143 | 143 | } |
144 | 144 | |
@@ -163,13 +163,13 @@ discard block |
||
163 | 163 | |
164 | 164 | $this->setResponse($response); |
165 | 165 | |
166 | - if (is_null($this->route)) { |
|
166 | + if ( is_null($this->route) ) { |
|
167 | 167 | |
168 | 168 | throw new DispatcherException("Route has not been loaded!"); |
169 | 169 | |
170 | 170 | } |
171 | 171 | |
172 | - if ($this->bypass_service) { |
|
172 | + if ( $this->bypass_service ) { |
|
173 | 173 | |
174 | 174 | return; |
175 | 175 | |
@@ -177,7 +177,7 @@ discard block |
||
177 | 177 | |
178 | 178 | $service = $this->getServiceInstance(); |
179 | 179 | |
180 | - if (!is_null($service)) { |
|
180 | + if ( !is_null($service) ) { |
|
181 | 181 | |
182 | 182 | $result = ""; |
183 | 183 | |
@@ -185,7 +185,7 @@ discard block |
||
185 | 185 | |
186 | 186 | $methods = $service->getImplementedMethods(); |
187 | 187 | |
188 | - if (in_array($method, $methods)) { |
|
188 | + if ( in_array($method, $methods) ) { |
|
189 | 189 | |
190 | 190 | $callable = $service->getMethod($method); |
191 | 191 | |
@@ -225,10 +225,10 @@ discard block |
||
225 | 225 | |
226 | 226 | $path = urldecode($this->getRequest()->route()); |
227 | 227 | |
228 | - foreach ($this->table->getRoutes() as $regex => $value) { |
|
228 | + foreach ( $this->table->getRoutes() as $regex => $value ) { |
|
229 | 229 | |
230 | 230 | // The current uri is checked against all the global regular expressions associated with the routes |
231 | - if (preg_match("/".$regex."/", $path, $matches)) { |
|
231 | + if ( preg_match("/".$regex."/", $path, $matches) ) { |
|
232 | 232 | |
233 | 233 | /* If a route is matched, all the bits of the route string are evalued in order to create |
234 | 234 | * new query parameters which will be available for the service class |
@@ -41,7 +41,7 @@ discard block |
||
41 | 41 | * Types of route that this table will accept |
42 | 42 | * @var array |
43 | 43 | */ |
44 | - const ALLOWED_ROUTES = [ "ROUTE", "REDIRECT", "ERROR" ]; |
|
44 | + const ALLOWED_ROUTES = ["ROUTE", "REDIRECT", "ERROR"]; |
|
45 | 45 | |
46 | 46 | /** |
47 | 47 | * Current repository of routes |
@@ -141,7 +141,7 @@ discard block |
||
141 | 141 | |
142 | 142 | $regex = $this->regex($route); |
143 | 143 | |
144 | - if (isset($this->routes[$regex])) { |
|
144 | + if ( isset($this->routes[$regex]) ) { |
|
145 | 145 | return $this->routes[$regex]; |
146 | 146 | } |
147 | 147 | |
@@ -163,7 +163,7 @@ discard block |
||
163 | 163 | |
164 | 164 | $routes = $this->routes; |
165 | 165 | |
166 | - if (isset($routes[$regex])) { |
|
166 | + if ( isset($routes[$regex]) ) { |
|
167 | 167 | |
168 | 168 | unset($routes[$regex]); |
169 | 169 | |
@@ -185,9 +185,9 @@ discard block |
||
185 | 185 | |
186 | 186 | public function load(array $routes) { |
187 | 187 | |
188 | - if (!empty($routes)) { |
|
188 | + if ( !empty($routes) ) { |
|
189 | 189 | |
190 | - foreach ($routes as $name => $route) { |
|
190 | + foreach ( $routes as $name => $route ) { |
|
191 | 191 | |
192 | 192 | $this->add( |
193 | 193 | $route['route'], |
@@ -249,11 +249,11 @@ discard block |
||
249 | 249 | |
250 | 250 | private function readCache() { |
251 | 251 | |
252 | - if ($this->configuration->get('routing-table-cache') !== true) return; |
|
252 | + if ( $this->configuration->get('routing-table-cache') !== true ) return; |
|
253 | 253 | |
254 | 254 | $data = $this->cache->read(); |
255 | 255 | |
256 | - if (is_null($data)) { |
|
256 | + if ( is_null($data) ) { |
|
257 | 257 | |
258 | 258 | $this->routes = []; |
259 | 259 | |
@@ -269,11 +269,11 @@ discard block |
||
269 | 269 | |
270 | 270 | private function dumpCache() { |
271 | 271 | |
272 | - if ($this->configuration->get('routing-table-cache') !== true) return; |
|
272 | + if ( $this->configuration->get('routing-table-cache') !== true ) return; |
|
273 | 273 | |
274 | 274 | $ttl = $this->configuration->get('routing-table-ttl'); |
275 | 275 | |
276 | - if ($this->cache->dump($this->routes, $ttl)) { |
|
276 | + if ( $this->cache->dump($this->routes, $ttl) ) { |
|
277 | 277 | $this->logger->debug("Routing table saved to cache"); |
278 | 278 | } else { |
279 | 279 | $this->logger->warning("Cannot save routing table to cache"); |
@@ -41,14 +41,14 @@ discard block |
||
41 | 41 | // the global regular expression against which all the request URI will be compared |
42 | 42 | public function read($folders = array(), Route $value = null, $regex = '') { |
43 | 43 | |
44 | - if (is_null($value)) { |
|
44 | + if ( is_null($value) ) { |
|
45 | 45 | |
46 | 46 | $value = new Route(); |
47 | 47 | |
48 | 48 | } |
49 | 49 | |
50 | 50 | // if the first 'folder' is empty is removed |
51 | - while (!empty($folders) && empty($folders[0])) { |
|
51 | + while ( !empty($folders) && empty($folders[0]) ) { |
|
52 | 52 | |
53 | 53 | array_shift($folders); |
54 | 54 | |
@@ -56,7 +56,7 @@ discard block |
||
56 | 56 | |
57 | 57 | // if the 'folder' array is empty, the route has been fully analyzed |
58 | 58 | // this is the exit condition from the recursive loop. |
59 | - if (empty($folders)) { |
|
59 | + if ( empty($folders) ) { |
|
60 | 60 | |
61 | 61 | return '^'.$regex.'[\/]?$'; |
62 | 62 | |
@@ -68,7 +68,7 @@ discard block |
||
68 | 68 | // All the parameters of the route must be json strings |
69 | 69 | $decoded = json_decode($folder, true); |
70 | 70 | |
71 | - if (!is_null($decoded) && is_array($decoded)) { |
|
71 | + if ( !is_null($decoded) && is_array($decoded) ) { |
|
72 | 72 | |
73 | 73 | $param_regex = ''; |
74 | 74 | |
@@ -84,7 +84,7 @@ discard block |
||
84 | 84 | * |
85 | 85 | * This is the reason of the following 'foreach' |
86 | 86 | */ |
87 | - foreach ($decoded as $key => $string) { |
|
87 | + foreach ( $decoded as $key => $string ) { |
|
88 | 88 | |
89 | 89 | $this->logger->debug("Route parser - parameter key: $key"); |
90 | 90 | |
@@ -96,7 +96,7 @@ discard block |
||
96 | 96 | */ |
97 | 97 | $param_regex .= $this->param($key, $string, $value); |
98 | 98 | |
99 | - if ($value->isQueryRequired($key)) { |
|
99 | + if ( $value->isQueryRequired($key) ) { |
|
100 | 100 | $param_required = true; |
101 | 101 | } |
102 | 102 | |
@@ -132,7 +132,7 @@ discard block |
||
132 | 132 | $field_required = false; |
133 | 133 | |
134 | 134 | // If the field name ends with a '*', the parameter is considered as required |
135 | - if (preg_match('/^(.+)\*$/', $key, $bits)) { |
|
135 | + if ( preg_match('/^(.+)\*$/', $key, $bits) ) { |
|
136 | 136 | |
137 | 137 | $key = $bits[1]; |
138 | 138 | $field_required = true; |
@@ -43,7 +43,7 @@ |
||
43 | 43 | |
44 | 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 |
@@ -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,7 +60,7 @@ discard block |
||
60 | 60 | |
61 | 61 | } |
62 | 62 | |
63 | - public function description($code=null) { |
|
63 | + public function description($code = null) { |
|
64 | 64 | |
65 | 65 | if ( is_null($code) ) return $this->codes->getMessage($this->status_code); |
66 | 66 |
@@ -48,7 +48,7 @@ |
||
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, |
@@ -87,7 +87,7 @@ discard block |
||
87 | 87 | |
88 | 88 | $file = $this->getTemporaryName(); |
89 | 89 | |
90 | - if (file_exists($file)) { |
|
90 | + if ( file_exists($file) ) { |
|
91 | 91 | return file_get_contents($file); |
92 | 92 | } |
93 | 93 | |
@@ -97,7 +97,7 @@ discard block |
||
97 | 97 | |
98 | 98 | public function load($slugOrControl) { |
99 | 99 | |
100 | - if (isset($_FILES) && isset($_FILES[$slugOrControl])) { |
|
100 | + if ( isset($_FILES) && isset($_FILES[$slugOrControl]) ) { |
|
101 | 101 | |
102 | 102 | $this->loadFromUploadedFile($slugOrControl); |
103 | 103 | |
@@ -111,11 +111,11 @@ discard block |
||
111 | 111 | |
112 | 112 | public function save($path, $as_slug = false) { |
113 | 113 | |
114 | - if (!empty($path) && file_exists($path)) { |
|
114 | + if ( !empty($path) && file_exists($path) ) { |
|
115 | 115 | |
116 | 116 | $local_name = "$path/".($as_slug ? $this->getSlug() : $this->getFileName()); |
117 | 117 | |
118 | - if (file_exists($local_name)) { |
|
118 | + if ( file_exists($local_name) ) { |
|
119 | 119 | |
120 | 120 | $files = glob("$local_name*"); |
121 | 121 | |
@@ -125,7 +125,7 @@ discard block |
||
125 | 125 | |
126 | 126 | } |
127 | 127 | |
128 | - if (move_uploaded_file($this->getTemporaryName(), $local_name)) { |
|
128 | + if ( move_uploaded_file($this->getTemporaryName(), $local_name) ) { |
|
129 | 129 | |
130 | 130 | // return file_exists($local_name); |
131 | 131 | return true; |
@@ -167,7 +167,7 @@ discard block |
||
167 | 167 | |
168 | 168 | $files = array(); |
169 | 169 | |
170 | - foreach ($_FILES as $idx => $data) { |
|
170 | + foreach ( $_FILES as $idx => $data ) { |
|
171 | 171 | |
172 | 172 | $files[] = new File($idx, $repository); |
173 | 173 |
@@ -28,7 +28,7 @@ |
||
28 | 28 | |
29 | 29 | public function __construct() { |
30 | 30 | |
31 | - foreach ($_FILES as $idx => $data) { |
|
31 | + foreach ( $_FILES as $idx => $data ) { |
|
32 | 32 | |
33 | 33 | $this->files[] = new File($idx); |
34 | 34 |