@@ -29,7 +29,7 @@ discard block |
||
| 29 | 29 | |
| 30 | 30 | private $code = 500; |
| 31 | 31 | |
| 32 | - private $supported_error_codes = array(400,403,404,405,500,501,503); |
|
| 32 | + private $supported_error_codes = array(400, 403, 404, 405, 500, 501, 503); |
|
| 33 | 33 | |
| 34 | 34 | private $content = null; |
| 35 | 35 | |
@@ -137,7 +137,7 @@ discard block |
||
| 137 | 137 | * |
| 138 | 138 | * @return ObjectRequest $this |
| 139 | 139 | */ |
| 140 | - public function setHeader($header, $value=null) { |
|
| 140 | + public function setHeader($header, $value = null) { |
|
| 141 | 141 | |
| 142 | 142 | $this->headers[$header] = $value; |
| 143 | 143 | |
@@ -154,7 +154,7 @@ discard block |
||
| 154 | 154 | */ |
| 155 | 155 | public function unsetHeader($header) { |
| 156 | 156 | |
| 157 | - if ( isset($this->headers[$header]) ) { |
|
| 157 | + if (isset($this->headers[$header])) { |
|
| 158 | 158 | |
| 159 | 159 | unset($this->headers[$header]); |
| 160 | 160 | |
@@ -175,7 +175,7 @@ discard block |
||
| 175 | 175 | */ |
| 176 | 176 | public function getHeader($header) { |
| 177 | 177 | |
| 178 | - if ( isset($this->headers[$header]) ) return $this->headers[$header]; |
|
| 178 | + if (isset($this->headers[$header])) return $this->headers[$header]; |
|
| 179 | 179 | |
| 180 | 180 | return null; |
| 181 | 181 | |
@@ -175,7 +175,9 @@ |
||
| 175 | 175 | */ |
| 176 | 176 | public function getHeader($header) { |
| 177 | 177 | |
| 178 | - if ( isset($this->headers[$header]) ) return $this->headers[$header]; |
|
| 178 | + if ( isset($this->headers[$header]) ) { |
|
| 179 | + return $this->headers[$header]; |
|
| 180 | + } |
|
| 179 | 181 | |
| 180 | 182 | return null; |
| 181 | 183 | |
@@ -38,15 +38,15 @@ |
||
| 38 | 38 | |
| 39 | 39 | $name = defined('DISPATCHER_LOG_NAME') ? DISPATCHER_LOG_NAME : 'dispatcher-default'; |
| 40 | 40 | |
| 41 | - $level = $this->getLevel( defined('DISPATCHER_LOG_LEVEL') ? DISPATCHER_LOG_LEVEL : 'DEBUG' ); |
|
| 41 | + $level = $this->getLevel(defined('DISPATCHER_LOG_LEVEL') ? DISPATCHER_LOG_LEVEL : 'DEBUG'); |
|
| 42 | 42 | |
| 43 | 43 | $target = defined('DISPATCHER_LOG_TARGET') ? DISPATCHER_LOG_TARGET : null; |
| 44 | 44 | |
| 45 | 45 | $this->logger = new Logger($name); |
| 46 | 46 | |
| 47 | - if ( $enabled ) { |
|
| 47 | + if ($enabled) { |
|
| 48 | 48 | |
| 49 | - $handler = is_null($target) ? new ErrorLogHandler() : new StreamHandler( defined('DISPATCHER_LOG_FOLDER') ? DISPATCHER_LOG_FOLDER.$target : $target, $level); |
|
| 49 | + $handler = is_null($target) ? new ErrorLogHandler() : new StreamHandler(defined('DISPATCHER_LOG_FOLDER') ? DISPATCHER_LOG_FOLDER.$target : $target, $level); |
|
| 50 | 50 | |
| 51 | 51 | } |
| 52 | 52 | else { |
@@ -48,8 +48,7 @@ |
||
| 48 | 48 | |
| 49 | 49 | $handler = is_null($target) ? new ErrorLogHandler() : new StreamHandler( defined('DISPATCHER_LOG_FOLDER') ? DISPATCHER_LOG_FOLDER.$target : $target, $level); |
| 50 | 50 | |
| 51 | - } |
|
| 52 | - else { |
|
| 51 | + } else { |
|
| 53 | 52 | |
| 54 | 53 | $handler = new NullHandler($level); |
| 55 | 54 | |
@@ -210,7 +210,9 @@ discard block |
||
| 210 | 210 | |
| 211 | 211 | $xml = $this->ObjectXML->asXML(); |
| 212 | 212 | |
| 213 | - if ( $xml === false ) throw new XMLException("Error formatting object"); |
|
| 213 | + if ( $xml === false ) { |
|
| 214 | + throw new XMLException("Error formatting object"); |
|
| 215 | + } |
|
| 214 | 216 | |
| 215 | 217 | return $xml; |
| 216 | 218 | |
@@ -231,7 +233,9 @@ discard block |
||
| 231 | 233 | |
| 232 | 234 | $parser_structs = xml_parse_into_struct($this->parser, $xml, $this->struct, $index); |
| 233 | 235 | |
| 234 | - if ( $parser_structs === 0 ) throw new XMLException("Failed to parse xml data into structs"); |
|
| 236 | + if ( $parser_structs === 0 ) { |
|
| 237 | + throw new XMLException("Failed to parse xml data into structs"); |
|
| 238 | + } |
|
| 235 | 239 | |
| 236 | 240 | $this->counter = count($this->struct); |
| 237 | 241 | |
@@ -350,11 +354,15 @@ discard block |
||
| 350 | 354 | |
| 351 | 355 | if ( !isset($target[$key]) ) { |
| 352 | 356 | |
| 353 | - if ($child != "") $target[$key] = $child; |
|
| 354 | - |
|
| 355 | - if ($attributes != "") foreach($attributes as $akey => $avalue) $target[$key][$akey] = $avalue; |
|
| 357 | + if ($child != "") { |
|
| 358 | + $target[$key] = $child; |
|
| 359 | + } |
|
| 356 | 360 | |
| 357 | - else if ( $value != "" ) $target[$key] = $value; |
|
| 361 | + if ($attributes != "") { |
|
| 362 | + foreach($attributes as $akey => $avalue) $target[$key][$akey] = $avalue; |
|
| 363 | + } else if ( $value != "" ) { |
|
| 364 | + $target[$key] = $value; |
|
| 365 | + } |
|
| 358 | 366 | |
| 359 | 367 | } else { |
| 360 | 368 | |
@@ -365,18 +373,21 @@ discard block |
||
| 365 | 373 | $target[$key][0] = $oldval; |
| 366 | 374 | $index=1; |
| 367 | 375 | |
| 368 | - } |
|
| 369 | - else { |
|
| 376 | + } else { |
|
| 370 | 377 | |
| 371 | 378 | $index = count($target[$key]); |
| 372 | 379 | |
| 373 | 380 | } |
| 374 | 381 | |
| 375 | - if ( $child != "" ) $target[$key][$index] = $child; |
|
| 376 | - |
|
| 377 | - if ( $attributes != "" ) foreach($attributes as $akey => $avalue) $target[$key][$index][$akey] = $avalue; |
|
| 382 | + if ( $child != "" ) { |
|
| 383 | + $target[$key][$index] = $child; |
|
| 384 | + } |
|
| 378 | 385 | |
| 379 | - elseif ( $value != "" ) $target[$key][$index] = $value; |
|
| 386 | + if ( $attributes != "" ) { |
|
| 387 | + foreach($attributes as $akey => $avalue) $target[$key][$index][$akey] = $avalue; |
|
| 388 | + } elseif ( $value != "" ) { |
|
| 389 | + $target[$key][$index] = $value; |
|
| 390 | + } |
|
| 380 | 391 | } |
| 381 | 392 | |
| 382 | 393 | return $target; |
@@ -393,9 +404,11 @@ discard block |
||
| 393 | 404 | |
| 394 | 405 | foreach ($data as $key => $value) { |
| 395 | 406 | |
| 396 | - if ( is_array($value) ) $this->pushElement($ObjectXML->addChild(is_numeric($key) ? 'KEY_'.$key : $key), $value); |
|
| 397 | - |
|
| 398 | - else $ObjectXML->addChild(is_numeric($key) ? 'KEY_'.$key : $key, mb_convert_encoding($value, $this->encoding)); |
|
| 407 | + if ( is_array($value) ) { |
|
| 408 | + $this->pushElement($ObjectXML->addChild(is_numeric($key) ? 'KEY_'.$key : $key), $value); |
|
| 409 | + } else { |
|
| 410 | + $ObjectXML->addChild(is_numeric($key) ? 'KEY_'.$key : $key, mb_convert_encoding($value, $this->encoding)); |
|
| 411 | + } |
|
| 399 | 412 | |
| 400 | 413 | } |
| 401 | 414 | |
@@ -116,7 +116,7 @@ discard block |
||
| 116 | 116 | * |
| 117 | 117 | * @param bool $bool |
| 118 | 118 | * |
| 119 | - * @return Object $this |
|
| 119 | + * @return XML $this |
|
| 120 | 120 | */ |
| 121 | 121 | final public function setIncludeHeader($bool) { |
| 122 | 122 | |
@@ -131,7 +131,7 @@ discard block |
||
| 131 | 131 | * |
| 132 | 132 | * @param int $int |
| 133 | 133 | * |
| 134 | - * @return Object $this |
|
| 134 | + * @return XML $this |
|
| 135 | 135 | */ |
| 136 | 136 | final public function setCaseFolding($int) { |
| 137 | 137 | |
@@ -146,7 +146,7 @@ discard block |
||
| 146 | 146 | * |
| 147 | 147 | * @param int $int |
| 148 | 148 | * |
| 149 | - * @return Object $this |
|
| 149 | + * @return XML $this |
|
| 150 | 150 | */ |
| 151 | 151 | final public function setSkipWhite($int) { |
| 152 | 152 | |
@@ -161,7 +161,7 @@ discard block |
||
| 161 | 161 | * |
| 162 | 162 | * @param string $encoding |
| 163 | 163 | * |
| 164 | - * @return Object $this |
|
| 164 | + * @return XML $this |
|
| 165 | 165 | */ |
| 166 | 166 | final public function setEncoding($encoding) { |
| 167 | 167 | |
@@ -219,6 +219,7 @@ discard block |
||
| 219 | 219 | /** |
| 220 | 220 | * encode XML string into array |
| 221 | 221 | * |
| 222 | + * @param string $xml |
|
| 222 | 223 | * @return array |
| 223 | 224 | */ |
| 224 | 225 | public function decode($xml, $encoding=null) { |
@@ -306,6 +307,7 @@ discard block |
||
| 306 | 307 | /** |
| 307 | 308 | * Get element childs (if any) |
| 308 | 309 | * |
| 310 | + * @param integer $i |
|
| 309 | 311 | * @return array |
| 310 | 312 | */ |
| 311 | 313 | private function getChilds(&$i) { |
@@ -202,7 +202,7 @@ discard block |
||
| 202 | 202 | */ |
| 203 | 203 | public function encode($data) { |
| 204 | 204 | |
| 205 | - $structure = ($this->includeHeader ? $this->getHeader() : "") . $this->getParent(); |
|
| 205 | + $structure = ($this->includeHeader ? $this->getHeader() : "").$this->getParent(); |
|
| 206 | 206 | |
| 207 | 207 | $this->ObjectXML = new SimpleXMLElement($structure); |
| 208 | 208 | |
@@ -210,7 +210,7 @@ discard block |
||
| 210 | 210 | |
| 211 | 211 | $xml = $this->ObjectXML->asXML(); |
| 212 | 212 | |
| 213 | - if ( $xml === false ) throw new XMLException("Error formatting object"); |
|
| 213 | + if ($xml === false) throw new XMLException("Error formatting object"); |
|
| 214 | 214 | |
| 215 | 215 | return $xml; |
| 216 | 216 | |
@@ -221,17 +221,17 @@ discard block |
||
| 221 | 221 | * |
| 222 | 222 | * @return array |
| 223 | 223 | */ |
| 224 | - public function decode($xml, $encoding=null) { |
|
| 224 | + public function decode($xml, $encoding = null) { |
|
| 225 | 225 | |
| 226 | 226 | $this->parser = is_null($encoding) ? xml_parser_create() : xml_parser_create($encoding); |
| 227 | 227 | |
| 228 | - xml_parser_set_option($this->parser,XML_OPTION_TARGET_ENCODING,$this->encoding); |
|
| 229 | - xml_parser_set_option($this->parser,XML_OPTION_CASE_FOLDING,$this->caseFolding); |
|
| 230 | - xml_parser_set_option($this->parser,XML_OPTION_SKIP_WHITE,$this->skipWhite); |
|
| 228 | + xml_parser_set_option($this->parser, XML_OPTION_TARGET_ENCODING, $this->encoding); |
|
| 229 | + xml_parser_set_option($this->parser, XML_OPTION_CASE_FOLDING, $this->caseFolding); |
|
| 230 | + xml_parser_set_option($this->parser, XML_OPTION_SKIP_WHITE, $this->skipWhite); |
|
| 231 | 231 | |
| 232 | 232 | $parser_structs = xml_parse_into_struct($this->parser, $xml, $this->struct, $index); |
| 233 | 233 | |
| 234 | - if ( $parser_structs === 0 ) throw new XMLException("Failed to parse xml data into structs"); |
|
| 234 | + if ($parser_structs === 0) throw new XMLException("Failed to parse xml data into structs"); |
|
| 235 | 235 | |
| 236 | 236 | $this->counter = count($this->struct); |
| 237 | 237 | |
@@ -251,9 +251,9 @@ discard block |
||
| 251 | 251 | */ |
| 252 | 252 | private function sanitizeKeys($input, $key) { |
| 253 | 253 | |
| 254 | - $key_value = explode("_",$this->struct[$key]["tag"]); |
|
| 254 | + $key_value = explode("_", $this->struct[$key]["tag"]); |
|
| 255 | 255 | |
| 256 | - if ( sizeof($key_value) == 2 AND $key_value[0] == "KEY" AND is_numeric($key_value[1]) ) { |
|
| 256 | + if (sizeof($key_value) == 2 AND $key_value[0] == "KEY" AND is_numeric($key_value[1])) { |
|
| 257 | 257 | |
| 258 | 258 | $this->struct[$key]["tag"] = intval($key_value[1]); |
| 259 | 259 | |
@@ -266,7 +266,7 @@ discard block |
||
| 266 | 266 | */ |
| 267 | 267 | private function free() { |
| 268 | 268 | |
| 269 | - if( isset($this->parser) AND @is_resource($this->parser) ) { |
|
| 269 | + if (isset($this->parser) AND @is_resource($this->parser)) { |
|
| 270 | 270 | |
| 271 | 271 | xml_parser_free($this->parser); |
| 272 | 272 | |
@@ -320,7 +320,7 @@ discard block |
||
| 320 | 320 | |
| 321 | 321 | $value = isset($this->struct[$i]["value"]) ? $this->struct[$i]["value"] : ""; |
| 322 | 322 | |
| 323 | - switch($this->struct[$i]["type"]) { |
|
| 323 | + switch ($this->struct[$i]["type"]) { |
|
| 324 | 324 | |
| 325 | 325 | case "open": |
| 326 | 326 | $child = $this->getChilds($i); |
@@ -348,13 +348,13 @@ discard block |
||
| 348 | 348 | */ |
| 349 | 349 | private function addNode($target, $key, $attributes, $child, $value) { |
| 350 | 350 | |
| 351 | - if ( !isset($target[$key]) ) { |
|
| 351 | + if (!isset($target[$key])) { |
|
| 352 | 352 | |
| 353 | 353 | if ($child != "") $target[$key] = $child; |
| 354 | 354 | |
| 355 | - if ($attributes != "") foreach($attributes as $akey => $avalue) $target[$key][$akey] = $avalue; |
|
| 355 | + if ($attributes != "") foreach ($attributes as $akey => $avalue) $target[$key][$akey] = $avalue; |
|
| 356 | 356 | |
| 357 | - else if ( $value != "" ) $target[$key] = $value; |
|
| 357 | + else if ($value != "") $target[$key] = $value; |
|
| 358 | 358 | |
| 359 | 359 | } else { |
| 360 | 360 | |
@@ -363,7 +363,7 @@ discard block |
||
| 363 | 363 | $oldval = $target[$key]; |
| 364 | 364 | $target[$key] = array(); |
| 365 | 365 | $target[$key][0] = $oldval; |
| 366 | - $index=1; |
|
| 366 | + $index = 1; |
|
| 367 | 367 | |
| 368 | 368 | } |
| 369 | 369 | else { |
@@ -372,11 +372,11 @@ discard block |
||
| 372 | 372 | |
| 373 | 373 | } |
| 374 | 374 | |
| 375 | - if ( $child != "" ) $target[$key][$index] = $child; |
|
| 375 | + if ($child != "") $target[$key][$index] = $child; |
|
| 376 | 376 | |
| 377 | - if ( $attributes != "" ) foreach($attributes as $akey => $avalue) $target[$key][$index][$akey] = $avalue; |
|
| 377 | + if ($attributes != "") foreach ($attributes as $akey => $avalue) $target[$key][$index][$akey] = $avalue; |
|
| 378 | 378 | |
| 379 | - elseif ( $value != "" ) $target[$key][$index] = $value; |
|
| 379 | + elseif ($value != "") $target[$key][$index] = $value; |
|
| 380 | 380 | } |
| 381 | 381 | |
| 382 | 382 | return $target; |
@@ -393,7 +393,7 @@ discard block |
||
| 393 | 393 | |
| 394 | 394 | foreach ($data as $key => $value) { |
| 395 | 395 | |
| 396 | - if ( is_array($value) ) $this->pushElement($ObjectXML->addChild(is_numeric($key) ? 'KEY_'.$key : $key), $value); |
|
| 396 | + if (is_array($value)) $this->pushElement($ObjectXML->addChild(is_numeric($key) ? 'KEY_'.$key : $key), $value); |
|
| 397 | 397 | |
| 398 | 398 | else $ObjectXML->addChild(is_numeric($key) ? 'KEY_'.$key : $key, mb_convert_encoding($value, $this->encoding)); |
| 399 | 399 | |
@@ -38,9 +38,9 @@ discard block |
||
| 38 | 38 | * |
| 39 | 39 | * @return array |
| 40 | 40 | */ |
| 41 | - final public function fromJson($data, $raw=false) { |
|
| 41 | + final public function fromJson($data, $raw = false) { |
|
| 42 | 42 | |
| 43 | - if ( !is_string($data) ) throw new Exception("Invalid data for JSON deserialization"); |
|
| 43 | + if (!is_string($data)) throw new Exception("Invalid data for JSON deserialization"); |
|
| 44 | 44 | |
| 45 | 45 | return json_decode($data, !$raw); |
| 46 | 46 | |
@@ -55,7 +55,7 @@ discard block |
||
| 55 | 55 | */ |
| 56 | 56 | final public function fromXml($data) { |
| 57 | 57 | |
| 58 | - if ( !is_string($data) ) throw new Exception("Invalid data for XML deserialization"); |
|
| 58 | + if (!is_string($data)) throw new Exception("Invalid data for XML deserialization"); |
|
| 59 | 59 | |
| 60 | 60 | $xmlEngine = new XML(); |
| 61 | 61 | |
@@ -72,7 +72,7 @@ discard block |
||
| 72 | 72 | */ |
| 73 | 73 | final public function fromYaml($data) { |
| 74 | 74 | |
| 75 | - if ( !is_string($data) ) throw new Exception("Invalid data for YAML deserialization"); |
|
| 75 | + if (!is_string($data)) throw new Exception("Invalid data for YAML deserialization"); |
|
| 76 | 76 | |
| 77 | 77 | return \Spyc::YAMLLoadString($data); |
| 78 | 78 | |
@@ -87,7 +87,7 @@ discard block |
||
| 87 | 87 | */ |
| 88 | 88 | final public function fromExport($data) { |
| 89 | 89 | |
| 90 | - if ( !is_string($data) ) throw new Exception("Invalid data for EXPORT deserialization"); |
|
| 90 | + if (!is_string($data)) throw new Exception("Invalid data for EXPORT deserialization"); |
|
| 91 | 91 | |
| 92 | 92 | return unserialize($data); |
| 93 | 93 | |
@@ -40,7 +40,9 @@ discard block |
||
| 40 | 40 | */ |
| 41 | 41 | final public function fromJson($data, $raw=false) { |
| 42 | 42 | |
| 43 | - if ( !is_string($data) ) throw new Exception("Invalid data for JSON deserialization"); |
|
| 43 | + if ( !is_string($data) ) { |
|
| 44 | + throw new Exception("Invalid data for JSON deserialization"); |
|
| 45 | + } |
|
| 44 | 46 | |
| 45 | 47 | return json_decode($data, !$raw); |
| 46 | 48 | |
@@ -55,7 +57,9 @@ discard block |
||
| 55 | 57 | */ |
| 56 | 58 | final public function fromXml($data) { |
| 57 | 59 | |
| 58 | - if ( !is_string($data) ) throw new Exception("Invalid data for XML deserialization"); |
|
| 60 | + if ( !is_string($data) ) { |
|
| 61 | + throw new Exception("Invalid data for XML deserialization"); |
|
| 62 | + } |
|
| 59 | 63 | |
| 60 | 64 | $xmlEngine = new XML(); |
| 61 | 65 | |
@@ -72,7 +76,9 @@ discard block |
||
| 72 | 76 | */ |
| 73 | 77 | final public function fromYaml($data) { |
| 74 | 78 | |
| 75 | - if ( !is_string($data) ) throw new Exception("Invalid data for YAML deserialization"); |
|
| 79 | + if ( !is_string($data) ) { |
|
| 80 | + throw new Exception("Invalid data for YAML deserialization"); |
|
| 81 | + } |
|
| 76 | 82 | |
| 77 | 83 | return \Spyc::YAMLLoadString($data); |
| 78 | 84 | |
@@ -87,7 +93,9 @@ discard block |
||
| 87 | 93 | */ |
| 88 | 94 | final public function fromExport($data) { |
| 89 | 95 | |
| 90 | - if ( !is_string($data) ) throw new Exception("Invalid data for EXPORT deserialization"); |
|
| 96 | + if ( !is_string($data) ) { |
|
| 97 | + throw new Exception("Invalid data for EXPORT deserialization"); |
|
| 98 | + } |
|
| 91 | 99 | |
| 92 | 100 | return unserialize($data); |
| 93 | 101 | |
@@ -193,7 +193,9 @@ discard block |
||
| 193 | 193 | |
| 194 | 194 | // Before composing the object request, remember to define the current (absolute) dispatcher baseurl |
| 195 | 195 | // (if not specified in dispatcher-config) |
| 196 | - if ( !defined("DISPATCHER_BASEURL") ) define("DISPATCHER_BASEURL",$this->urlGetAbsolute($request_service)); |
|
| 196 | + if ( !defined("DISPATCHER_BASEURL") ) { |
|
| 197 | + define("DISPATCHER_BASEURL",$this->urlGetAbsolute($request_service)); |
|
| 198 | + } |
|
| 197 | 199 | |
| 198 | 200 | // Now let's compose request object |
| 199 | 201 | |
@@ -228,22 +230,24 @@ discard block |
||
| 228 | 230 | |
| 229 | 231 | if ( strtoupper($type) == "ROUTE" ) { |
| 230 | 232 | |
| 231 | - if ( $relative ) $this->routingtable->setRoute($service, $type, DISPATCHER_SERVICES_FOLDER.$target, $parameters); |
|
| 232 | - |
|
| 233 | - else $this->routingtable->setRoute($service, $type, $target, $parameters); |
|
| 234 | - |
|
| 235 | - } |
|
| 236 | - |
|
| 237 | - else if ( strtoupper($type) == "REDIRECT" ) { |
|
| 233 | + if ( $relative ) { |
|
| 234 | + $this->routingtable->setRoute($service, $type, DISPATCHER_SERVICES_FOLDER.$target, $parameters); |
|
| 235 | + } else { |
|
| 236 | + $this->routingtable->setRoute($service, $type, $target, $parameters); |
|
| 237 | + } |
|
| 238 | 238 | |
| 239 | - if ( $relative ) $this->routingtable->setRoute($service, $type, DISPATCHER_BASEURL.$target, $parameters); |
|
| 239 | + } else if ( strtoupper($type) == "REDIRECT" ) { |
|
| 240 | 240 | |
| 241 | - else $this->routingtable->setRoute($service, $type, $target, $parameters); |
|
| 241 | + if ( $relative ) { |
|
| 242 | + $this->routingtable->setRoute($service, $type, DISPATCHER_BASEURL.$target, $parameters); |
|
| 243 | + } else { |
|
| 244 | + $this->routingtable->setRoute($service, $type, $target, $parameters); |
|
| 245 | + } |
|
| 242 | 246 | |
| 247 | + } else { |
|
| 248 | + $this->routingtable->setRoute($service, $type, $target, $parameters); |
|
| 243 | 249 | } |
| 244 | 250 | |
| 245 | - else $this->routingtable->setRoute($service, $type, $target, $parameters); |
|
| 246 | - |
|
| 247 | 251 | } catch (Exception $e) { |
| 248 | 252 | |
| 249 | 253 | //debug error but do not stop dispatcher |
@@ -391,19 +395,25 @@ discard block |
||
| 391 | 395 | |
| 392 | 396 | $fork = $this->events->fire("dispatcher.request", "REQUEST", $this->request); |
| 393 | 397 | |
| 394 | - if ( $fork instanceof \Comodojo\Dispatcher\ObjectRequest\ObjectRequest ) $this->request = $fork; |
|
| 398 | + if ( $fork instanceof \Comodojo\Dispatcher\ObjectRequest\ObjectRequest ) { |
|
| 399 | + $this->request = $fork; |
|
| 400 | + } |
|
| 395 | 401 | |
| 396 | 402 | // Fire level3 event "dispatcher.request.[method]" |
| 397 | 403 | |
| 398 | 404 | $fork = $this->events->fire("dispatcher.request.".$this->request_method, "REQUEST", $this->request); |
| 399 | 405 | |
| 400 | - if ( $fork instanceof \Comodojo\Dispatcher\ObjectRequest\ObjectRequest ) $this->request = $fork; |
|
| 406 | + if ( $fork instanceof \Comodojo\Dispatcher\ObjectRequest\ObjectRequest ) { |
|
| 407 | + $this->request = $fork; |
|
| 408 | + } |
|
| 401 | 409 | |
| 402 | 410 | // Fire level3 event "dispatcher.request.[service]" |
| 403 | 411 | |
| 404 | 412 | $fork = $this->events->fire("dispatcher.request.".$this->request->getService(), "REQUEST", $this->request); |
| 405 | 413 | |
| 406 | - if ( $fork instanceof \Comodojo\Dispatcher\ObjectRequest\ObjectRequest ) $this->request = $fork; |
|
| 414 | + if ( $fork instanceof \Comodojo\Dispatcher\ObjectRequest\ObjectRequest ) { |
|
| 415 | + $this->request = $fork; |
|
| 416 | + } |
|
| 407 | 417 | |
| 408 | 418 | // Fire special event, it will not modify request |
| 409 | 419 | |
@@ -430,7 +440,9 @@ discard block |
||
| 430 | 440 | |
| 431 | 441 | $fork = $this->events->fire("dispatcher.routingtable", "TABLE", $this->routingtable); |
| 432 | 442 | |
| 433 | - if ( $fork instanceof \Comodojo\Dispatcher\ObjectRoutingTable\ObjectRoutingTable ) $this->routingtable = $fork; |
|
| 443 | + if ( $fork instanceof \Comodojo\Dispatcher\ObjectRoutingTable\ObjectRoutingTable ) { |
|
| 444 | + $this->routingtable = $fork; |
|
| 445 | + } |
|
| 434 | 446 | |
| 435 | 447 | // Retrieve current route from routing table |
| 436 | 448 | |
@@ -471,7 +483,9 @@ discard block |
||
| 471 | 483 | unset($preroute["parameters"]["ttl"]); |
| 472 | 484 | } |
| 473 | 485 | if ( isset($preroute["parameters"]["headers"]) ) { |
| 474 | - if ( is_array($preroute["parameters"]["headers"]) ) foreach ($preroute["parameters"]["headers"] as $header => $value) $this->serviceroute->setHeader($header, $value); |
|
| 486 | + if ( is_array($preroute["parameters"]["headers"]) ) { |
|
| 487 | + foreach ($preroute["parameters"]["headers"] as $header => $value) $this->serviceroute->setHeader($header, $value); |
|
| 488 | + } |
|
| 475 | 489 | unset($preroute["parameters"]["headers"]); |
| 476 | 490 | } |
| 477 | 491 | if ( isset($preroute["parameters"]["accessControl"]) ) { |
@@ -490,15 +504,21 @@ discard block |
||
| 490 | 504 | |
| 491 | 505 | $fork = $this->events->fire("dispatcher.serviceroute", "ROUTE", $this->serviceroute); |
| 492 | 506 | |
| 493 | - if ( $fork instanceof \Comodojo\Dispatcher\ObjectRoute\ObjectRoute ) $this->serviceroute = $fork; |
|
| 507 | + if ( $fork instanceof \Comodojo\Dispatcher\ObjectRoute\ObjectRoute ) { |
|
| 508 | + $this->serviceroute = $fork; |
|
| 509 | + } |
|
| 494 | 510 | |
| 495 | 511 | $fork = $this->events->fire("dispatcher.serviceroute.".$this->serviceroute->getType(), "ROUTE", $this->serviceroute); |
| 496 | 512 | |
| 497 | - if ( $fork instanceof \Comodojo\Dispatcher\ObjectRoute\ObjectRoute ) $this->serviceroute = $fork; |
|
| 513 | + if ( $fork instanceof \Comodojo\Dispatcher\ObjectRoute\ObjectRoute ) { |
|
| 514 | + $this->serviceroute = $fork; |
|
| 515 | + } |
|
| 498 | 516 | |
| 499 | 517 | $fork = $this->events->fire("dispatcher.serviceroute.".$this->serviceroute->getService(), "ROUTE", $this->serviceroute); |
| 500 | 518 | |
| 501 | - if ( $fork instanceof \Comodojo\Dispatcher\ObjectRoute\ObjectRoute ) $this->serviceroute = $fork; |
|
| 519 | + if ( $fork instanceof \Comodojo\Dispatcher\ObjectRoute\ObjectRoute ) { |
|
| 520 | + $this->serviceroute = $fork; |
|
| 521 | + } |
|
| 502 | 522 | |
| 503 | 523 | // Fire special event, it will not modify route |
| 504 | 524 | |
@@ -625,7 +645,9 @@ discard block |
||
| 625 | 645 | $scr = explode('/', $_SERVER['SCRIPT_NAME']); |
| 626 | 646 | |
| 627 | 647 | for($i= 0;$i < sizeof($scr);$i++) { |
| 628 | - if ($uri[$i] == $scr[$i]) unset($uri[$i]); |
|
| 648 | + if ($uri[$i] == $scr[$i]) { |
|
| 649 | + unset($uri[$i]); |
|
| 650 | + } |
|
| 629 | 651 | } |
| 630 | 652 | |
| 631 | 653 | $service_matrix = array_values($uri); |
@@ -638,16 +660,14 @@ discard block |
||
| 638 | 660 | |
| 639 | 661 | $service_attributes = empty($last) ? array_slice($service_matrix, 1, -1) : array_slice($service_matrix, 1); |
| 640 | 662 | |
| 641 | - } |
|
| 642 | - else { |
|
| 663 | + } else { |
|
| 643 | 664 | |
| 644 | 665 | $service_requested = "default"; |
| 645 | 666 | $service_attributes = array(); |
| 646 | 667 | |
| 647 | 668 | } |
| 648 | 669 | |
| 649 | - } |
|
| 650 | - else { |
|
| 670 | + } else { |
|
| 651 | 671 | |
| 652 | 672 | $service_matrix = $_GET; |
| 653 | 673 | |
@@ -657,8 +677,7 @@ discard block |
||
| 657 | 677 | unset($service_matrix["service"]); |
| 658 | 678 | $service_attributes = $service_matrix; |
| 659 | 679 | |
| 660 | - } |
|
| 661 | - else { |
|
| 680 | + } else { |
|
| 662 | 681 | |
| 663 | 682 | $service_requested = ""; |
| 664 | 683 | $service_attributes = array(); |
@@ -702,9 +721,9 @@ discard block |
||
| 702 | 721 | |
| 703 | 722 | $http = 'http' . ((isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') ? 's' : '') . '://'; |
| 704 | 723 | |
| 705 | - if ( is_null($service) ) $uri = ""; |
|
| 706 | - |
|
| 707 | - else { |
|
| 724 | + if ( is_null($service) ) { |
|
| 725 | + $uri = ""; |
|
| 726 | + } else { |
|
| 708 | 727 | |
| 709 | 728 | $self = $_SERVER['PHP_SELF']; |
| 710 | 729 | |
@@ -759,7 +778,9 @@ discard block |
||
| 759 | 778 | |
| 760 | 779 | private function attributesMatch($provided, $expected, $liked) { |
| 761 | 780 | |
| 762 | - if ( $this->working_mode == "STANDARD" ) return $this->parametersMatch($provided, $expected, $liked); |
|
| 781 | + if ( $this->working_mode == "STANDARD" ) { |
|
| 782 | + return $this->parametersMatch($provided, $expected, $liked); |
|
| 783 | + } |
|
| 763 | 784 | |
| 764 | 785 | $attributes = array(); |
| 765 | 786 | |
@@ -767,15 +788,13 @@ discard block |
||
| 767 | 788 | $esize = sizeof($expected); |
| 768 | 789 | $lsize = sizeof($liked); |
| 769 | 790 | |
| 770 | - if ( $psize < $esize ) throw new DispatcherException("Conversation error", 400); |
|
| 771 | - |
|
| 772 | - else if ( $psize == $esize ) { |
|
| 791 | + if ( $psize < $esize ) { |
|
| 792 | + throw new DispatcherException("Conversation error", 400); |
|
| 793 | + } else if ( $psize == $esize ) { |
|
| 773 | 794 | |
| 774 | 795 | $attributes = $psize == 0 ? array() : array_combine($expected, $provided); |
| 775 | 796 | |
| 776 | - } |
|
| 777 | - |
|
| 778 | - else { |
|
| 797 | + } else { |
|
| 779 | 798 | |
| 780 | 799 | if ( $esize == 0 ) { |
| 781 | 800 | |
@@ -801,13 +820,11 @@ discard block |
||
| 801 | 820 | |
| 802 | 821 | $l_attributes = array_combine(array_slice($liked, 0, $lvaluessize), $lvalues); |
| 803 | 822 | |
| 804 | - } |
|
| 805 | - else if ( $lvaluessize == $lsize ) { |
|
| 823 | + } else if ( $lvaluessize == $lsize ) { |
|
| 806 | 824 | |
| 807 | 825 | $l_attributes = $lvaluessize == 0 ? array() : array_combine($liked, $lvalues); |
| 808 | 826 | |
| 809 | - } |
|
| 810 | - else { |
|
| 827 | + } else { |
|
| 811 | 828 | |
| 812 | 829 | if ( $lsize == 0 ) { |
| 813 | 830 | |
@@ -837,7 +854,9 @@ discard block |
||
| 837 | 854 | |
| 838 | 855 | foreach ($expected as $parameter) { |
| 839 | 856 | |
| 840 | - if ( !isset($provided[$parameter]) ) throw new DispatcherException("Conversation error", 400); |
|
| 857 | + if ( !isset($provided[$parameter]) ) { |
|
| 858 | + throw new DispatcherException("Conversation error", 400); |
|
| 859 | + } |
|
| 841 | 860 | |
| 842 | 861 | } |
| 843 | 862 | |
@@ -877,13 +896,17 @@ discard block |
||
| 877 | 896 | |
| 878 | 897 | // If there's no cache for this request, use routing information to find service |
| 879 | 898 | |
| 880 | - if ( (include($target)) === false ) throw new DispatcherException("Cannot run service", 500); |
|
| 899 | + if ( (include($target)) === false ) { |
|
| 900 | + throw new DispatcherException("Cannot run service", 500); |
|
| 901 | + } |
|
| 881 | 902 | |
| 882 | 903 | // Find a service implementation and try to init it |
| 883 | 904 | |
| 884 | 905 | $service_class = $route->getClass(); |
| 885 | 906 | |
| 886 | - if ( empty($service_class) ) throw new DispatcherException("Cannot run service", 500); |
|
| 907 | + if ( empty($service_class) ) { |
|
| 908 | + throw new DispatcherException("Cannot run service", 500); |
|
| 909 | + } |
|
| 887 | 910 | |
| 888 | 911 | $service_class = "\\Comodojo\\Dispatcher\\Service\\".$service_class; |
| 889 | 912 | |
@@ -1010,13 +1033,17 @@ discard block |
||
| 1010 | 1033 | |
| 1011 | 1034 | $fork = $this->events->fire("dispatcher.result", "RESULT", $route); |
| 1012 | 1035 | |
| 1013 | - if ( $fork instanceof \Comodojo\Dispatcher\ObjectResult\ObjectResultInterface ) $route = $fork; |
|
| 1036 | + if ( $fork instanceof \Comodojo\Dispatcher\ObjectResult\ObjectResultInterface ) { |
|
| 1037 | + $route = $fork; |
|
| 1038 | + } |
|
| 1014 | 1039 | |
| 1015 | 1040 | // Fire second hook (level2), as specified above |
| 1016 | 1041 | |
| 1017 | 1042 | $fork = $this->events->fire($hook, "RESULT", $route); |
| 1018 | 1043 | |
| 1019 | - if ( $fork instanceof \Comodojo\Dispatcher\ObjectResult\ObjectResultInterface ) $route = $fork; |
|
| 1044 | + if ( $fork instanceof \Comodojo\Dispatcher\ObjectResult\ObjectResultInterface ) { |
|
| 1045 | + $route = $fork; |
|
| 1046 | + } |
|
| 1020 | 1047 | |
| 1021 | 1048 | // Now select and fire last hook (level3) |
| 1022 | 1049 | // This means that event engine will fire something like "dispatcher.route.200" |
@@ -1024,13 +1051,17 @@ discard block |
||
| 1024 | 1051 | |
| 1025 | 1052 | $fork = $this->events->fire($hook.".".$route->getStatusCode(), "RESULT", $route); |
| 1026 | 1053 | |
| 1027 | - if ( $fork instanceof \Comodojo\Dispatcher\ObjectResult\ObjectResultInterface ) $route = $fork; |
|
| 1054 | + if ( $fork instanceof \Comodojo\Dispatcher\ObjectResult\ObjectResultInterface ) { |
|
| 1055 | + $route = $fork; |
|
| 1056 | + } |
|
| 1028 | 1057 | |
| 1029 | 1058 | // Fire special event, it may modify result |
| 1030 | 1059 | |
| 1031 | 1060 | $fork = $this->events->fire("dispatcher.result.#", "RESULT", $route); |
| 1032 | 1061 | |
| 1033 | - if ( $fork instanceof \Comodojo\Dispatcher\ObjectResult\ObjectResultInterface ) $route = $fork; |
|
| 1062 | + if ( $fork instanceof \Comodojo\Dispatcher\ObjectResult\ObjectResultInterface ) { |
|
| 1063 | + $route = $fork; |
|
| 1064 | + } |
|
| 1034 | 1065 | |
| 1035 | 1066 | // After hooks: |
| 1036 | 1067 | // - store cache |
@@ -1052,7 +1083,9 @@ discard block |
||
| 1052 | 1083 | |
| 1053 | 1084 | $this->header->free(); |
| 1054 | 1085 | |
| 1055 | - if ( $cache == "CLIENT" OR $cache == "BOTH" ) $this->header->setClientCache($this->serviceroute->getTtl()); |
|
| 1086 | + if ( $cache == "CLIENT" OR $cache == "BOTH" ) { |
|
| 1087 | + $this->header->setClientCache($this->serviceroute->getTtl()); |
|
| 1088 | + } |
|
| 1056 | 1089 | |
| 1057 | 1090 | $this->header->setContentType($route->getContentType(), $route->getCharset()); |
| 1058 | 1091 | |
@@ -375,7 +375,7 @@ discard block |
||
| 375 | 375 | /** |
| 376 | 376 | * Dispatcher working method |
| 377 | 377 | * |
| 378 | - * @return mixed |
|
| 378 | + * @return string |
|
| 379 | 379 | */ |
| 380 | 380 | final public function dispatch() { |
| 381 | 381 | |
@@ -696,7 +696,7 @@ discard block |
||
| 696 | 696 | /** |
| 697 | 697 | * Return dispatcher baseurl, no matter the request |
| 698 | 698 | * |
| 699 | - * @return uri The baseurl |
|
| 699 | + * @return string The baseurl |
|
| 700 | 700 | */ |
| 701 | 701 | private function urlGetAbsolute($service=null) { |
| 702 | 702 | |
@@ -845,6 +845,9 @@ discard block |
||
| 845 | 845 | |
| 846 | 846 | } |
| 847 | 847 | |
| 848 | + /** |
|
| 849 | + * @return ObjectResultInterface |
|
| 850 | + */ |
|
| 848 | 851 | private function runService(ObjectRequest $request, ObjectRoute $route) { |
| 849 | 852 | |
| 850 | 853 | $method = $request->getMethod(); |
@@ -977,7 +980,7 @@ discard block |
||
| 977 | 980 | /** |
| 978 | 981 | * Route request handling ObjectResult hooks |
| 979 | 982 | * |
| 980 | - * @param ObjectResult $route An implementation of ObjectResultInterface |
|
| 983 | + * @param ObjectResultInterface $route An implementation of ObjectResultInterface |
|
| 981 | 984 | * @return string Content (stuff that will go on screen) |
| 982 | 985 | */ |
| 983 | 986 | private function route(ObjectResultInterface $route) { |
@@ -181,19 +181,19 @@ discard block |
||
| 181 | 181 | |
| 182 | 182 | // Starts composing request object (ObjectRequest) |
| 183 | 183 | |
| 184 | - list($request_service,$request_attributes) = $this->urlInterpreter($this->working_mode); |
|
| 184 | + list($request_service, $request_attributes) = $this->urlInterpreter($this->working_mode); |
|
| 185 | 185 | |
| 186 | 186 | list($request_parameters, $request_raw_parameters) = $this->deserializeParameters($this->request_method); |
| 187 | 187 | |
| 188 | - $this->logger->debug('Provided attributes',$request_attributes); |
|
| 188 | + $this->logger->debug('Provided attributes', $request_attributes); |
|
| 189 | 189 | |
| 190 | - $this->logger->debug('Provided parameters',$request_parameters); |
|
| 190 | + $this->logger->debug('Provided parameters', $request_parameters); |
|
| 191 | 191 | |
| 192 | 192 | $request_headers = $this->header->getRequestHeaders(); |
| 193 | 193 | |
| 194 | 194 | // Before composing the object request, remember to define the current (absolute) dispatcher baseurl |
| 195 | 195 | // (if not specified in dispatcher-config) |
| 196 | - if ( !defined("DISPATCHER_BASEURL") ) define("DISPATCHER_BASEURL",$this->urlGetAbsolute($request_service)); |
|
| 196 | + if (!defined("DISPATCHER_BASEURL")) define("DISPATCHER_BASEURL", $this->urlGetAbsolute($request_service)); |
|
| 197 | 197 | |
| 198 | 198 | // Now let's compose request object |
| 199 | 199 | |
@@ -222,21 +222,21 @@ discard block |
||
| 222 | 222 | * @param array $parameters (optional) Service options (cache, ...) |
| 223 | 223 | * @param bool $relative (optional) If true, target will be assumed in default service directory |
| 224 | 224 | */ |
| 225 | - final public function setRoute($service, $type, $target, $parameters=array(), $relative=true) { |
|
| 225 | + final public function setRoute($service, $type, $target, $parameters = array(), $relative = true) { |
|
| 226 | 226 | |
| 227 | 227 | try { |
| 228 | 228 | |
| 229 | - if ( strtoupper($type) == "ROUTE" ) { |
|
| 229 | + if (strtoupper($type) == "ROUTE") { |
|
| 230 | 230 | |
| 231 | - if ( $relative ) $this->routingtable->setRoute($service, $type, DISPATCHER_SERVICES_FOLDER.$target, $parameters); |
|
| 231 | + if ($relative) $this->routingtable->setRoute($service, $type, DISPATCHER_SERVICES_FOLDER.$target, $parameters); |
|
| 232 | 232 | |
| 233 | 233 | else $this->routingtable->setRoute($service, $type, $target, $parameters); |
| 234 | 234 | |
| 235 | 235 | } |
| 236 | 236 | |
| 237 | - else if ( strtoupper($type) == "REDIRECT" ) { |
|
| 237 | + else if (strtoupper($type) == "REDIRECT") { |
|
| 238 | 238 | |
| 239 | - if ( $relative ) $this->routingtable->setRoute($service, $type, DISPATCHER_BASEURL.$target, $parameters); |
|
| 239 | + if ($relative) $this->routingtable->setRoute($service, $type, DISPATCHER_BASEURL.$target, $parameters); |
|
| 240 | 240 | |
| 241 | 241 | else $this->routingtable->setRoute($service, $type, $target, $parameters); |
| 242 | 242 | |
@@ -247,7 +247,7 @@ discard block |
||
| 247 | 247 | } catch (Exception $e) { |
| 248 | 248 | |
| 249 | 249 | //debug error but do not stop dispatcher |
| 250 | - $this->logger->warning( 'Unable to set route', array('SERVIVE' => $service) ); |
|
| 250 | + $this->logger->warning('Unable to set route', array('SERVIVE' => $service)); |
|
| 251 | 251 | |
| 252 | 252 | } |
| 253 | 253 | |
@@ -269,7 +269,7 @@ discard block |
||
| 269 | 269 | } catch (Exception $e) { |
| 270 | 270 | |
| 271 | 271 | //debug error but do not stop dispatcher |
| 272 | - $this->logger->warning( 'Unable to unset route', array('SERVIVE' => $service) ); |
|
| 272 | + $this->logger->warning('Unable to unset route', array('SERVIVE' => $service)); |
|
| 273 | 273 | |
| 274 | 274 | } |
| 275 | 275 | |
@@ -282,7 +282,7 @@ discard block |
||
| 282 | 282 | * @param string $callback The callback (or class if $method is specified) |
| 283 | 283 | * @param string $method (optional) Method for $callback |
| 284 | 284 | */ |
| 285 | - final public function addHook($event, $callback, $method=null) { |
|
| 285 | + final public function addHook($event, $callback, $method = null) { |
|
| 286 | 286 | |
| 287 | 287 | try { |
| 288 | 288 | |
@@ -291,11 +291,11 @@ discard block |
||
| 291 | 291 | } catch (Exception $e) { |
| 292 | 292 | |
| 293 | 293 | //debug error but do not stop dispatcher |
| 294 | - $this->logger->warning( 'Unable to add hook', array( |
|
| 294 | + $this->logger->warning('Unable to add hook', array( |
|
| 295 | 295 | 'CALLBACK' => $callback, |
| 296 | 296 | 'METHOD' => $method, |
| 297 | 297 | 'EVENT' => $event |
| 298 | - ) ); |
|
| 298 | + )); |
|
| 299 | 299 | |
| 300 | 300 | } |
| 301 | 301 | |
@@ -307,7 +307,7 @@ discard block |
||
| 307 | 307 | * @param string $event The event name |
| 308 | 308 | * @param string $callback The callback (or class if $method is specified) |
| 309 | 309 | */ |
| 310 | - final public function removeHook($event, $callback=null) { |
|
| 310 | + final public function removeHook($event, $callback = null) { |
|
| 311 | 311 | |
| 312 | 312 | try { |
| 313 | 313 | |
@@ -316,10 +316,10 @@ discard block |
||
| 316 | 316 | } catch (Exception $e) { |
| 317 | 317 | |
| 318 | 318 | //debug error but do not stop dispatcher |
| 319 | - $this->logger->warning( 'Unable to remove hook', array( |
|
| 319 | + $this->logger->warning('Unable to remove hook', array( |
|
| 320 | 320 | 'CALLBACK' => $callback, |
| 321 | 321 | 'EVENT' => $event |
| 322 | - ) ); |
|
| 322 | + )); |
|
| 323 | 323 | |
| 324 | 324 | } |
| 325 | 325 | |
@@ -331,7 +331,7 @@ discard block |
||
| 331 | 331 | * @param string $plugin The plugin name |
| 332 | 332 | * @param string $folder (optional) plugin folder (if omitted, dispatcher will use default one) |
| 333 | 333 | */ |
| 334 | - final public function loadPlugin($plugin, $folder=DISPATCHER_PLUGINS_FOLDER) { |
|
| 334 | + final public function loadPlugin($plugin, $folder = DISPATCHER_PLUGINS_FOLDER) { |
|
| 335 | 335 | |
| 336 | 336 | include $folder.$plugin.".php"; |
| 337 | 337 | |
@@ -368,7 +368,7 @@ discard block |
||
| 368 | 368 | */ |
| 369 | 369 | final public function clearCache($all = null) { |
| 370 | 370 | |
| 371 | - return $this->cacher->purge( $all == true ? null : $this->service_url ); |
|
| 371 | + return $this->cacher->purge($all == true ? null : $this->service_url); |
|
| 372 | 372 | |
| 373 | 373 | } |
| 374 | 374 | |
@@ -391,19 +391,19 @@ discard block |
||
| 391 | 391 | |
| 392 | 392 | $fork = $this->events->fire("dispatcher.request", "REQUEST", $this->request); |
| 393 | 393 | |
| 394 | - if ( $fork instanceof \Comodojo\Dispatcher\ObjectRequest\ObjectRequest ) $this->request = $fork; |
|
| 394 | + if ($fork instanceof \Comodojo\Dispatcher\ObjectRequest\ObjectRequest) $this->request = $fork; |
|
| 395 | 395 | |
| 396 | 396 | // Fire level3 event "dispatcher.request.[method]" |
| 397 | 397 | |
| 398 | 398 | $fork = $this->events->fire("dispatcher.request.".$this->request_method, "REQUEST", $this->request); |
| 399 | 399 | |
| 400 | - if ( $fork instanceof \Comodojo\Dispatcher\ObjectRequest\ObjectRequest ) $this->request = $fork; |
|
| 400 | + if ($fork instanceof \Comodojo\Dispatcher\ObjectRequest\ObjectRequest) $this->request = $fork; |
|
| 401 | 401 | |
| 402 | 402 | // Fire level3 event "dispatcher.request.[service]" |
| 403 | 403 | |
| 404 | 404 | $fork = $this->events->fire("dispatcher.request.".$this->request->getService(), "REQUEST", $this->request); |
| 405 | 405 | |
| 406 | - if ( $fork instanceof \Comodojo\Dispatcher\ObjectRequest\ObjectRequest ) $this->request = $fork; |
|
| 406 | + if ($fork instanceof \Comodojo\Dispatcher\ObjectRequest\ObjectRequest) $this->request = $fork; |
|
| 407 | 407 | |
| 408 | 408 | // Fire special event, it will not modify request |
| 409 | 409 | |
@@ -411,7 +411,7 @@ discard block |
||
| 411 | 411 | |
| 412 | 412 | // Check if dispatcher is enabled |
| 413 | 413 | |
| 414 | - if ( $this->enabled == false ) { |
|
| 414 | + if ($this->enabled == false) { |
|
| 415 | 415 | |
| 416 | 416 | $route = new ObjectError(); |
| 417 | 417 | $route->setStatusCode(503); |
@@ -430,7 +430,7 @@ discard block |
||
| 430 | 430 | |
| 431 | 431 | $fork = $this->events->fire("dispatcher.routingtable", "TABLE", $this->routingtable); |
| 432 | 432 | |
| 433 | - if ( $fork instanceof \Comodojo\Dispatcher\ObjectRoutingTable\ObjectRoutingTable ) $this->routingtable = $fork; |
|
| 433 | + if ($fork instanceof \Comodojo\Dispatcher\ObjectRoutingTable\ObjectRoutingTable) $this->routingtable = $fork; |
|
| 434 | 434 | |
| 435 | 435 | // Retrieve current route from routing table |
| 436 | 436 | |
@@ -447,34 +447,34 @@ discard block |
||
| 447 | 447 | ->setType($preroute["type"]) |
| 448 | 448 | ->setTarget($preroute["target"]); |
| 449 | 449 | |
| 450 | - if ( isset($preroute["parameters"]["class"]) ) { |
|
| 450 | + if (isset($preroute["parameters"]["class"])) { |
|
| 451 | 451 | $this->serviceroute->setClass($preroute["parameters"]["class"]); |
| 452 | 452 | } else { |
| 453 | 453 | $t = pathinfo($preroute["target"]); |
| 454 | 454 | $this->serviceroute->setClass(preg_replace('/\\.[^.\\s]{3,4}$/', '', $t["filename"])); |
| 455 | 455 | } |
| 456 | 456 | |
| 457 | - if ( isset($preroute["parameters"]["redirectCode"]) ) { |
|
| 457 | + if (isset($preroute["parameters"]["redirectCode"])) { |
|
| 458 | 458 | $this->serviceroute->setRedirectCode($preroute["parameters"]["redirectCode"]); |
| 459 | 459 | unset($preroute["parameters"]["redirectCode"]); |
| 460 | 460 | } |
| 461 | - if ( isset($preroute["parameters"]["errorCode"]) ) { |
|
| 461 | + if (isset($preroute["parameters"]["errorCode"])) { |
|
| 462 | 462 | $this->serviceroute->setErrorCode($preroute["parameters"]["errorCode"]); |
| 463 | 463 | unset($preroute["parameters"]["errorCode"]); |
| 464 | 464 | } |
| 465 | - if ( isset($preroute["parameters"]["cache"]) ) { |
|
| 465 | + if (isset($preroute["parameters"]["cache"])) { |
|
| 466 | 466 | $this->serviceroute->setCache($preroute["parameters"]["cache"]); |
| 467 | 467 | unset($preroute["parameters"]["cache"]); |
| 468 | 468 | } |
| 469 | - if ( isset($preroute["parameters"]["ttl"]) ) { |
|
| 469 | + if (isset($preroute["parameters"]["ttl"])) { |
|
| 470 | 470 | $this->serviceroute->setTtl($preroute["parameters"]["ttl"]); |
| 471 | 471 | unset($preroute["parameters"]["ttl"]); |
| 472 | 472 | } |
| 473 | - if ( isset($preroute["parameters"]["headers"]) ) { |
|
| 474 | - if ( is_array($preroute["parameters"]["headers"]) ) foreach ($preroute["parameters"]["headers"] as $header => $value) $this->serviceroute->setHeader($header, $value); |
|
| 473 | + if (isset($preroute["parameters"]["headers"])) { |
|
| 474 | + if (is_array($preroute["parameters"]["headers"])) foreach ($preroute["parameters"]["headers"] as $header => $value) $this->serviceroute->setHeader($header, $value); |
|
| 475 | 475 | unset($preroute["parameters"]["headers"]); |
| 476 | 476 | } |
| 477 | - if ( isset($preroute["parameters"]["accessControl"]) ) { |
|
| 477 | + if (isset($preroute["parameters"]["accessControl"])) { |
|
| 478 | 478 | $this->serviceroute->setRedirectCode($preroute["parameters"]["accessControl"]); |
| 479 | 479 | unset($preroute["parameters"]["accessControl"]); |
| 480 | 480 | } |
@@ -490,15 +490,15 @@ discard block |
||
| 490 | 490 | |
| 491 | 491 | $fork = $this->events->fire("dispatcher.serviceroute", "ROUTE", $this->serviceroute); |
| 492 | 492 | |
| 493 | - if ( $fork instanceof \Comodojo\Dispatcher\ObjectRoute\ObjectRoute ) $this->serviceroute = $fork; |
|
| 493 | + if ($fork instanceof \Comodojo\Dispatcher\ObjectRoute\ObjectRoute) $this->serviceroute = $fork; |
|
| 494 | 494 | |
| 495 | 495 | $fork = $this->events->fire("dispatcher.serviceroute.".$this->serviceroute->getType(), "ROUTE", $this->serviceroute); |
| 496 | 496 | |
| 497 | - if ( $fork instanceof \Comodojo\Dispatcher\ObjectRoute\ObjectRoute ) $this->serviceroute = $fork; |
|
| 497 | + if ($fork instanceof \Comodojo\Dispatcher\ObjectRoute\ObjectRoute) $this->serviceroute = $fork; |
|
| 498 | 498 | |
| 499 | 499 | $fork = $this->events->fire("dispatcher.serviceroute.".$this->serviceroute->getService(), "ROUTE", $this->serviceroute); |
| 500 | 500 | |
| 501 | - if ( $fork instanceof \Comodojo\Dispatcher\ObjectRoute\ObjectRoute ) $this->serviceroute = $fork; |
|
| 501 | + if ($fork instanceof \Comodojo\Dispatcher\ObjectRoute\ObjectRoute) $this->serviceroute = $fork; |
|
| 502 | 502 | |
| 503 | 503 | // Fire special event, it will not modify route |
| 504 | 504 | |
@@ -508,11 +508,11 @@ discard block |
||
| 508 | 508 | |
| 509 | 509 | $accesscontrol = preg_replace('/\s+/', '', $this->serviceroute->getAccessControl()); |
| 510 | 510 | |
| 511 | - if ( $accesscontrol != null AND $accesscontrol != "*" ) { |
|
| 511 | + if ($accesscontrol != null AND $accesscontrol != "*") { |
|
| 512 | 512 | |
| 513 | 513 | $origins = explode(",", $accesscontrol); |
| 514 | 514 | |
| 515 | - if ( !in_array(@$_SERVER['HTTP_ORIGIN'], $origins) ) { |
|
| 515 | + if (!in_array(@$_SERVER['HTTP_ORIGIN'], $origins)) { |
|
| 516 | 516 | |
| 517 | 517 | $route = new ObjectError(); |
| 518 | 518 | $route->setStatusCode(403)->setContent("Origin not allowed"); |
@@ -539,7 +539,7 @@ discard block |
||
| 539 | 539 | 'REDIRECTCODE' => $this->serviceroute->getRedirectCode() |
| 540 | 540 | )); |
| 541 | 541 | |
| 542 | - switch($this->serviceroute->getType()) { |
|
| 542 | + switch ($this->serviceroute->getType()) { |
|
| 543 | 543 | |
| 544 | 544 | case "ERROR": |
| 545 | 545 | |
@@ -624,7 +624,7 @@ discard block |
||
| 624 | 624 | $uri = explode('/', $_SERVER['REQUEST_URI']); |
| 625 | 625 | $scr = explode('/', $_SERVER['SCRIPT_NAME']); |
| 626 | 626 | |
| 627 | - for($i= 0;$i < sizeof($scr);$i++) { |
|
| 627 | + for ($i = 0; $i < sizeof($scr); $i++) { |
|
| 628 | 628 | if ($uri[$i] == $scr[$i]) unset($uri[$i]); |
| 629 | 629 | } |
| 630 | 630 | |
@@ -698,21 +698,21 @@ discard block |
||
| 698 | 698 | * |
| 699 | 699 | * @return uri The baseurl |
| 700 | 700 | */ |
| 701 | - private function urlGetAbsolute($service=null) { |
|
| 701 | + private function urlGetAbsolute($service = null) { |
|
| 702 | 702 | |
| 703 | - $http = 'http' . ((isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') ? 's' : '') . '://'; |
|
| 703 | + $http = 'http'.((isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') ? 's' : '').'://'; |
|
| 704 | 704 | |
| 705 | - if ( is_null($service) ) $uri = ""; |
|
| 705 | + if (is_null($service)) $uri = ""; |
|
| 706 | 706 | |
| 707 | 707 | else { |
| 708 | 708 | |
| 709 | 709 | $self = $_SERVER['PHP_SELF']; |
| 710 | 710 | |
| 711 | - $uri = preg_replace("/\/index.php(.*?)$/i","",$self); |
|
| 711 | + $uri = preg_replace("/\/index.php(.*?)$/i", "", $self); |
|
| 712 | 712 | |
| 713 | 713 | } |
| 714 | 714 | |
| 715 | - return ( $http . $_SERVER['HTTP_HOST'] . $uri . "/" ); |
|
| 715 | + return ($http.$_SERVER['HTTP_HOST'].$uri."/"); |
|
| 716 | 716 | |
| 717 | 717 | } |
| 718 | 718 | |
@@ -736,7 +736,7 @@ discard block |
||
| 736 | 736 | |
| 737 | 737 | $parameters = array(); |
| 738 | 738 | |
| 739 | - switch($method) { |
|
| 739 | + switch ($method) { |
|
| 740 | 740 | |
| 741 | 741 | case 'POST': |
| 742 | 742 | |
@@ -759,7 +759,7 @@ discard block |
||
| 759 | 759 | |
| 760 | 760 | private function attributesMatch($provided, $expected, $liked) { |
| 761 | 761 | |
| 762 | - if ( $this->working_mode == "STANDARD" ) return $this->parametersMatch($provided, $expected, $liked); |
|
| 762 | + if ($this->working_mode == "STANDARD") return $this->parametersMatch($provided, $expected, $liked); |
|
| 763 | 763 | |
| 764 | 764 | $attributes = array(); |
| 765 | 765 | |
@@ -767,9 +767,9 @@ discard block |
||
| 767 | 767 | $esize = sizeof($expected); |
| 768 | 768 | $lsize = sizeof($liked); |
| 769 | 769 | |
| 770 | - if ( $psize < $esize ) throw new DispatcherException("Conversation error", 400); |
|
| 770 | + if ($psize < $esize) throw new DispatcherException("Conversation error", 400); |
|
| 771 | 771 | |
| 772 | - else if ( $psize == $esize ) { |
|
| 772 | + else if ($psize == $esize) { |
|
| 773 | 773 | |
| 774 | 774 | $attributes = $psize == 0 ? array() : array_combine($expected, $provided); |
| 775 | 775 | |
@@ -777,7 +777,7 @@ discard block |
||
| 777 | 777 | |
| 778 | 778 | else { |
| 779 | 779 | |
| 780 | - if ( $esize == 0 ) { |
|
| 780 | + if ($esize == 0) { |
|
| 781 | 781 | |
| 782 | 782 | $e_attributes = array(); |
| 783 | 783 | |
@@ -797,19 +797,19 @@ discard block |
||
| 797 | 797 | |
| 798 | 798 | $l_attributes = array(); |
| 799 | 799 | |
| 800 | - if ( $lvaluessize < $lsize ) { |
|
| 800 | + if ($lvaluessize < $lsize) { |
|
| 801 | 801 | |
| 802 | 802 | $l_attributes = array_combine(array_slice($liked, 0, $lvaluessize), $lvalues); |
| 803 | 803 | |
| 804 | 804 | } |
| 805 | - else if ( $lvaluessize == $lsize ) { |
|
| 805 | + else if ($lvaluessize == $lsize) { |
|
| 806 | 806 | |
| 807 | 807 | $l_attributes = $lvaluessize == 0 ? array() : array_combine($liked, $lvalues); |
| 808 | 808 | |
| 809 | 809 | } |
| 810 | 810 | else { |
| 811 | 811 | |
| 812 | - if ( $lsize == 0 ) { |
|
| 812 | + if ($lsize == 0) { |
|
| 813 | 813 | |
| 814 | 814 | $l_attributes = $lvalues; |
| 815 | 815 | |
@@ -837,7 +837,7 @@ discard block |
||
| 837 | 837 | |
| 838 | 838 | foreach ($expected as $parameter) { |
| 839 | 839 | |
| 840 | - if ( !isset($provided[$parameter]) ) throw new DispatcherException("Conversation error", 400); |
|
| 840 | + if (!isset($provided[$parameter])) throw new DispatcherException("Conversation error", 400); |
|
| 841 | 841 | |
| 842 | 842 | } |
| 843 | 843 | |
@@ -855,11 +855,11 @@ discard block |
||
| 855 | 855 | |
| 856 | 856 | // First of all, check cache (in case of GET request) |
| 857 | 857 | |
| 858 | - if ( $method == "GET" AND ( $cache == "SERVER" OR $cache == "BOTH" ) ) { |
|
| 858 | + if ($method == "GET" AND ($cache == "SERVER" OR $cache == "BOTH")) { |
|
| 859 | 859 | |
| 860 | 860 | $from_cache = $this->cacher->get($this->service_url, $ttl); |
| 861 | 861 | |
| 862 | - if ( is_array($from_cache) ) { |
|
| 862 | + if (is_array($from_cache)) { |
|
| 863 | 863 | |
| 864 | 864 | $maxage = $from_cache["maxage"]; |
| 865 | 865 | $bestbefore = $from_cache["bestbefore"]; |
@@ -877,13 +877,13 @@ discard block |
||
| 877 | 877 | |
| 878 | 878 | // If there's no cache for this request, use routing information to find service |
| 879 | 879 | |
| 880 | - if ( (include($target)) === false ) throw new DispatcherException("Cannot run service", 500); |
|
| 880 | + if ((include($target)) === false) throw new DispatcherException("Cannot run service", 500); |
|
| 881 | 881 | |
| 882 | 882 | // Find a service implementation and try to init it |
| 883 | 883 | |
| 884 | 884 | $service_class = $route->getClass(); |
| 885 | 885 | |
| 886 | - if ( empty($service_class) ) throw new DispatcherException("Cannot run service", 500); |
|
| 886 | + if (empty($service_class)) throw new DispatcherException("Cannot run service", 500); |
|
| 887 | 887 | |
| 888 | 888 | $service_class = "\\Comodojo\\Dispatcher\\Service\\".$service_class; |
| 889 | 889 | |
@@ -903,7 +903,7 @@ discard block |
||
| 903 | 903 | |
| 904 | 904 | // Check if service supports current HTTP method |
| 905 | 905 | |
| 906 | - if ( !in_array($method, explode(",", $theservice->getSupportedMethods())) ) { |
|
| 906 | + if (!in_array($method, explode(",", $theservice->getSupportedMethods()))) { |
|
| 907 | 907 | |
| 908 | 908 | throw new DispatcherException("Allow: ".$theservice->getSupportedMethods(), 405); |
| 909 | 909 | |
@@ -911,9 +911,9 @@ discard block |
||
| 911 | 911 | |
| 912 | 912 | // Check if service implements current HTTP method |
| 913 | 913 | |
| 914 | - if ( !in_array($method, $theservice->getImplementedMethods()) ) { |
|
| 914 | + if (!in_array($method, $theservice->getImplementedMethods())) { |
|
| 915 | 915 | |
| 916 | - throw new DispatcherException("Allow: ".implode(",",$theservice->getImplementedMethods()), 501); |
|
| 916 | + throw new DispatcherException("Allow: ".implode(",", $theservice->getImplementedMethods()), 501); |
|
| 917 | 917 | |
| 918 | 918 | } |
| 919 | 919 | |
@@ -956,7 +956,7 @@ discard block |
||
| 956 | 956 | $return->setService($service) |
| 957 | 957 | ->setStatusCode($theservice->getStatusCode()) |
| 958 | 958 | ->setContent($result) |
| 959 | - ->setHeaders( array_merge($theservice->getHeaders(), $route->getHeaders()) ) |
|
| 959 | + ->setHeaders(array_merge($theservice->getHeaders(), $route->getHeaders())) |
|
| 960 | 960 | ->setContentType($theservice->getContentType()) |
| 961 | 961 | ->setCharset($theservice->getCharset()); |
| 962 | 962 | |
@@ -986,15 +986,15 @@ discard block |
||
| 986 | 986 | // This means event engine will fire a dispatcher.[routetype] event |
| 987 | 987 | // In case of wrong instance, create an ObjectError (500, null) instance |
| 988 | 988 | |
| 989 | - if ( $route instanceof ObjectSuccess ) { |
|
| 989 | + if ($route instanceof ObjectSuccess) { |
|
| 990 | 990 | |
| 991 | 991 | $hook = "dispatcher.route"; |
| 992 | 992 | |
| 993 | - } else if ( $route instanceof ObjectError ) { |
|
| 993 | + } else if ($route instanceof ObjectError) { |
|
| 994 | 994 | |
| 995 | 995 | $hook = "dispatcher.error"; |
| 996 | 996 | |
| 997 | - } else if ( $route instanceof ObjectRedirect ) { |
|
| 997 | + } else if ($route instanceof ObjectRedirect) { |
|
| 998 | 998 | |
| 999 | 999 | $hook = "dispatcher.redirect"; |
| 1000 | 1000 | |
@@ -1010,13 +1010,13 @@ discard block |
||
| 1010 | 1010 | |
| 1011 | 1011 | $fork = $this->events->fire("dispatcher.result", "RESULT", $route); |
| 1012 | 1012 | |
| 1013 | - if ( $fork instanceof \Comodojo\Dispatcher\ObjectResult\ObjectResultInterface ) $route = $fork; |
|
| 1013 | + if ($fork instanceof \Comodojo\Dispatcher\ObjectResult\ObjectResultInterface) $route = $fork; |
|
| 1014 | 1014 | |
| 1015 | 1015 | // Fire second hook (level2), as specified above |
| 1016 | 1016 | |
| 1017 | 1017 | $fork = $this->events->fire($hook, "RESULT", $route); |
| 1018 | 1018 | |
| 1019 | - if ( $fork instanceof \Comodojo\Dispatcher\ObjectResult\ObjectResultInterface ) $route = $fork; |
|
| 1019 | + if ($fork instanceof \Comodojo\Dispatcher\ObjectResult\ObjectResultInterface) $route = $fork; |
|
| 1020 | 1020 | |
| 1021 | 1021 | // Now select and fire last hook (level3) |
| 1022 | 1022 | // This means that event engine will fire something like "dispatcher.route.200" |
@@ -1024,13 +1024,13 @@ discard block |
||
| 1024 | 1024 | |
| 1025 | 1025 | $fork = $this->events->fire($hook.".".$route->getStatusCode(), "RESULT", $route); |
| 1026 | 1026 | |
| 1027 | - if ( $fork instanceof \Comodojo\Dispatcher\ObjectResult\ObjectResultInterface ) $route = $fork; |
|
| 1027 | + if ($fork instanceof \Comodojo\Dispatcher\ObjectResult\ObjectResultInterface) $route = $fork; |
|
| 1028 | 1028 | |
| 1029 | 1029 | // Fire special event, it may modify result |
| 1030 | 1030 | |
| 1031 | 1031 | $fork = $this->events->fire("dispatcher.result.#", "RESULT", $route); |
| 1032 | 1032 | |
| 1033 | - if ( $fork instanceof \Comodojo\Dispatcher\ObjectResult\ObjectResultInterface ) $route = $fork; |
|
| 1033 | + if ($fork instanceof \Comodojo\Dispatcher\ObjectResult\ObjectResultInterface) $route = $fork; |
|
| 1034 | 1034 | |
| 1035 | 1035 | // After hooks: |
| 1036 | 1036 | // - store cache |
@@ -1039,10 +1039,10 @@ discard block |
||
| 1039 | 1039 | |
| 1040 | 1040 | $cache = $route instanceof \Comodojo\Dispatcher\ObjectResult\ObjectSuccess ? $this->serviceroute->getCache() : null; |
| 1041 | 1041 | |
| 1042 | - if ( $this->request_method == "GET" AND |
|
| 1043 | - ( $cache == "SERVER" OR $cache == "BOTH" ) AND |
|
| 1042 | + if ($this->request_method == "GET" AND |
|
| 1043 | + ($cache == "SERVER" OR $cache == "BOTH") AND |
|
| 1044 | 1044 | $this->result_comes_from_cache == false AND |
| 1045 | - $route instanceof \Comodojo\Dispatcher\ObjectResult\ObjectSuccess ) |
|
| 1045 | + $route instanceof \Comodojo\Dispatcher\ObjectResult\ObjectSuccess) |
|
| 1046 | 1046 | { |
| 1047 | 1047 | |
| 1048 | 1048 | $this->cacher->set($this->service_url, $route); |
@@ -1052,7 +1052,7 @@ discard block |
||
| 1052 | 1052 | |
| 1053 | 1053 | $this->header->free(); |
| 1054 | 1054 | |
| 1055 | - if ( $cache == "CLIENT" OR $cache == "BOTH" ) $this->header->setClientCache($this->serviceroute->getTtl()); |
|
| 1055 | + if ($cache == "CLIENT" OR $cache == "BOTH") $this->header->setClientCache($this->serviceroute->getTtl()); |
|
| 1056 | 1056 | |
| 1057 | 1057 | $this->header->setContentType($route->getContentType(), $route->getCharset()); |
| 1058 | 1058 | |