@@ -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 | |
@@ -1074,7 +1074,7 @@ discard block |
||
| 1074 | 1074 | |
| 1075 | 1075 | private static function end($result) { |
| 1076 | 1076 | |
| 1077 | - if ( defined('DISPATCHER_PHPUNIT_TEST') && @constant('DISPATCHER_PHPUNIT_TEST') === true ) { |
|
| 1077 | + if (defined('DISPATCHER_PHPUNIT_TEST') && @constant('DISPATCHER_PHPUNIT_TEST') === true) { |
|
| 1078 | 1078 | |
| 1079 | 1079 | return $result; |
| 1080 | 1080 | |
@@ -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 | |
@@ -153,7 +153,7 @@ discard block |
||
| 153 | 153 | * |
| 154 | 154 | * @var array |
| 155 | 155 | */ |
| 156 | - private $supported_success_codes = array(200,202,204); |
|
| 156 | + private $supported_success_codes = array(200, 202, 204); |
|
| 157 | 157 | |
| 158 | 158 | /*************** HTTP METHODS IMPLEMENTATIONS **************/ |
| 159 | 159 | |
@@ -248,7 +248,7 @@ discard block |
||
| 248 | 248 | * |
| 249 | 249 | * @return Object $this |
| 250 | 250 | */ |
| 251 | - final public function expects($method, $attributes, $parameters=array()) { |
|
| 251 | + final public function expects($method, $attributes, $parameters = array()) { |
|
| 252 | 252 | |
| 253 | 253 | $method = strtoupper($method); |
| 254 | 254 | |
@@ -268,7 +268,7 @@ discard block |
||
| 268 | 268 | * |
| 269 | 269 | * @return Object $this |
| 270 | 270 | */ |
| 271 | - final public function likes($method, $attributes, $parameters=array()) { |
|
| 271 | + final public function likes($method, $attributes, $parameters = array()) { |
|
| 272 | 272 | |
| 273 | 273 | $method = strtoupper($method); |
| 274 | 274 | |
@@ -421,7 +421,7 @@ discard block |
||
| 421 | 421 | * |
| 422 | 422 | * @return Object $this |
| 423 | 423 | */ |
| 424 | - final public function setHeader($header, $value=null) { |
|
| 424 | + final public function setHeader($header, $value = null) { |
|
| 425 | 425 | |
| 426 | 426 | $this->headers[$header] = $value; |
| 427 | 427 | |
@@ -438,7 +438,7 @@ discard block |
||
| 438 | 438 | */ |
| 439 | 439 | final public function unsetHeader($header) { |
| 440 | 440 | |
| 441 | - if ( isset($this->headers[$header]) ) { |
|
| 441 | + if (isset($this->headers[$header])) { |
|
| 442 | 442 | |
| 443 | 443 | unset($this->headers[$header]); |
| 444 | 444 | |
@@ -459,7 +459,7 @@ discard block |
||
| 459 | 459 | */ |
| 460 | 460 | final public function getHeader($header) { |
| 461 | 461 | |
| 462 | - if ( isset($this->headers[$header]) ) return $this->headers[$header]; |
|
| 462 | + if (isset($this->headers[$header])) return $this->headers[$header]; |
|
| 463 | 463 | |
| 464 | 464 | return null; |
| 465 | 465 | |
@@ -522,15 +522,15 @@ discard block |
||
| 522 | 522 | */ |
| 523 | 523 | final public function getImplementedMethods() { |
| 524 | 524 | |
| 525 | - if ( method_exists($this, 'any') ) return explode(",",$this->supported_http_methods); |
|
| 525 | + if (method_exists($this, 'any')) return explode(",", $this->supported_http_methods); |
|
| 526 | 526 | |
| 527 | - $supported_methods = explode(',',$this->supported_http_methods); |
|
| 527 | + $supported_methods = explode(',', $this->supported_http_methods); |
|
| 528 | 528 | |
| 529 | 529 | $implemented_methods = array(); |
| 530 | 530 | |
| 531 | - foreach ( $supported_methods as $method ) { |
|
| 531 | + foreach ($supported_methods as $method) { |
|
| 532 | 532 | |
| 533 | - if ( method_exists($this, strtolower($method)) ) array_push($implemented_methods,$method); |
|
| 533 | + if (method_exists($this, strtolower($method))) array_push($implemented_methods, $method); |
|
| 534 | 534 | |
| 535 | 535 | } |
| 536 | 536 | |
@@ -545,7 +545,7 @@ discard block |
||
| 545 | 545 | */ |
| 546 | 546 | final public function getCallableMethod($method) { |
| 547 | 547 | |
| 548 | - if ( method_exists($this, strtolower($method)) ) return strtolower($method); |
|
| 548 | + if (method_exists($this, strtolower($method))) return strtolower($method); |
|
| 549 | 549 | |
| 550 | 550 | else return "any"; |
| 551 | 551 | |
@@ -562,9 +562,9 @@ discard block |
||
| 562 | 562 | |
| 563 | 563 | return array( |
| 564 | 564 | |
| 565 | - ( sizeof($this->expected_attributes[$method]) == 0 AND sizeof($this->expected_attributes["ANY"]) != 0 ) ? $this->expected_attributes["ANY"] : $this->expected_attributes[$method], |
|
| 565 | + (sizeof($this->expected_attributes[$method]) == 0 AND sizeof($this->expected_attributes["ANY"]) != 0) ? $this->expected_attributes["ANY"] : $this->expected_attributes[$method], |
|
| 566 | 566 | |
| 567 | - ( sizeof($this->expected_parameters[$method]) == 0 AND sizeof($this->expected_parameters["ANY"]) != 0 ) ? $this->expected_parameters["ANY"] : $this->expected_parameters[$method] |
|
| 567 | + (sizeof($this->expected_parameters[$method]) == 0 AND sizeof($this->expected_parameters["ANY"]) != 0) ? $this->expected_parameters["ANY"] : $this->expected_parameters[$method] |
|
| 568 | 568 | |
| 569 | 569 | ); |
| 570 | 570 | |
@@ -581,9 +581,9 @@ discard block |
||
| 581 | 581 | |
| 582 | 582 | return array( |
| 583 | 583 | |
| 584 | - ( sizeof($this->liked_attributes[$method]) == 0 AND sizeof($this->liked_attributes["ANY"]) != 0 ) ? $this->liked_attributes["ANY"] : $this->liked_attributes[$method], |
|
| 584 | + (sizeof($this->liked_attributes[$method]) == 0 AND sizeof($this->liked_attributes["ANY"]) != 0) ? $this->liked_attributes["ANY"] : $this->liked_attributes[$method], |
|
| 585 | 585 | |
| 586 | - ( sizeof($this->liked_parameters[$method]) == 0 AND sizeof($this->liked_parameters["ANY"]) != 0 ) ? $this->liked_parameters["ANY"] : $this->liked_parameters[$method] |
|
| 586 | + (sizeof($this->liked_parameters[$method]) == 0 AND sizeof($this->liked_parameters["ANY"]) != 0) ? $this->liked_parameters["ANY"] : $this->liked_parameters[$method] |
|
| 587 | 587 | |
| 588 | 588 | ); |
| 589 | 589 | |
@@ -619,7 +619,7 @@ discard block |
||
| 619 | 619 | */ |
| 620 | 620 | final public function getAttribute($attribute) { |
| 621 | 621 | |
| 622 | - if ( isset($this->attributes[$attribute]) ) return $this->attributes[$attribute]; |
|
| 622 | + if (isset($this->attributes[$attribute])) return $this->attributes[$attribute]; |
|
| 623 | 623 | |
| 624 | 624 | return null; |
| 625 | 625 | |
@@ -650,7 +650,7 @@ discard block |
||
| 650 | 650 | * |
| 651 | 651 | * @return array |
| 652 | 652 | */ |
| 653 | - final public function getParameters($raw=false) { |
|
| 653 | + final public function getParameters($raw = false) { |
|
| 654 | 654 | |
| 655 | 655 | return $raw ? $this->raw_parameters : $this->parameters; |
| 656 | 656 | |
@@ -665,7 +665,7 @@ discard block |
||
| 665 | 665 | */ |
| 666 | 666 | final public function getParameter($parameter) { |
| 667 | 667 | |
| 668 | - if ( isset($this->parameters[$parameter]) ) return $this->parameters[$parameter]; |
|
| 668 | + if (isset($this->parameters[$parameter])) return $this->parameters[$parameter]; |
|
| 669 | 669 | |
| 670 | 670 | return null; |
| 671 | 671 | |
@@ -690,7 +690,7 @@ discard block |
||
| 690 | 690 | */ |
| 691 | 691 | final public function getRequestHeader($header) { |
| 692 | 692 | |
| 693 | - if ( isset($this->request_headers[$header]) ) return $this->request_headers[$header]; |
|
| 693 | + if (isset($this->request_headers[$header])) return $this->request_headers[$header]; |
|
| 694 | 694 | |
| 695 | 695 | return null; |
| 696 | 696 | |
@@ -708,7 +708,7 @@ discard block |
||
| 708 | 708 | |
| 709 | 709 | private function methodsToArray() { |
| 710 | 710 | |
| 711 | - $methods = explode(",",$this->supported_http_methods); |
|
| 711 | + $methods = explode(",", $this->supported_http_methods); |
|
| 712 | 712 | |
| 713 | 713 | $methods_array = array(); |
| 714 | 714 | |
@@ -459,7 +459,9 @@ discard block |
||
| 459 | 459 | */ |
| 460 | 460 | final public function getHeader($header) { |
| 461 | 461 | |
| 462 | - if ( isset($this->headers[$header]) ) return $this->headers[$header]; |
|
| 462 | + if ( isset($this->headers[$header]) ) { |
|
| 463 | + return $this->headers[$header]; |
|
| 464 | + } |
|
| 463 | 465 | |
| 464 | 466 | return null; |
| 465 | 467 | |
@@ -522,7 +524,9 @@ discard block |
||
| 522 | 524 | */ |
| 523 | 525 | final public function getImplementedMethods() { |
| 524 | 526 | |
| 525 | - if ( method_exists($this, 'any') ) return explode(",",$this->supported_http_methods); |
|
| 527 | + if ( method_exists($this, 'any') ) { |
|
| 528 | + return explode(",",$this->supported_http_methods); |
|
| 529 | + } |
|
| 526 | 530 | |
| 527 | 531 | $supported_methods = explode(',',$this->supported_http_methods); |
| 528 | 532 | |
@@ -530,7 +534,9 @@ discard block |
||
| 530 | 534 | |
| 531 | 535 | foreach ( $supported_methods as $method ) { |
| 532 | 536 | |
| 533 | - if ( method_exists($this, strtolower($method)) ) array_push($implemented_methods,$method); |
|
| 537 | + if ( method_exists($this, strtolower($method)) ) { |
|
| 538 | + array_push($implemented_methods,$method); |
|
| 539 | + } |
|
| 534 | 540 | |
| 535 | 541 | } |
| 536 | 542 | |
@@ -545,9 +551,11 @@ discard block |
||
| 545 | 551 | */ |
| 546 | 552 | final public function getCallableMethod($method) { |
| 547 | 553 | |
| 548 | - if ( method_exists($this, strtolower($method)) ) return strtolower($method); |
|
| 549 | - |
|
| 550 | - else return "any"; |
|
| 554 | + if ( method_exists($this, strtolower($method)) ) { |
|
| 555 | + return strtolower($method); |
|
| 556 | + } else { |
|
| 557 | + return "any"; |
|
| 558 | + } |
|
| 551 | 559 | |
| 552 | 560 | } |
| 553 | 561 | |
@@ -619,7 +627,9 @@ discard block |
||
| 619 | 627 | */ |
| 620 | 628 | final public function getAttribute($attribute) { |
| 621 | 629 | |
| 622 | - if ( isset($this->attributes[$attribute]) ) return $this->attributes[$attribute]; |
|
| 630 | + if ( isset($this->attributes[$attribute]) ) { |
|
| 631 | + return $this->attributes[$attribute]; |
|
| 632 | + } |
|
| 623 | 633 | |
| 624 | 634 | return null; |
| 625 | 635 | |
@@ -665,7 +675,9 @@ discard block |
||
| 665 | 675 | */ |
| 666 | 676 | final public function getParameter($parameter) { |
| 667 | 677 | |
| 668 | - if ( isset($this->parameters[$parameter]) ) return $this->parameters[$parameter]; |
|
| 678 | + if ( isset($this->parameters[$parameter]) ) { |
|
| 679 | + return $this->parameters[$parameter]; |
|
| 680 | + } |
|
| 669 | 681 | |
| 670 | 682 | return null; |
| 671 | 683 | |
@@ -690,7 +702,9 @@ discard block |
||
| 690 | 702 | */ |
| 691 | 703 | final public function getRequestHeader($header) { |
| 692 | 704 | |
| 693 | - if ( isset($this->request_headers[$header]) ) return $this->request_headers[$header]; |
|
| 705 | + if ( isset($this->request_headers[$header]) ) { |
|
| 706 | + return $this->request_headers[$header]; |
|
| 707 | + } |
|
| 694 | 708 | |
| 695 | 709 | return null; |
| 696 | 710 | |
@@ -712,7 +726,9 @@ discard block |
||
| 712 | 726 | |
| 713 | 727 | $methods_array = array(); |
| 714 | 728 | |
| 715 | - foreach ($methods as $method) $methods_array[$method] = array(); |
|
| 729 | + foreach ($methods as $method) { |
|
| 730 | + $methods_array[$method] = array(); |
|
| 731 | + } |
|
| 716 | 732 | |
| 717 | 733 | $methods_array['ANY'] = array(); |
| 718 | 734 | |