@@ -186,8 +186,7 @@ discard block |
||
186 | 186 | |
187 | 187 | $this->cache = false; |
188 | 188 | |
189 | - } |
|
190 | - else { |
|
189 | + } else { |
|
191 | 190 | |
192 | 191 | $cache = strtoupper($cache); |
193 | 192 | |
@@ -279,7 +278,9 @@ discard block |
||
279 | 278 | */ |
280 | 279 | public function getHeader($header) { |
281 | 280 | |
282 | - if ( isset($this->headers[$header]) ) return $this->headers[$header]; |
|
281 | + if ( isset($this->headers[$header]) ) { |
|
282 | + return $this->headers[$header]; |
|
283 | + } |
|
283 | 284 | |
284 | 285 | return null; |
285 | 286 | |
@@ -344,9 +345,11 @@ discard block |
||
344 | 345 | */ |
345 | 346 | public function getParameter($parameter) { |
346 | 347 | |
347 | - if ( isset($this->parameters[$parameter]) ) return $this->parameters[$parameter]; |
|
348 | - |
|
349 | - else return null; |
|
348 | + if ( isset($this->parameters[$parameter]) ) { |
|
349 | + return $this->parameters[$parameter]; |
|
350 | + } else { |
|
351 | + return null; |
|
352 | + } |
|
350 | 353 | |
351 | 354 | } |
352 | 355 |
@@ -189,7 +189,9 @@ discard block |
||
189 | 189 | |
190 | 190 | // Before composing the object request, remember to define the current (absolute) dispatcher baseurl |
191 | 191 | // (if not specified in dispatcher-config) |
192 | - if ( !defined("DISPATCHER_BASEURL") ) define("DISPATCHER_BASEURL",$this->urlGetAbsolute($request_service)); |
|
192 | + if ( !defined("DISPATCHER_BASEURL") ) { |
|
193 | + define("DISPATCHER_BASEURL",$this->urlGetAbsolute($request_service)); |
|
194 | + } |
|
193 | 195 | |
194 | 196 | // Now let's compose request object |
195 | 197 | |
@@ -224,22 +226,24 @@ discard block |
||
224 | 226 | |
225 | 227 | if ( strtoupper($type) == "ROUTE" ) { |
226 | 228 | |
227 | - if ( $relative ) $this->routingtable->setRoute($service, $type, DISPATCHER_SERVICES_FOLDER.$target, $parameters); |
|
228 | - |
|
229 | - else $this->routingtable->setRoute($service, $type, $target, $parameters); |
|
230 | - |
|
231 | - } |
|
232 | - |
|
233 | - else if ( strtoupper($type) == "REDIRECT" ) { |
|
229 | + if ( $relative ) { |
|
230 | + $this->routingtable->setRoute($service, $type, DISPATCHER_SERVICES_FOLDER.$target, $parameters); |
|
231 | + } else { |
|
232 | + $this->routingtable->setRoute($service, $type, $target, $parameters); |
|
233 | + } |
|
234 | 234 | |
235 | - if ( $relative ) $this->routingtable->setRoute($service, $type, DISPATCHER_BASEURL.$target, $parameters); |
|
235 | + } else if ( strtoupper($type) == "REDIRECT" ) { |
|
236 | 236 | |
237 | - else $this->routingtable->setRoute($service, $type, $target, $parameters); |
|
237 | + if ( $relative ) { |
|
238 | + $this->routingtable->setRoute($service, $type, DISPATCHER_BASEURL.$target, $parameters); |
|
239 | + } else { |
|
240 | + $this->routingtable->setRoute($service, $type, $target, $parameters); |
|
241 | + } |
|
238 | 242 | |
243 | + } else { |
|
244 | + $this->routingtable->setRoute($service, $type, $target, $parameters); |
|
239 | 245 | } |
240 | 246 | |
241 | - else $this->routingtable->setRoute($service, $type, $target, $parameters); |
|
242 | - |
|
243 | 247 | } catch (Exception $e) { |
244 | 248 | |
245 | 249 | //debug error but do not stop dispatcher |
@@ -380,26 +384,34 @@ discard block |
||
380 | 384 | |
381 | 385 | $fork = $this->events->fire("dispatcher", "DISPATCHER", $this->enabled); |
382 | 386 | |
383 | - if ( is_bool($fork) ) $this->enabled = $fork; |
|
387 | + if ( is_bool($fork) ) { |
|
388 | + $this->enabled = $fork; |
|
389 | + } |
|
384 | 390 | |
385 | 391 | // After building dispatcher instance, fire THE level2 event "dispatcher.request" |
386 | 392 | // This default hook will expose current request (ObjectRequest) to callbacks |
387 | 393 | |
388 | 394 | $fork = $this->events->fire("dispatcher.request", "REQUEST", $this->request); |
389 | 395 | |
390 | - if ( $fork instanceof \Comodojo\Dispatcher\ObjectRequest\ObjectRequest ) $this->request = $fork; |
|
396 | + if ( $fork instanceof \Comodojo\Dispatcher\ObjectRequest\ObjectRequest ) { |
|
397 | + $this->request = $fork; |
|
398 | + } |
|
391 | 399 | |
392 | 400 | // Fire level3 event "dispatcher.request.[method]" |
393 | 401 | |
394 | 402 | $fork = $this->events->fire("dispatcher.request.".$this->request_method, "REQUEST", $this->request); |
395 | 403 | |
396 | - if ( $fork instanceof \Comodojo\Dispatcher\ObjectRequest\ObjectRequest ) $this->request = $fork; |
|
404 | + if ( $fork instanceof \Comodojo\Dispatcher\ObjectRequest\ObjectRequest ) { |
|
405 | + $this->request = $fork; |
|
406 | + } |
|
397 | 407 | |
398 | 408 | // Fire level3 event "dispatcher.request.[service]" |
399 | 409 | |
400 | 410 | $fork = $this->events->fire("dispatcher.request.".$this->request->getService(), "REQUEST", $this->request); |
401 | 411 | |
402 | - if ( $fork instanceof \Comodojo\Dispatcher\ObjectRequest\ObjectRequest ) $this->request = $fork; |
|
412 | + if ( $fork instanceof \Comodojo\Dispatcher\ObjectRequest\ObjectRequest ) { |
|
413 | + $this->request = $fork; |
|
414 | + } |
|
403 | 415 | |
404 | 416 | // Fire special event, it will not modify request |
405 | 417 | |
@@ -426,7 +438,9 @@ discard block |
||
426 | 438 | |
427 | 439 | $fork = $this->events->fire("dispatcher.routingtable", "TABLE", $this->routingtable); |
428 | 440 | |
429 | - if ( $fork instanceof \Comodojo\Dispatcher\ObjectRoutingTable\ObjectRoutingTable ) $this->routingtable = $fork; |
|
441 | + if ( $fork instanceof \Comodojo\Dispatcher\ObjectRoutingTable\ObjectRoutingTable ) { |
|
442 | + $this->routingtable = $fork; |
|
443 | + } |
|
430 | 444 | |
431 | 445 | // Retrieve current route from routing table |
432 | 446 | |
@@ -467,7 +481,9 @@ discard block |
||
467 | 481 | unset($preroute["parameters"]["ttl"]); |
468 | 482 | } |
469 | 483 | if ( isset($preroute["parameters"]["headers"]) ) { |
470 | - if ( is_array($preroute["parameters"]["headers"]) ) foreach ($preroute["parameters"]["headers"] as $header => $value) $this->serviceroute->setHeader($header, $value); |
|
484 | + if ( is_array($preroute["parameters"]["headers"]) ) { |
|
485 | + foreach ($preroute["parameters"]["headers"] as $header => $value) $this->serviceroute->setHeader($header, $value); |
|
486 | + } |
|
471 | 487 | unset($preroute["parameters"]["headers"]); |
472 | 488 | } |
473 | 489 | if ( isset($preroute["parameters"]["accessControl"]) ) { |
@@ -486,15 +502,21 @@ discard block |
||
486 | 502 | |
487 | 503 | $fork = $this->events->fire("dispatcher.serviceroute", "ROUTE", $this->serviceroute); |
488 | 504 | |
489 | - if ( $fork instanceof \Comodojo\Dispatcher\ObjectRoute\ObjectRoute ) $this->serviceroute = $fork; |
|
505 | + if ( $fork instanceof \Comodojo\Dispatcher\ObjectRoute\ObjectRoute ) { |
|
506 | + $this->serviceroute = $fork; |
|
507 | + } |
|
490 | 508 | |
491 | 509 | $fork = $this->events->fire("dispatcher.serviceroute.".$this->serviceroute->getType(), "ROUTE", $this->serviceroute); |
492 | 510 | |
493 | - if ( $fork instanceof \Comodojo\Dispatcher\ObjectRoute\ObjectRoute ) $this->serviceroute = $fork; |
|
511 | + if ( $fork instanceof \Comodojo\Dispatcher\ObjectRoute\ObjectRoute ) { |
|
512 | + $this->serviceroute = $fork; |
|
513 | + } |
|
494 | 514 | |
495 | 515 | $fork = $this->events->fire("dispatcher.serviceroute.".$this->serviceroute->getService(), "ROUTE", $this->serviceroute); |
496 | 516 | |
497 | - if ( $fork instanceof \Comodojo\Dispatcher\ObjectRoute\ObjectRoute ) $this->serviceroute = $fork; |
|
517 | + if ( $fork instanceof \Comodojo\Dispatcher\ObjectRoute\ObjectRoute ) { |
|
518 | + $this->serviceroute = $fork; |
|
519 | + } |
|
498 | 520 | |
499 | 521 | // Fire special event, it will not modify route |
500 | 522 | |
@@ -621,7 +643,9 @@ discard block |
||
621 | 643 | $scr = explode('/', $_SERVER['SCRIPT_NAME']); |
622 | 644 | |
623 | 645 | for($i= 0;$i < sizeof($scr);$i++) { |
624 | - if ($uri[$i] == $scr[$i]) unset($uri[$i]); |
|
646 | + if ($uri[$i] == $scr[$i]) { |
|
647 | + unset($uri[$i]); |
|
648 | + } |
|
625 | 649 | } |
626 | 650 | |
627 | 651 | $service_matrix = array_values($uri); |
@@ -634,16 +658,14 @@ discard block |
||
634 | 658 | |
635 | 659 | $service_attributes = empty($last) ? array_slice($service_matrix, 1, -1) : array_slice($service_matrix, 1); |
636 | 660 | |
637 | - } |
|
638 | - else { |
|
661 | + } else { |
|
639 | 662 | |
640 | 663 | $service_requested = "default"; |
641 | 664 | $service_attributes = Array(); |
642 | 665 | |
643 | 666 | } |
644 | 667 | |
645 | - } |
|
646 | - else { |
|
668 | + } else { |
|
647 | 669 | |
648 | 670 | $service_matrix = $_GET; |
649 | 671 | |
@@ -653,8 +675,7 @@ discard block |
||
653 | 675 | unset($service_matrix["service"]); |
654 | 676 | $service_attributes = $service_matrix; |
655 | 677 | |
656 | - } |
|
657 | - else { |
|
678 | + } else { |
|
658 | 679 | |
659 | 680 | $service_requested = ""; |
660 | 681 | $service_attributes = Array(); |
@@ -698,9 +719,9 @@ discard block |
||
698 | 719 | |
699 | 720 | $http = 'http' . ((isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') ? 's' : '') . '://'; |
700 | 721 | |
701 | - if ( is_null($service) ) $uri = ""; |
|
702 | - |
|
703 | - else { |
|
722 | + if ( is_null($service) ) { |
|
723 | + $uri = ""; |
|
724 | + } else { |
|
704 | 725 | |
705 | 726 | $self = $_SERVER['PHP_SELF']; |
706 | 727 | |
@@ -755,7 +776,9 @@ discard block |
||
755 | 776 | |
756 | 777 | private function attributesMatch($provided, $expected, $liked) { |
757 | 778 | |
758 | - if ( $this->working_mode == "STANDARD" ) return $this->parametersMatch($provided, $expected, $liked); |
|
779 | + if ( $this->working_mode == "STANDARD" ) { |
|
780 | + return $this->parametersMatch($provided, $expected, $liked); |
|
781 | + } |
|
759 | 782 | |
760 | 783 | $attributes = Array(); |
761 | 784 | |
@@ -763,15 +786,13 @@ discard block |
||
763 | 786 | $esize = sizeof($expected); |
764 | 787 | $lsize = sizeof($liked); |
765 | 788 | |
766 | - if ( $psize < $esize ) throw new DispatcherException("Conversation error", 400); |
|
767 | - |
|
768 | - else if ( $psize == $esize ) { |
|
789 | + if ( $psize < $esize ) { |
|
790 | + throw new DispatcherException("Conversation error", 400); |
|
791 | + } else if ( $psize == $esize ) { |
|
769 | 792 | |
770 | 793 | $attributes = $psize == 0 ? array() : array_combine($expected, $provided); |
771 | 794 | |
772 | - } |
|
773 | - |
|
774 | - else { |
|
795 | + } else { |
|
775 | 796 | |
776 | 797 | if ( $esize == 0 ) { |
777 | 798 | |
@@ -797,13 +818,11 @@ discard block |
||
797 | 818 | |
798 | 819 | $l_attributes = array_combine(array_slice($liked, 0, $lvaluessize), $lvalues); |
799 | 820 | |
800 | - } |
|
801 | - else if ( $lvaluessize == $lsize ) { |
|
821 | + } else if ( $lvaluessize == $lsize ) { |
|
802 | 822 | |
803 | 823 | $l_attributes = $lvaluessize == 0 ? array() : array_combine($liked, $lvalues); |
804 | 824 | |
805 | - } |
|
806 | - else { |
|
825 | + } else { |
|
807 | 826 | |
808 | 827 | if ( $lsize == 0 ) { |
809 | 828 | |
@@ -833,7 +852,9 @@ discard block |
||
833 | 852 | |
834 | 853 | foreach ($expected as $parameter) { |
835 | 854 | |
836 | - if ( !isset($provided[$parameter]) ) throw new DispatcherException("Conversation error", 400); |
|
855 | + if ( !isset($provided[$parameter]) ) { |
|
856 | + throw new DispatcherException("Conversation error", 400); |
|
857 | + } |
|
837 | 858 | |
838 | 859 | } |
839 | 860 | |
@@ -873,13 +894,17 @@ discard block |
||
873 | 894 | |
874 | 895 | // If there's no cache for this request, use routing information to find service |
875 | 896 | |
876 | - if ( (include($target)) === false ) throw new DispatcherException("Cannot run service", 500); |
|
897 | + if ( (include($target)) === false ) { |
|
898 | + throw new DispatcherException("Cannot run service", 500); |
|
899 | + } |
|
877 | 900 | |
878 | 901 | // Find a service implementation and try to init it |
879 | 902 | |
880 | 903 | $service_class = $route->getClass(); |
881 | 904 | |
882 | - if ( empty($service_class) ) throw new DispatcherException("Cannot run service", 500); |
|
905 | + if ( empty($service_class) ) { |
|
906 | + throw new DispatcherException("Cannot run service", 500); |
|
907 | + } |
|
883 | 908 | |
884 | 909 | $service_class = "\\Comodojo\\Dispatcher\\Service\\".$service_class; |
885 | 910 | |
@@ -1006,13 +1031,17 @@ discard block |
||
1006 | 1031 | |
1007 | 1032 | $fork = $this->events->fire("dispatcher.result", "RESULT", $route); |
1008 | 1033 | |
1009 | - if ( $fork instanceof \Comodojo\Dispatcher\ObjectResult\ObjectResultInterface ) $route = $fork; |
|
1034 | + if ( $fork instanceof \Comodojo\Dispatcher\ObjectResult\ObjectResultInterface ) { |
|
1035 | + $route = $fork; |
|
1036 | + } |
|
1010 | 1037 | |
1011 | 1038 | // Fire second hook (level2), as specified above |
1012 | 1039 | |
1013 | 1040 | $fork = $this->events->fire($hook, "RESULT", $route); |
1014 | 1041 | |
1015 | - if ( $fork instanceof \Comodojo\Dispatcher\ObjectResult\ObjectResultInterface ) $route = $fork; |
|
1042 | + if ( $fork instanceof \Comodojo\Dispatcher\ObjectResult\ObjectResultInterface ) { |
|
1043 | + $route = $fork; |
|
1044 | + } |
|
1016 | 1045 | |
1017 | 1046 | // Now select and fire last hook (level3) |
1018 | 1047 | // This means that event engine will fire something like "dispatcher.route.200" |
@@ -1020,13 +1049,17 @@ discard block |
||
1020 | 1049 | |
1021 | 1050 | $fork = $this->events->fire($hook.".".$route->getStatusCode(), "RESULT", $route); |
1022 | 1051 | |
1023 | - if ( $fork instanceof \Comodojo\Dispatcher\ObjectResult\ObjectResultInterface ) $route = $fork; |
|
1052 | + if ( $fork instanceof \Comodojo\Dispatcher\ObjectResult\ObjectResultInterface ) { |
|
1053 | + $route = $fork; |
|
1054 | + } |
|
1024 | 1055 | |
1025 | 1056 | // Fire special event, it may modify result |
1026 | 1057 | |
1027 | 1058 | $fork = $this->events->fire("dispatcher.result.#", "RESULT", $route); |
1028 | 1059 | |
1029 | - if ( $fork instanceof \Comodojo\Dispatcher\ObjectResult\ObjectResultInterface ) $route = $fork; |
|
1060 | + if ( $fork instanceof \Comodojo\Dispatcher\ObjectResult\ObjectResultInterface ) { |
|
1061 | + $route = $fork; |
|
1062 | + } |
|
1030 | 1063 | |
1031 | 1064 | // After hooks: |
1032 | 1065 | // - store cache |
@@ -1048,7 +1081,9 @@ discard block |
||
1048 | 1081 | |
1049 | 1082 | $this->header->free(); |
1050 | 1083 | |
1051 | - if ( $cache == "CLIENT" OR $cache == "BOTH" ) $this->header->setClientCache($this->serviceroute->getTtl()); |
|
1084 | + if ( $cache == "CLIENT" OR $cache == "BOTH" ) { |
|
1085 | + $this->header->setClientCache($this->serviceroute->getTtl()); |
|
1086 | + } |
|
1052 | 1087 | |
1053 | 1088 | $this->header->setContentType($route->getContentType(), $route->getCharset()); |
1054 | 1089 |
@@ -39,7 +39,9 @@ discard block |
||
39 | 39 | */ |
40 | 40 | final public function toJson($data, $flags=null) { |
41 | 41 | |
42 | - if ( !( is_array($data) OR is_object($data) ) ) throw new Exception("Invalid data for JSON serialization"); |
|
42 | + if ( !( is_array($data) OR is_object($data) ) ) { |
|
43 | + throw new Exception("Invalid data for JSON serialization"); |
|
44 | + } |
|
43 | 45 | |
44 | 46 | return json_encode($data, $flags); |
45 | 47 | |
@@ -57,9 +59,13 @@ discard block |
||
57 | 59 | */ |
58 | 60 | final public function toXml($data, $prettify=false) { |
59 | 61 | |
60 | - if ( !( is_array($data) OR is_object($data) ) ) throw new Exception("Invalid data for XML serialization"); |
|
62 | + if ( !( is_array($data) OR is_object($data) ) ) { |
|
63 | + throw new Exception("Invalid data for XML serialization"); |
|
64 | + } |
|
61 | 65 | |
62 | - if ( is_object($data) ) $data = $this->objectToArray($data); |
|
66 | + if ( is_object($data) ) { |
|
67 | + $data = $this->objectToArray($data); |
|
68 | + } |
|
63 | 69 | |
64 | 70 | $xmlEngine = new XML(); |
65 | 71 | |
@@ -103,9 +109,13 @@ discard block |
||
103 | 109 | */ |
104 | 110 | final public function toYaml($data) { |
105 | 111 | |
106 | - if ( !( is_array($data) OR is_object($data) ) ) throw new Exception("Invalid data for XML serialization"); |
|
112 | + if ( !( is_array($data) OR is_object($data) ) ) { |
|
113 | + throw new Exception("Invalid data for XML serialization"); |
|
114 | + } |
|
107 | 115 | |
108 | - if ( is_object($data) ) $data = $this->objectToArray($data); |
|
116 | + if ( is_object($data) ) { |
|
117 | + $data = $this->objectToArray($data); |
|
118 | + } |
|
109 | 119 | |
110 | 120 | return \Spyc::YAMLDump($data); |
111 | 121 | |
@@ -158,7 +168,9 @@ discard block |
||
158 | 168 | |
159 | 169 | foreach($xmlStringArray as $k=>$tag){ |
160 | 170 | |
161 | - if ($tag == "") continue; |
|
171 | + if ($tag == "") { |
|
172 | + continue; |
|
173 | + } |
|
162 | 174 | |
163 | 175 | if ($tag[0]=="<" AND $tag[1] != "/") { |
164 | 176 | |
@@ -203,9 +215,9 @@ discard block |
||
203 | 215 | |
204 | 216 | return $array; |
205 | 217 | |
218 | + } else { |
|
219 | + return $stdObj; |
|
206 | 220 | } |
207 | - |
|
208 | - else return $stdObj; |
|
209 | 221 | |
210 | 222 | } |
211 | 223 |
@@ -95,8 +95,7 @@ discard block |
||
95 | 95 | |
96 | 96 | return false; |
97 | 97 | |
98 | - } |
|
99 | - else { |
|
98 | + } else { |
|
100 | 99 | |
101 | 100 | $this->logger->error('Empty data, nothign to cache'); |
102 | 101 | |
@@ -120,8 +119,7 @@ discard block |
||
120 | 119 | |
121 | 120 | if ($this->fail_silently) { |
122 | 121 | return false; |
123 | - } |
|
124 | - else { |
|
122 | + } else { |
|
125 | 123 | throw new IOException("Error writing to cache"); |
126 | 124 | } |
127 | 125 | } |
@@ -176,8 +174,7 @@ discard block |
||
176 | 174 | |
177 | 175 | return false; |
178 | 176 | |
179 | - } |
|
180 | - else { |
|
177 | + } else { |
|
181 | 178 | |
182 | 179 | throw new IOException("Error reading from cache"); |
183 | 180 | |
@@ -191,10 +188,10 @@ discard block |
||
191 | 188 | "object" => $u_data |
192 | 189 | ); |
193 | 190 | |
191 | + } else { |
|
192 | + return false; |
|
194 | 193 | } |
195 | 194 | |
196 | - else return false; |
|
197 | - |
|
198 | 195 | } |
199 | 196 | |
200 | 197 | /** |
@@ -226,17 +223,20 @@ discard block |
||
226 | 223 | while( false !== ( $cache_file = readdir($cache_path) ) ) { |
227 | 224 | |
228 | 225 | if ( pathinfo($cache_file, PATHINFO_EXTENSION) == "cache" ) { |
229 | - if ( unlink( $this->cache_path . ( $this->cache_path[strlen($this->cache_path)-1] == "/" ? "" : "/" ) . $cache_file ) == false ) return false; |
|
230 | - else $cache_files_number++; |
|
226 | + if ( unlink( $this->cache_path . ( $this->cache_path[strlen($this->cache_path)-1] == "/" ? "" : "/" ) . $cache_file ) == false ) { |
|
227 | + return false; |
|
228 | + } else { |
|
229 | + $cache_files_number++; |
|
230 | + } |
|
231 | + } else { |
|
232 | + continue; |
|
231 | 233 | } |
232 | - else continue; |
|
233 | 234 | |
234 | 235 | } |
235 | 236 | |
236 | 237 | closedir($cache_path); |
237 | 238 | |
238 | - } |
|
239 | - else { |
|
239 | + } else { |
|
240 | 240 | |
241 | 241 | $this->logger->info('Purging request cache', array( |
242 | 242 | 'REQUEST' => $request |
@@ -251,8 +251,9 @@ discard block |
||
251 | 251 | $unlink = unlink($cacheFile); |
252 | 252 | $cache_files_number = $unlink ? 1 : false; |
253 | 253 | |
254 | + } else { |
|
255 | + $cache_files_number = 0; |
|
254 | 256 | } |
255 | - else $cache_files_number = 0; |
|
256 | 257 | |
257 | 258 | } |
258 | 259 |
@@ -121,7 +121,9 @@ discard block |
||
121 | 121 | |
122 | 122 | // If service is null, route to landing or (if not specified) to default route |
123 | 123 | |
124 | - if ( empty($service) ) return $this->routeToLanding(); |
|
124 | + if ( empty($service) ) { |
|
125 | + return $this->routeToLanding(); |
|
126 | + } |
|
125 | 127 | |
126 | 128 | // If service is in table, check if it is routable (in case of "ROUTE" route). |
127 | 129 | // If true, route request |
@@ -131,14 +133,16 @@ discard block |
||
131 | 133 | |
132 | 134 | if ( $this->table[$service]["type"] == "ROUTE" ) { |
133 | 135 | |
134 | - if ( $this->routable($this->table[$service]["target"]) ) return $this->table[$service]; |
|
135 | - |
|
136 | - else return $this->routeToNowhere(); |
|
136 | + if ( $this->routable($this->table[$service]["target"]) ) { |
|
137 | + return $this->table[$service]; |
|
138 | + } else { |
|
139 | + return $this->routeToNowhere(); |
|
140 | + } |
|
137 | 141 | |
142 | + } else { |
|
143 | + return $this->table[$service]; |
|
138 | 144 | } |
139 | 145 | |
140 | - else return $this->table[$service]; |
|
141 | - |
|
142 | 146 | } |
143 | 147 | |
144 | 148 | // If autoroute is enabled, try to match service name with a service file. |
@@ -156,7 +160,9 @@ discard block |
||
156 | 160 | |
157 | 161 | // If a route cannot be traced, emit a 404 - not found - response |
158 | 162 | |
159 | - else return $this->routeToNotfound(); |
|
163 | + else { |
|
164 | + return $this->routeToNotfound(); |
|
165 | + } |
|
160 | 166 | |
161 | 167 | } |
162 | 168 | |
@@ -180,9 +186,11 @@ discard block |
||
180 | 186 | */ |
181 | 187 | private function routable($target, $relative=false) { |
182 | 188 | |
183 | - if ( $relative ) return is_readable(DISPATCHER_SERVICES_FOLDER.$target) ? true : false; |
|
184 | - |
|
185 | - else return is_readable($target) ? true : false; |
|
189 | + if ( $relative ) { |
|
190 | + return is_readable(DISPATCHER_SERVICES_FOLDER.$target) ? true : false; |
|
191 | + } else { |
|
192 | + return is_readable($target) ? true : false; |
|
193 | + } |
|
186 | 194 | |
187 | 195 | } |
188 | 196 | |
@@ -197,10 +205,10 @@ discard block |
||
197 | 205 | |
198 | 206 | return $this->table[""]; |
199 | 207 | |
208 | + } else { |
|
209 | + return $this->routeToDefault(); |
|
200 | 210 | } |
201 | 211 | |
202 | - else return $this->routeToDefault(); |
|
203 | - |
|
204 | 212 | } |
205 | 213 | |
206 | 214 | /** |
@@ -214,10 +222,10 @@ discard block |
||
214 | 222 | |
215 | 223 | return $this->table["default"]; |
216 | 224 | |
225 | + } else { |
|
226 | + return $this->routeToNotfound(); |
|
217 | 227 | } |
218 | 228 | |
219 | - else return $this->routeToNotfound(); |
|
220 | - |
|
221 | 229 | } |
222 | 230 | |
223 | 231 | /** |
@@ -165,9 +165,11 @@ discard block |
||
165 | 165 | */ |
166 | 166 | public function setAttribute($name=null, $value) { |
167 | 167 | |
168 | - if ( is_null($name) ) array_push($this->attributes, $value); |
|
169 | - |
|
170 | - else $this->attributes[$name] = $value; |
|
168 | + if ( is_null($name) ) { |
|
169 | + array_push($this->attributes, $value); |
|
170 | + } else { |
|
171 | + $this->attributes[$name] = $value; |
|
172 | + } |
|
171 | 173 | |
172 | 174 | return $this; |
173 | 175 | |
@@ -417,7 +419,9 @@ discard block |
||
417 | 419 | */ |
418 | 420 | public function getHeader($header) { |
419 | 421 | |
420 | - if ( isset($this->headers[$header]) ) return $this->headers[$header]; |
|
422 | + if ( isset($this->headers[$header]) ) { |
|
423 | + return $this->headers[$header]; |
|
424 | + } |
|
421 | 425 | |
422 | 426 | return null; |
423 | 427 |
@@ -77,9 +77,11 @@ discard block |
||
77 | 77 | */ |
78 | 78 | final public function get($header) { |
79 | 79 | |
80 | - if ( array_key_exists($header, $this->headers) ) return $this->headers[$header]; |
|
81 | - |
|
82 | - else return null; |
|
80 | + if ( array_key_exists($header, $this->headers) ) { |
|
81 | + return $this->headers[$header]; |
|
82 | + } else { |
|
83 | + return null; |
|
84 | + } |
|
83 | 85 | |
84 | 86 | } |
85 | 87 | |
@@ -163,10 +165,16 @@ discard block |
||
163 | 165 | |
164 | 166 | case 304: //Not Modified |
165 | 167 | |
166 | - if ( $value === false ) header($_SERVER["SERVER_PROTOCOL"].' 304 Not Modified'); |
|
167 | - else header('Last-Modified: '.gmdate('D, d M Y H:i:s', $value).' GMT', true, 304); |
|
168 | + if ( $value === false ) { |
|
169 | + header($_SERVER["SERVER_PROTOCOL"].' 304 Not Modified'); |
|
170 | + } else { |
|
171 | + header('Last-Modified: '.gmdate('D, d M Y H:i:s', $value).' GMT', true, 304); |
|
172 | + } |
|
168 | 173 | |
169 | - if ($contentLength !== 0) header('Content-Length: '.$contentLength); //is it needed? |
|
174 | + if ($contentLength !== 0) { |
|
175 | + header('Content-Length: '.$contentLength); |
|
176 | + } |
|
177 | + //is it needed? |
|
170 | 178 | |
171 | 179 | $this->processExtraHeaders($this->headers); |
172 | 180 | |
@@ -240,8 +248,7 @@ discard block |
||
240 | 248 | if ( $ttl > 0 ) { |
241 | 249 | $this->set("Cache-Control","max-age=".$ttl.", must-revalidate"); |
242 | 250 | $this->set("Expires",gmdate("D, d M Y H:i:s", (int)$this->current_time + $ttl)." GMT"); |
243 | - } |
|
244 | - else { |
|
251 | + } else { |
|
245 | 252 | $this->set("Cache-Control","no-cache, must-revalidate"); |
246 | 253 | $this->set("Expires","Mon, 26 Jul 1997 05:00:00 GMT"); |
247 | 254 | } |
@@ -260,8 +267,11 @@ discard block |
||
260 | 267 | public function setContentType($type, $charset=null) { |
261 | 268 | |
262 | 269 | |
263 | - if ( is_null($charset) ) $this->set("Content-type",strtolower($type)); |
|
264 | - else $this->set("Content-type",strtolower($type)."; charset=".$charset); |
|
270 | + if ( is_null($charset) ) { |
|
271 | + $this->set("Content-type",strtolower($type)); |
|
272 | + } else { |
|
273 | + $this->set("Content-type",strtolower($type)."; charset=".$charset); |
|
274 | + } |
|
265 | 275 | |
266 | 276 | return $this; |
267 | 277 | |
@@ -276,13 +286,15 @@ discard block |
||
276 | 286 | |
277 | 287 | $headers = ''; |
278 | 288 | |
279 | - if (function_exists('getallheaders')) $headers = getallheaders(); |
|
280 | - |
|
281 | - else { |
|
289 | + if (function_exists('getallheaders')) { |
|
290 | + $headers = getallheaders(); |
|
291 | + } else { |
|
282 | 292 | |
283 | 293 | foreach ($_SERVER as $name => $value) { |
284 | 294 | |
285 | - if (substr($name, 0, 5) == 'HTTP_') $headers[str_replace(' ', '-', ucwords(strtolower(str_replace('_', ' ', substr($name, 5)))))] = $value; |
|
295 | + if (substr($name, 0, 5) == 'HTTP_') { |
|
296 | + $headers[str_replace(' ', '-', ucwords(strtolower(str_replace('_', ' ', substr($name, 5)))))] = $value; |
|
297 | + } |
|
286 | 298 | } |
287 | 299 | |
288 | 300 | } |
@@ -300,8 +312,11 @@ discard block |
||
300 | 312 | |
301 | 313 | foreach ( $headers as $header => $value ) { |
302 | 314 | |
303 | - if ( is_null($value) ) header($header, true); |
|
304 | - else header($header.": ".$value, true); |
|
315 | + if ( is_null($value) ) { |
|
316 | + header($header, true); |
|
317 | + } else { |
|
318 | + header($header.": ".$value, true); |
|
319 | + } |
|
305 | 320 | |
306 | 321 | } |
307 | 322 |
@@ -173,7 +173,9 @@ |
||
173 | 173 | */ |
174 | 174 | public function getHeader($header) { |
175 | 175 | |
176 | - if ( isset($this->headers[$header]) ) return $this->headers[$header]; |
|
176 | + if ( isset($this->headers[$header]) ) { |
|
177 | + return $this->headers[$header]; |
|
178 | + } |
|
177 | 179 | |
178 | 180 | return null; |
179 | 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 |