@@ -142,9 +142,9 @@ discard block |
||
| 142 | 142 | */ |
| 143 | 143 | foreach ($decoded as $key => $string) { |
| 144 | 144 | |
| 145 | - $this->logger->debug("PARAMETER KEY: " . $key); |
|
| 145 | + $this->logger->debug("PARAMETER KEY: ".$key); |
|
| 146 | 146 | |
| 147 | - $this->logger->debug("PARAMETER STRING: " . $string); |
|
| 147 | + $this->logger->debug("PARAMETER STRING: ".$string); |
|
| 148 | 148 | |
| 149 | 149 | /* The key and the regex of every paramater is passed to the 'readparam' |
| 150 | 150 | * method which will build an appropriate regular expression and will understand |
@@ -152,14 +152,14 @@ discard block |
||
| 152 | 152 | */ |
| 153 | 153 | $param_regex .= $this->readparam($key, $string, $param_required, $value); |
| 154 | 154 | |
| 155 | - $this->logger->debug("PARAMETER REGEX: " . $param_regex); |
|
| 155 | + $this->logger->debug("PARAMETER REGEX: ".$param_regex); |
|
| 156 | 156 | |
| 157 | 157 | } |
| 158 | 158 | // Once the parameter is analyzed, the result is passed to the next iteration |
| 159 | 159 | return $this->readpath( |
| 160 | 160 | $folders, |
| 161 | 161 | $value, |
| 162 | - $regex.'(?:\/'.$param_regex.')'. (($param_required)?'{1}':'?') |
|
| 162 | + $regex.'(?:\/'.$param_regex.')'.(($param_required) ? '{1}' : '?') |
|
| 163 | 163 | ); |
| 164 | 164 | |
| 165 | 165 | } else { |
@@ -224,7 +224,7 @@ discard block |
||
| 224 | 224 | * If the field is required, the regular expression is completed with a '{1}' (which make it compulsory), |
| 225 | 225 | * otherwise a '?' is added. |
| 226 | 226 | */ |
| 227 | - return '(?P<' . $key . '>' . $string . ')' . (($field_required)?'{1}':'?'); |
|
| 227 | + return '(?P<'.$key.'>'.$string.')'.(($field_required) ? '{1}' : '?'); |
|
| 228 | 228 | |
| 229 | 229 | } |
| 230 | 230 | |
@@ -232,24 +232,24 @@ discard block |
||
| 232 | 232 | private function add($folders, $type, $class, $parameters) { |
| 233 | 233 | |
| 234 | 234 | // The values associated with a route are as follows: |
| 235 | - $value = array( |
|
| 236 | - "type" => $type, // Type of route |
|
| 237 | - "class" => $class, // Class to be invoked |
|
| 238 | - "service" => array(), // Service name (it can be a list of namespaces plus a final service name) |
|
| 235 | + $value = array( |
|
| 236 | + "type" => $type, // Type of route |
|
| 237 | + "class" => $class, // Class to be invoked |
|
| 238 | + "service" => array(), // Service name (it can be a list of namespaces plus a final service name) |
|
| 239 | 239 | "parameters" => $parameters, // Parameters passed via the composer.json configuration (cache, ttl, etc...) |
| 240 | 240 | "query" => array() // List of parameters with their regular expression that must be added among the query parameters |
| 241 | 241 | ); |
| 242 | 242 | |
| 243 | - $this->logger->debug("ROUTE: " . implode("/", $folders)); |
|
| 243 | + $this->logger->debug("ROUTE: ".implode("/", $folders)); |
|
| 244 | 244 | |
| 245 | - $this->logger->debug("PARAMETERS: " . var_export($value, true)); |
|
| 245 | + $this->logger->debug("PARAMETERS: ".var_export($value, true)); |
|
| 246 | 246 | |
| 247 | 247 | // This method generate a global regular expression which will be able to match all the URI supported by the route |
| 248 | 248 | $regex = $this->readpath($folders, $value); |
| 249 | 249 | |
| 250 | - $this->logger->debug("ROUTE: " . $regex); |
|
| 250 | + $this->logger->debug("ROUTE: ".$regex); |
|
| 251 | 251 | |
| 252 | - $this->logger->debug("PARAMETERS: " . var_export($value, true)); |
|
| 252 | + $this->logger->debug("PARAMETERS: ".var_export($value, true)); |
|
| 253 | 253 | |
| 254 | 254 | $this->routes[$regex] = $value; |
| 255 | 255 | |
@@ -70,10 +70,11 @@ discard block |
||
| 70 | 70 | |
| 71 | 71 | $regex = $this->readpath($folders); |
| 72 | 72 | |
| 73 | - if (isset($this->routes[$regex])) |
|
| 74 | - return $this->routes[$regex]; |
|
| 75 | - else |
|
| 76 | - return null; |
|
| 73 | + if (isset($this->routes[$regex])) { |
|
| 74 | + return $this->routes[$regex]; |
|
| 75 | + } else { |
|
| 76 | + return null; |
|
| 77 | + } |
|
| 77 | 78 | |
| 78 | 79 | } |
| 79 | 80 | |
@@ -83,7 +84,9 @@ discard block |
||
| 83 | 84 | |
| 84 | 85 | $regex = $this->readpath($folders); |
| 85 | 86 | |
| 86 | - if (isset($this->routes[$regex])) unset($this->routes[$regex]); |
|
| 87 | + if (isset($this->routes[$regex])) { |
|
| 88 | + unset($this->routes[$regex]); |
|
| 89 | + } |
|
| 87 | 90 | |
| 88 | 91 | } |
| 89 | 92 | |
@@ -164,7 +167,9 @@ discard block |
||
| 164 | 167 | |
| 165 | 168 | } else { |
| 166 | 169 | // if the element is not a json string, I assume it's the service name |
| 167 | - if (!isset($value['service'])) $value['service'] = array(); |
|
| 170 | + if (!isset($value['service'])) { |
|
| 171 | + $value['service'] = array(); |
|
| 172 | + } |
|
| 168 | 173 | array_push($value['service'], $folder); |
| 169 | 174 | |
| 170 | 175 | return $this->readpath( |
@@ -95,6 +95,9 @@ discard block |
||
| 95 | 95 | |
| 96 | 96 | } |
| 97 | 97 | |
| 98 | + /** |
|
| 99 | + * @return Configuration |
|
| 100 | + */ |
|
| 98 | 101 | public function configuration() { |
| 99 | 102 | |
| 100 | 103 | if (empty($this->configuration)) { |
@@ -131,6 +134,9 @@ discard block |
||
| 131 | 134 | |
| 132 | 135 | } |
| 133 | 136 | |
| 137 | + /** |
|
| 138 | + * @return Request |
|
| 139 | + */ |
|
| 134 | 140 | public function request() { |
| 135 | 141 | |
| 136 | 142 | if (empty($this->request)) { |
@@ -143,6 +149,9 @@ discard block |
||
| 143 | 149 | |
| 144 | 150 | } |
| 145 | 151 | |
| 152 | + /** |
|
| 153 | + * @return RouteCollector |
|
| 154 | + */ |
|
| 146 | 155 | public function router() { |
| 147 | 156 | |
| 148 | 157 | if (empty($this->router)) { |
@@ -155,6 +164,9 @@ discard block |
||
| 155 | 164 | |
| 156 | 165 | } |
| 157 | 166 | |
| 167 | + /** |
|
| 168 | + * @return Response |
|
| 169 | + */ |
|
| 158 | 170 | public function response() { |
| 159 | 171 | |
| 160 | 172 | if (empty($this->response)) { |
@@ -167,6 +179,9 @@ discard block |
||
| 167 | 179 | |
| 168 | 180 | } |
| 169 | 181 | |
| 182 | + /** |
|
| 183 | + * @return null|Extra |
|
| 184 | + */ |
|
| 170 | 185 | public function extra() { |
| 171 | 186 | |
| 172 | 187 | if (empty($this->extra)) { |
@@ -273,6 +288,9 @@ discard block |
||
| 273 | 288 | |
| 274 | 289 | } |
| 275 | 290 | |
| 291 | + /** |
|
| 292 | + * @param string $name |
|
| 293 | + */ |
|
| 276 | 294 | private function emitServiceSpecializedEvents($name) { |
| 277 | 295 | |
| 278 | 296 | $this->logger()->debug("Emitting $name service-event."); |
@@ -99,7 +99,7 @@ discard block |
||
| 99 | 99 | |
| 100 | 100 | if (empty($this->configuration)) { |
| 101 | 101 | |
| 102 | - $this->configuration = new Configuration( DefaultConfiguration::get() ); |
|
| 102 | + $this->configuration = new Configuration(DefaultConfiguration::get()); |
|
| 103 | 103 | |
| 104 | 104 | } |
| 105 | 105 | |
@@ -199,9 +199,9 @@ discard block |
||
| 199 | 199 | |
| 200 | 200 | $this->logger()->debug("Emitting global dispatcher event."); |
| 201 | 201 | |
| 202 | - $this->events()->emit( new DispatcherEvent($this) ); |
|
| 202 | + $this->events()->emit(new DispatcherEvent($this)); |
|
| 203 | 203 | |
| 204 | - if ( $this->configuration()->get('enabled') === false ) { |
|
| 204 | + if ($this->configuration()->get('enabled') === false) { |
|
| 205 | 205 | |
| 206 | 206 | $this->logger()->debug("Dispatcher disabled, shutting down gracefully."); |
| 207 | 207 | |
@@ -217,11 +217,11 @@ discard block |
||
| 217 | 217 | |
| 218 | 218 | } |
| 219 | 219 | |
| 220 | - $this->events()->emit( $this->emitServiceSpecializedEvents('dispatcher.request') ); |
|
| 220 | + $this->events()->emit($this->emitServiceSpecializedEvents('dispatcher.request')); |
|
| 221 | 221 | |
| 222 | - $this->events()->emit( $this->emitServiceSpecializedEvents('dispatcher.request.'.$this->request()->method()->get()) ); |
|
| 222 | + $this->events()->emit($this->emitServiceSpecializedEvents('dispatcher.request.'.$this->request()->method()->get())); |
|
| 223 | 223 | |
| 224 | - $this->events()->emit( $this->emitServiceSpecializedEvents('dispatcher.request.#') ); |
|
| 224 | + $this->events()->emit($this->emitServiceSpecializedEvents('dispatcher.request.#')); |
|
| 225 | 225 | |
| 226 | 226 | $this->logger()->debug("Starting router."); |
| 227 | 227 | |
@@ -245,13 +245,13 @@ discard block |
||
| 245 | 245 | |
| 246 | 246 | $this->logger()->debug("Route acquired, type $route_type directed to $route_service."); |
| 247 | 247 | |
| 248 | - $this->events()->emit( $this->emitServiceSpecializedEvents('dispatcher.route') ); |
|
| 248 | + $this->events()->emit($this->emitServiceSpecializedEvents('dispatcher.route')); |
|
| 249 | 249 | |
| 250 | - $this->events()->emit( $this->emitServiceSpecializedEvents('dispatcher.route.'.$route_type) ); |
|
| 250 | + $this->events()->emit($this->emitServiceSpecializedEvents('dispatcher.route.'.$route_type)); |
|
| 251 | 251 | |
| 252 | - $this->events()->emit( $this->emitServiceSpecializedEvents('dispatcher.route.'.$route_service) ); |
|
| 252 | + $this->events()->emit($this->emitServiceSpecializedEvents('dispatcher.route.'.$route_service)); |
|
| 253 | 253 | |
| 254 | - $this->events()->emit( $this->emitServiceSpecializedEvents('dispatcher.route.#') ); |
|
| 254 | + $this->events()->emit($this->emitServiceSpecializedEvents('dispatcher.route.#')); |
|
| 255 | 255 | |
| 256 | 256 | // translate route to service |
| 257 | 257 | |
@@ -307,11 +307,11 @@ discard block |
||
| 307 | 307 | |
| 308 | 308 | private function shutdown() { |
| 309 | 309 | |
| 310 | - $this->events()->emit( $this->emitServiceSpecializedEvents('dispatcher.response') ); |
|
| 310 | + $this->events()->emit($this->emitServiceSpecializedEvents('dispatcher.response')); |
|
| 311 | 311 | |
| 312 | - $this->events()->emit( $this->emitServiceSpecializedEvents('dispatcher.response.'.$this->response()->status()->get()) ); |
|
| 312 | + $this->events()->emit($this->emitServiceSpecializedEvents('dispatcher.response.'.$this->response()->status()->get())); |
|
| 313 | 313 | |
| 314 | - $this->events()->emit( $this->emitServiceSpecializedEvents('dispatcher.response.#') ); |
|
| 314 | + $this->events()->emit($this->emitServiceSpecializedEvents('dispatcher.response.#')); |
|
| 315 | 315 | |
| 316 | 316 | $this->logger()->debug("Composing return value."); |
| 317 | 317 | |
@@ -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 | |