@@ -29,7 +29,7 @@ discard block |
||
| 29 | 29 | |
| 30 | 30 | public function subscribe($event, $class, $method = null, $priority = 0) { |
| 31 | 31 | |
| 32 | - $callable = ( is_null($method) ) ? $class : array($class, $method); |
|
| 32 | + $callable = (is_null($method)) ? $class : array($class, $method); |
|
| 33 | 33 | |
| 34 | 34 | return $this->addListener($event, $callable, $priority); |
| 35 | 35 | |
@@ -37,7 +37,7 @@ discard block |
||
| 37 | 37 | |
| 38 | 38 | public function subscribeOnce($event, $class, $method = null, $priority = 0) { |
| 39 | 39 | |
| 40 | - $callable = ( is_null($method) ) ? $class : array($class, $method); |
|
| 40 | + $callable = (is_null($method)) ? $class : array($class, $method); |
|
| 41 | 41 | |
| 42 | 42 | return $this->addOneTimeListener($event, $callable, $priority); |
| 43 | 43 | |
@@ -45,11 +45,11 @@ discard block |
||
| 45 | 45 | |
| 46 | 46 | public function loadPlugins($plugins) { |
| 47 | 47 | |
| 48 | - if ( !empty($plugins) ) { |
|
| 48 | + if (!empty($plugins)) { |
|
| 49 | 49 | |
| 50 | - foreach( $plugins as $name => $event ) { |
|
| 50 | + foreach ($plugins as $name => $event) { |
|
| 51 | 51 | |
| 52 | - $callable = ( is_null($event['method']) ) ? $event["class"] : array($event["class"], $event["method"]); |
|
| 52 | + $callable = (is_null($event['method'])) ? $event["class"] : array($event["class"], $event["method"]); |
|
| 53 | 53 | |
| 54 | 54 | $this->addListener($event["event"], $callable, $event["priority"]); |
| 55 | 55 | |
@@ -209,6 +209,9 @@ |
||
| 209 | 209 | |
| 210 | 210 | } |
| 211 | 211 | |
| 212 | + /** |
|
| 213 | + * @param string[] $bits |
|
| 214 | + */ |
|
| 212 | 215 | private function evalUri($parameters, $bits) { |
| 213 | 216 | |
| 214 | 217 | $count = 0; |
@@ -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); |
@@ -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 | |
@@ -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 | |