@@ -94,6 +94,9 @@ discard block |
||
| 94 | 94 | |
| 95 | 95 | } |
| 96 | 96 | |
| 97 | + /** |
|
| 98 | + * @return Configuration |
|
| 99 | + */ |
|
| 97 | 100 | public function configuration() { |
| 98 | 101 | |
| 99 | 102 | if (empty($this->configuration)) { |
@@ -130,6 +133,9 @@ discard block |
||
| 130 | 133 | |
| 131 | 134 | } |
| 132 | 135 | |
| 136 | + /** |
|
| 137 | + * @return Request |
|
| 138 | + */ |
|
| 133 | 139 | public function request() { |
| 134 | 140 | |
| 135 | 141 | if (empty($this->request)) { |
@@ -142,6 +148,9 @@ discard block |
||
| 142 | 148 | |
| 143 | 149 | } |
| 144 | 150 | |
| 151 | + /** |
|
| 152 | + * @return Router |
|
| 153 | + */ |
|
| 145 | 154 | public function router() { |
| 146 | 155 | |
| 147 | 156 | if (empty($this->router)) { |
@@ -154,6 +163,9 @@ discard block |
||
| 154 | 163 | |
| 155 | 164 | } |
| 156 | 165 | |
| 166 | + /** |
|
| 167 | + * @return Response |
|
| 168 | + */ |
|
| 157 | 169 | public function response() { |
| 158 | 170 | |
| 159 | 171 | if (empty($this->response)) { |
@@ -166,6 +178,9 @@ discard block |
||
| 166 | 178 | |
| 167 | 179 | } |
| 168 | 180 | |
| 181 | + /** |
|
| 182 | + * @return null|Extra |
|
| 183 | + */ |
|
| 169 | 184 | public function extra() { |
| 170 | 185 | |
| 171 | 186 | if (empty($this->extra)) { |
@@ -272,6 +287,9 @@ discard block |
||
| 272 | 287 | |
| 273 | 288 | } |
| 274 | 289 | |
| 290 | + /** |
|
| 291 | + * @param string $name |
|
| 292 | + */ |
|
| 275 | 293 | private function emitServiceSpecializedEvents($name) { |
| 276 | 294 | |
| 277 | 295 | $this->logger()->debug("Emitting $name service-event."); |
@@ -118,8 +118,9 @@ |
||
| 118 | 118 | $extra |
| 119 | 119 | ); |
| 120 | 120 | |
| 121 | + } else { |
|
| 122 | + return null; |
|
| 121 | 123 | } |
| 122 | - else return null; |
|
| 123 | 124 | |
| 124 | 125 | } |
| 125 | 126 | |
@@ -89,10 +89,10 @@ discard block |
||
| 89 | 89 | |
| 90 | 90 | $methods = $this->configuration->get('allowed-http-methods'); |
| 91 | 91 | |
| 92 | - if ( ( $methods != null || !empty($methods) ) && in_array($method, $methods) === false ) { |
|
| 92 | + if (($methods != null || !empty($methods)) && in_array($method, $methods) === false) { |
|
| 93 | 93 | |
| 94 | 94 | throw new DispatcherException("Method not allowed", 0, null, 405, array( |
| 95 | - "Allow" => implode(",",$methods) |
|
| 95 | + "Allow" => implode(",", $methods) |
|
| 96 | 96 | )); |
| 97 | 97 | |
| 98 | 98 | } |
@@ -135,7 +135,7 @@ discard block |
||
| 135 | 135 | |
| 136 | 136 | $methods = $service->getImplementedMethods(); |
| 137 | 137 | |
| 138 | - if ( in_array($method, $methods) ) { |
|
| 138 | + if (in_array($method, $methods)) { |
|
| 139 | 139 | |
| 140 | 140 | $callable = $service->getMethod($method); |
| 141 | 141 | |
@@ -178,7 +178,7 @@ discard block |
||
| 178 | 178 | foreach ($this->table->routes() as $regex => $value) { |
| 179 | 179 | |
| 180 | 180 | // The current uri is checked against all the global regular expressions associated with the routes |
| 181 | - if (preg_match("/" . $regex . "/", $path, $matches)) { |
|
| 181 | + if (preg_match("/".$regex."/", $path, $matches)) { |
|
| 182 | 182 | |
| 183 | 183 | /* If a route is matched, all the bits of the route string are evalued in order to create |
| 184 | 184 | * new query parameters which will be available for the service class |
@@ -198,7 +198,7 @@ discard block |
||
| 198 | 198 | |
| 199 | 199 | $this->route->setClassName($value['class']); |
| 200 | 200 | $this->route->setType($value['type']); |
| 201 | - $this->route->setService(empty($service)?"default":$service); |
|
| 201 | + $this->route->setService(empty($service) ? "default" : $service); |
|
| 202 | 202 | |
| 203 | 203 | return true; |
| 204 | 204 | |
@@ -212,7 +212,7 @@ discard block |
||
| 212 | 212 | |
| 213 | 213 | private function evalUri($parameters, $bits) { |
| 214 | 214 | |
| 215 | - $count = 0; |
|
| 215 | + $count = 0; |
|
| 216 | 216 | |
| 217 | 217 | // Because of the nature of the global regular expression, all the bits of the matched route are associated with a parameter key |
| 218 | 218 | foreach ($parameters as $key => $value) { |
@@ -221,7 +221,7 @@ discard block |
||
| 221 | 221 | /* if it's available a bit associated with the parameter name, it is compared against |
| 222 | 222 | * it's regular expression in order to extrect backreferences |
| 223 | 223 | */ |
| 224 | - if (preg_match('/^' . $value['regex'] . '$/', $bits[$key], $matches)) { |
|
| 224 | + if (preg_match('/^'.$value['regex'].'$/', $bits[$key], $matches)) { |
|
| 225 | 225 | |
| 226 | 226 | if (count($matches) == 1) $matches = $matches[0]; // This is the case where no backreferences are present or available. |
| 227 | 227 | |
@@ -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); |
@@ -73,9 +73,9 @@ discard block |
||
| 73 | 73 | */ |
| 74 | 74 | foreach ($decoded as $key => $string) { |
| 75 | 75 | |
| 76 | - $this->logger->debug("PARAMETER KEY: " . $key); |
|
| 76 | + $this->logger->debug("PARAMETER KEY: ".$key); |
|
| 77 | 77 | |
| 78 | - $this->logger->debug("PARAMETER STRING: " . $string); |
|
| 78 | + $this->logger->debug("PARAMETER STRING: ".$string); |
|
| 79 | 79 | |
| 80 | 80 | /* The key and the regex of every paramater is passed to the 'param' |
| 81 | 81 | * method which will build an appropriate regular expression and will understand |
@@ -83,14 +83,14 @@ discard block |
||
| 83 | 83 | */ |
| 84 | 84 | $param_regex .= $this->param($key, $string, $param_required, $value); |
| 85 | 85 | |
| 86 | - $this->logger->debug("PARAMETER REGEX: " . $param_regex); |
|
| 86 | + $this->logger->debug("PARAMETER REGEX: ".$param_regex); |
|
| 87 | 87 | |
| 88 | 88 | } |
| 89 | 89 | // Once the parameter is analyzed, the result is passed to the next iteration |
| 90 | 90 | return $this->read( |
| 91 | 91 | $folders, |
| 92 | 92 | $value, |
| 93 | - $regex.'(?:\/'.$param_regex.')'. (($param_required)?'{1}':'?') |
|
| 93 | + $regex.'(?:\/'.$param_regex.')'.(($param_required) ? '{1}' : '?') |
|
| 94 | 94 | ); |
| 95 | 95 | |
| 96 | 96 | } else { |
@@ -155,7 +155,7 @@ discard block |
||
| 155 | 155 | * If the field is required, the regular expression is completed with a '{1}' (which make it compulsory), |
| 156 | 156 | * otherwise a '?' is added. |
| 157 | 157 | */ |
| 158 | - return '(?P<' . $key . '>' . $string . ')' . (($field_required)?'{1}':'?'); |
|
| 158 | + return '(?P<'.$key.'>'.$string.')'.(($field_required) ? '{1}' : '?'); |
|
| 159 | 159 | |
| 160 | 160 | } |
| 161 | 161 | |
@@ -95,7 +95,9 @@ |
||
| 95 | 95 | |
| 96 | 96 | } else { |
| 97 | 97 | // if the element is not a json string, I assume it's the service name |
| 98 | - if (!isset($value['service'])) $value['service'] = array(); |
|
| 98 | + if (!isset($value['service'])) { |
|
| 99 | + $value['service'] = array(); |
|
| 100 | + } |
|
| 99 | 101 | array_push($value['service'], $folder); |
| 100 | 102 | |
| 101 | 103 | return $this->read( |
@@ -145,9 +145,9 @@ discard block |
||
| 145 | 145 | |
| 146 | 146 | public function load($routes) { |
| 147 | 147 | |
| 148 | - if ( !empty($routes) ) { |
|
| 148 | + if (!empty($routes)) { |
|
| 149 | 149 | |
| 150 | - foreach( $routes as $name => $route ) { |
|
| 150 | + foreach ($routes as $name => $route) { |
|
| 151 | 151 | |
| 152 | 152 | $this->add($route['route'], $route['type'], $route['class'], $route['parameters']); |
| 153 | 153 | |
@@ -191,22 +191,22 @@ discard block |
||
| 191 | 191 | private function register($folders, $type, $class, $parameters) { |
| 192 | 192 | |
| 193 | 193 | // The values associated with a route are as follows: |
| 194 | - $value = array( |
|
| 195 | - "type" => $type, // Type of route |
|
| 196 | - "class" => $class, // Class to be invoked |
|
| 197 | - "service" => array(), // Service name (it can be a list of namespaces plus a final service name) |
|
| 194 | + $value = array( |
|
| 195 | + "type" => $type, // Type of route |
|
| 196 | + "class" => $class, // Class to be invoked |
|
| 197 | + "service" => array(), // Service name (it can be a list of namespaces plus a final service name) |
|
| 198 | 198 | "parameters" => $parameters, // Parameters passed via the composer.json configuration (cache, ttl, etc...) |
| 199 | 199 | "query" => array() // List of parameters with their regular expression that must be added among the query parameters |
| 200 | 200 | ); |
| 201 | 201 | |
| 202 | - $this->logger->debug("ROUTE: " . implode("/", $folders)); |
|
| 202 | + $this->logger->debug("ROUTE: ".implode("/", $folders)); |
|
| 203 | 203 | |
| 204 | 204 | //$this->logger->debug("PARAMETERS: " . var_export($value, true)); |
| 205 | 205 | |
| 206 | 206 | // This method generate a global regular expression which will be able to match all the URI supported by the route |
| 207 | 207 | $regex = $this->parser->read($folders, $value); |
| 208 | 208 | |
| 209 | - $this->logger->debug("ROUTE: " . $regex); |
|
| 209 | + $this->logger->debug("ROUTE: ".$regex); |
|
| 210 | 210 | |
| 211 | 211 | //$this->logger->debug("PARAMETERS: " . var_export($value, true)); |
| 212 | 212 | |
@@ -104,10 +104,11 @@ discard block |
||
| 104 | 104 | |
| 105 | 105 | $regex = $this->parser->read($folders); |
| 106 | 106 | |
| 107 | - if (isset($this->routes[$regex])) |
|
| 108 | - return $this->routes[$regex]; |
|
| 109 | - else |
|
| 110 | - return null; |
|
| 107 | + if (isset($this->routes[$regex])) { |
|
| 108 | + return $this->routes[$regex]; |
|
| 109 | + } else { |
|
| 110 | + return null; |
|
| 111 | + } |
|
| 111 | 112 | |
| 112 | 113 | } |
| 113 | 114 | |
@@ -117,7 +118,9 @@ discard block |
||
| 117 | 118 | |
| 118 | 119 | $regex = $this->parser->read($folders); |
| 119 | 120 | |
| 120 | - if (isset($this->routes[$regex])) unset($this->routes[$regex]); |
|
| 121 | + if (isset($this->routes[$regex])) { |
|
| 122 | + unset($this->routes[$regex]); |
|
| 123 | + } |
|
| 121 | 124 | |
| 122 | 125 | } |
| 123 | 126 | |
@@ -165,7 +168,9 @@ discard block |
||
| 165 | 168 | |
| 166 | 169 | $routes = $this->cache->get("dispatcher_routes"); |
| 167 | 170 | |
| 168 | - if (is_null($routes)) return null; |
|
| 171 | + if (is_null($routes)) { |
|
| 172 | + return null; |
|
| 173 | + } |
|
| 169 | 174 | |
| 170 | 175 | $this->routes($routes); |
| 171 | 176 | |