@@ -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 | |
@@ -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 | |