Completed
Push — master ( 2c1559...dd108d )
by Marco
13:03
created
src/Dispatcher.php 2 patches
Doc Comments   +6 added lines, -3 removed lines patch added patch discarded remove patch
@@ -375,7 +375,7 @@  discard block
 block discarded – undo
375 375
     /**
376 376
      * Dispatcher working method
377 377
      *
378
-     * @return  mixed
378
+     * @return  string
379 379
      */
380 380
     final public function dispatch() {
381 381
 
@@ -696,7 +696,7 @@  discard block
 block discarded – undo
696 696
     /**
697 697
      * Return dispatcher baseurl, no matter the request
698 698
      *
699
-     * @return uri  The baseurl
699
+     * @return string  The baseurl
700 700
      */
701 701
     private function urlGetAbsolute($service=null) {
702 702
 
@@ -845,6 +845,9 @@  discard block
 block discarded – undo
845 845
 
846 846
     }
847 847
 
848
+    /**
849
+     * @return ObjectResultInterface
850
+     */
848 851
     private function runService(ObjectRequest $request, ObjectRoute $route) {
849 852
 
850 853
         $method = $request->getMethod();
@@ -977,7 +980,7 @@  discard block
 block discarded – undo
977 980
     /**
978 981
      * Route request handling ObjectResult hooks
979 982
      *
980
-     * @param   ObjectResult    $route  An implementation of ObjectResultInterface
983
+     * @param   ObjectResultInterface    $route  An implementation of ObjectResultInterface
981 984
      * @return  string                  Content (stuff that will go on screen)
982 985
      */
983 986
     private function route(ObjectResultInterface $route) {
Please login to merge, or discard this patch.
Spacing   +72 added lines, -72 removed lines patch added patch discarded remove patch
@@ -181,19 +181,19 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 
Please login to merge, or discard this patch.
src/XML.php 2 patches
Doc Comments   +6 added lines, -4 removed lines patch added patch discarded remove patch
@@ -116,7 +116,7 @@  discard block
 block discarded – undo
116 116
      *
117 117
      * @param bool $bool
118 118
      *
119
-     * @return Object $this
119
+     * @return XML $this
120 120
      */
121 121
     final public function setIncludeHeader($bool) {
122 122
 
@@ -131,7 +131,7 @@  discard block
 block discarded – undo
131 131
      *
132 132
      * @param int $int
133 133
      *
134
-     * @return Object $this
134
+     * @return XML $this
135 135
      */
136 136
     final public function setCaseFolding($int) {
137 137
 
@@ -146,7 +146,7 @@  discard block
 block discarded – undo
146 146
      *
147 147
      * @param int $int
148 148
      *
149
-     * @return Object $this
149
+     * @return XML $this
150 150
      */
151 151
     final public function setSkipWhite($int) {
152 152
 
@@ -161,7 +161,7 @@  discard block
 block discarded – undo
161 161
      *
162 162
      * @param string $encoding
163 163
      *
164
-     * @return Object $this
164
+     * @return XML $this
165 165
      */
166 166
     final public function setEncoding($encoding) {
167 167
 
@@ -219,6 +219,7 @@  discard block
 block discarded – undo
219 219
     /**
220 220
      * encode XML string into array
221 221
      *
222
+     * @param string $xml
222 223
      * @return array
223 224
      */
224 225
     public function decode($xml, $encoding=null) {
@@ -306,6 +307,7 @@  discard block
 block discarded – undo
306 307
     /**
307 308
      * Get element childs (if any)
308 309
      *
310
+     * @param integer $i
309 311
      * @return array
310 312
      */
311 313
     private function getChilds(&$i) {
Please login to merge, or discard this patch.
Spacing   +19 added lines, -19 removed lines patch added patch discarded remove patch
@@ -202,7 +202,7 @@  discard block
 block discarded – undo
202 202
      */
203 203
     public function encode($data) {
204 204
 
205
-        $structure = ($this->includeHeader ? $this->getHeader() : "") . $this->getParent();
205
+        $structure = ($this->includeHeader ? $this->getHeader() : "").$this->getParent();
206 206
 
207 207
         $this->ObjectXML = new SimpleXMLElement($structure);
208 208
 
@@ -210,7 +210,7 @@  discard block
 block discarded – undo
210 210
 
211 211
         $xml = $this->ObjectXML->asXML();
212 212
 
213
-        if ( $xml === false ) throw new XMLException("Error formatting object");
213
+        if ($xml === false) throw new XMLException("Error formatting object");
214 214
 
215 215
         return $xml;
216 216
 
@@ -221,17 +221,17 @@  discard block
 block discarded – undo
221 221
      *
222 222
      * @return array
223 223
      */
224
-    public function decode($xml, $encoding=null) {
224
+    public function decode($xml, $encoding = null) {
225 225
 
226 226
         $this->parser = is_null($encoding) ? xml_parser_create() : xml_parser_create($encoding);
227 227
 
228
-        xml_parser_set_option($this->parser,XML_OPTION_TARGET_ENCODING,$this->encoding);
229
-        xml_parser_set_option($this->parser,XML_OPTION_CASE_FOLDING,$this->caseFolding);
230
-        xml_parser_set_option($this->parser,XML_OPTION_SKIP_WHITE,$this->skipWhite);
228
+        xml_parser_set_option($this->parser, XML_OPTION_TARGET_ENCODING, $this->encoding);
229
+        xml_parser_set_option($this->parser, XML_OPTION_CASE_FOLDING, $this->caseFolding);
230
+        xml_parser_set_option($this->parser, XML_OPTION_SKIP_WHITE, $this->skipWhite);
231 231
 
232 232
         $parser_structs = xml_parse_into_struct($this->parser, $xml, $this->struct, $index);
233 233
 
234
-        if ( $parser_structs === 0 ) throw new XMLException("Failed to parse xml data into structs");
234
+        if ($parser_structs === 0) throw new XMLException("Failed to parse xml data into structs");
235 235
 
236 236
         $this->counter = count($this->struct);
237 237
 
@@ -251,9 +251,9 @@  discard block
 block discarded – undo
251 251
      */
252 252
     private function sanitizeKeys($input, $key) {
253 253
 
254
-        $key_value = explode("_",$this->struct[$key]["tag"]);
254
+        $key_value = explode("_", $this->struct[$key]["tag"]);
255 255
 
256
-        if ( sizeof($key_value) == 2 AND $key_value[0] == "KEY" AND is_numeric($key_value[1]) ) {
256
+        if (sizeof($key_value) == 2 AND $key_value[0] == "KEY" AND is_numeric($key_value[1])) {
257 257
 
258 258
             $this->struct[$key]["tag"] = intval($key_value[1]);
259 259
 
@@ -266,7 +266,7 @@  discard block
 block discarded – undo
266 266
      */
267 267
     private function free() {
268 268
 
269
-        if( isset($this->parser) AND @is_resource($this->parser) ) {
269
+        if (isset($this->parser) AND @is_resource($this->parser)) {
270 270
 
271 271
             xml_parser_free($this->parser);
272 272
 
@@ -320,7 +320,7 @@  discard block
 block discarded – undo
320 320
 
321 321
             $value = isset($this->struct[$i]["value"]) ? $this->struct[$i]["value"] : "";
322 322
 
323
-            switch($this->struct[$i]["type"]) {
323
+            switch ($this->struct[$i]["type"]) {
324 324
 
325 325
                 case "open":
326 326
                 $child = $this->getChilds($i);
@@ -348,13 +348,13 @@  discard block
 block discarded – undo
348 348
      */
349 349
     private function addNode($target, $key, $attributes, $child, $value) {
350 350
 
351
-        if ( !isset($target[$key]) ) {
351
+        if (!isset($target[$key])) {
352 352
 
353 353
             if ($child != "") $target[$key] = $child;
354 354
 
355
-            if ($attributes != "") foreach($attributes as $akey => $avalue) $target[$key][$akey] = $avalue;
355
+            if ($attributes != "") foreach ($attributes as $akey => $avalue) $target[$key][$akey] = $avalue;
356 356
 
357
-            else if ( $value != "" ) $target[$key] = $value;
357
+            else if ($value != "") $target[$key] = $value;
358 358
 
359 359
         } else {
360 360
 
@@ -363,7 +363,7 @@  discard block
 block discarded – undo
363 363
                 $oldval = $target[$key];
364 364
                 $target[$key] = array();
365 365
                 $target[$key][0] = $oldval;
366
-                $index=1;
366
+                $index = 1;
367 367
 
368 368
             }
369 369
             else {
@@ -372,11 +372,11 @@  discard block
 block discarded – undo
372 372
 
373 373
             }
374 374
 
375
-            if ( $child != "" ) $target[$key][$index] = $child;
375
+            if ($child != "") $target[$key][$index] = $child;
376 376
 
377
-            if ( $attributes != "" ) foreach($attributes as $akey => $avalue) $target[$key][$index][$akey] = $avalue;
377
+            if ($attributes != "") foreach ($attributes as $akey => $avalue) $target[$key][$index][$akey] = $avalue;
378 378
 
379
-            elseif ( $value != "" ) $target[$key][$index] = $value;
379
+            elseif ($value != "") $target[$key][$index] = $value;
380 380
         }
381 381
 
382 382
         return $target;
@@ -393,7 +393,7 @@  discard block
 block discarded – undo
393 393
 
394 394
         foreach ($data as $key => $value) {
395 395
 
396
-            if ( is_array($value) ) $this->pushElement($ObjectXML->addChild(is_numeric($key) ? 'KEY_'.$key : $key), $value);
396
+            if (is_array($value)) $this->pushElement($ObjectXML->addChild(is_numeric($key) ? 'KEY_'.$key : $key), $value);
397 397
 
398 398
             else $ObjectXML->addChild(is_numeric($key) ? 'KEY_'.$key : $key, mb_convert_encoding($value, $this->encoding));
399 399
 
Please login to merge, or discard this patch.