@@ -59,7 +59,7 @@ |
||
| 59 | 59 | * Constructor method. It only acquire current time and notify that cache is ready |
| 60 | 60 | * |
| 61 | 61 | * @param float $time Dispatcher time |
| 62 | - * @param Object $logger Logger, injected by dispatcher |
|
| 62 | + * @param Debug $logger Logger, injected by dispatcher |
|
| 63 | 63 | */ |
| 64 | 64 | final public function __construct($time, $logger) { |
| 65 | 65 | |
@@ -189,7 +189,7 @@ |
||
| 189 | 189 | "bestbefore"=> $best_before, |
| 190 | 190 | //"content" => $u_data["cache_content"] |
| 191 | 191 | "object" => $u_data |
| 192 | - ); |
|
| 192 | + ); |
|
| 193 | 193 | |
| 194 | 194 | } |
| 195 | 195 | |
@@ -105,9 +105,9 @@ discard block |
||
| 105 | 105 | } |
| 106 | 106 | } |
| 107 | 107 | |
| 108 | - $cacheTag = md5($request) . ".cache"; |
|
| 108 | + $cacheTag = md5($request).".cache"; |
|
| 109 | 109 | |
| 110 | - $cacheFile = $this->cache_path . ( $this->cache_path[strlen($this->cache_path)-1] == "/" ? "" : "/" ) . $cacheTag; |
|
| 110 | + $cacheFile = $this->cache_path.($this->cache_path[strlen($this->cache_path)-1] == "/" ? "" : "/").$cacheTag; |
|
| 111 | 111 | |
| 112 | 112 | $f_data = serialize($data); |
| 113 | 113 | |
@@ -138,7 +138,7 @@ discard block |
||
| 138 | 138 | * |
| 139 | 139 | * @return array An array containing maxage, bestbefore, object (data) |
| 140 | 140 | */ |
| 141 | - final public function get($request, $ttl=DISPATCHER_CACHE_TTL) { |
|
| 141 | + final public function get($request, $ttl = DISPATCHER_CACHE_TTL) { |
|
| 142 | 142 | |
| 143 | 143 | if (!DISPATCHER_CACHE_ENABLED) { |
| 144 | 144 | |
@@ -148,19 +148,19 @@ discard block |
||
| 148 | 148 | |
| 149 | 149 | } |
| 150 | 150 | |
| 151 | - $last_time_limit = (int)$this->current_time - $ttl; |
|
| 151 | + $last_time_limit = (int)$this->current_time-$ttl; |
|
| 152 | 152 | |
| 153 | - $cacheTag = md5($request) . ".cache"; |
|
| 153 | + $cacheTag = md5($request).".cache"; |
|
| 154 | 154 | |
| 155 | - $cacheFile = $this->cache_path . ( $this->cache_path[strlen($this->cache_path)-1] == "/" ? "" : "/" ) . $cacheTag; |
|
| 155 | + $cacheFile = $this->cache_path.($this->cache_path[strlen($this->cache_path)-1] == "/" ? "" : "/").$cacheTag; |
|
| 156 | 156 | |
| 157 | 157 | $cache_time = @filemtime($cacheFile); |
| 158 | 158 | |
| 159 | 159 | if (is_readable($cacheFile) AND $cache_time >= $last_time_limit) { |
| 160 | 160 | |
| 161 | - $max_age = $cache_time + $ttl - (int)$this->current_time; |
|
| 161 | + $max_age = $cache_time+$ttl-(int)$this->current_time; |
|
| 162 | 162 | |
| 163 | - $best_before = gmdate("D, d M Y H:i:s", $cache_time + $ttl) . " GMT"; |
|
| 163 | + $best_before = gmdate("D, d M Y H:i:s", $cache_time+$ttl)." GMT"; |
|
| 164 | 164 | |
| 165 | 165 | $data = file_get_contents($cacheFile); |
| 166 | 166 | |
@@ -204,16 +204,16 @@ discard block |
||
| 204 | 204 | * |
| 205 | 205 | * @return bool |
| 206 | 206 | */ |
| 207 | - public function purge($request=null) { |
|
| 207 | + public function purge($request = null) { |
|
| 208 | 208 | |
| 209 | - if ( is_null($request) ) { |
|
| 209 | + if (is_null($request)) { |
|
| 210 | 210 | |
| 211 | 211 | $this->logger->info('Purging whole cache'); |
| 212 | 212 | |
| 213 | 213 | $cache_files_number = 0; |
| 214 | 214 | |
| 215 | 215 | $cache_path = opendir($this->cache_path); |
| 216 | - if ( $cache_path === false ) { |
|
| 216 | + if ($cache_path === false) { |
|
| 217 | 217 | |
| 218 | 218 | $this->logger->error('Unable to open cache folder', array( |
| 219 | 219 | 'CACHEFOLDER' => $this->cache_path |
@@ -223,10 +223,10 @@ discard block |
||
| 223 | 223 | |
| 224 | 224 | } |
| 225 | 225 | |
| 226 | - while( false !== ( $cache_file = readdir($cache_path) ) ) { |
|
| 226 | + while (false !== ($cache_file = readdir($cache_path))) { |
|
| 227 | 227 | |
| 228 | - 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; |
|
| 228 | + 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 | 230 | else $cache_files_number++; |
| 231 | 231 | } |
| 232 | 232 | else continue; |
@@ -242,11 +242,11 @@ discard block |
||
| 242 | 242 | 'REQUEST' => $request |
| 243 | 243 | )); |
| 244 | 244 | |
| 245 | - $cacheTag = md5($request) . ".cache"; |
|
| 245 | + $cacheTag = md5($request).".cache"; |
|
| 246 | 246 | |
| 247 | - $cacheFile = $this->cache_path . ( $this->cache_path[strlen($this->cache_path)-1] == "/" ? "" : "/" ) . $cacheTag; |
|
| 247 | + $cacheFile = $this->cache_path.($this->cache_path[strlen($this->cache_path)-1] == "/" ? "" : "/").$cacheTag; |
|
| 248 | 248 | |
| 249 | - if ( is_readable($cacheFile) ) { |
|
| 249 | + if (is_readable($cacheFile)) { |
|
| 250 | 250 | |
| 251 | 251 | $unlink = unlink($cacheFile); |
| 252 | 252 | $cache_files_number = $unlink ? 1 : false; |
@@ -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 | |
@@ -692,7 +692,7 @@ discard block |
||
| 692 | 692 | /** |
| 693 | 693 | * Return dispatcher baseurl, no matter the request |
| 694 | 694 | * |
| 695 | - * @return uri The baseurl |
|
| 695 | + * @return string The baseurl |
|
| 696 | 696 | */ |
| 697 | 697 | private function urlGetAbsolute($service=null) { |
| 698 | 698 | |
@@ -841,6 +841,9 @@ discard block |
||
| 841 | 841 | |
| 842 | 842 | } |
| 843 | 843 | |
| 844 | + /** |
|
| 845 | + * @return ObjectResultInterface |
|
| 846 | + */ |
|
| 844 | 847 | private function runService(ObjectRequest $request, ObjectRoute $route) { |
| 845 | 848 | |
| 846 | 849 | $method = $request->getMethod(); |
@@ -973,7 +976,7 @@ discard block |
||
| 973 | 976 | /** |
| 974 | 977 | * Route request handling ObjectResult hooks |
| 975 | 978 | * |
| 976 | - * @param ObjectResult $route An implementation of ObjectResultInterface |
|
| 979 | + * @param ObjectResultInterface $route An implementation of ObjectResultInterface |
|
| 977 | 980 | * @return string Content (stuff that will go on screen) |
| 978 | 981 | */ |
| 979 | 982 | private function route(ObjectResultInterface $route) { |
@@ -1068,6 +1071,9 @@ discard block |
||
| 1068 | 1071 | |
| 1069 | 1072 | } |
| 1070 | 1073 | |
| 1074 | + /** |
|
| 1075 | + * @param string $result |
|
| 1076 | + */ |
|
| 1071 | 1077 | private static function end($result) { |
| 1072 | 1078 | |
| 1073 | 1079 | if ( defined('DISPATCHER_PHPUNIT_TEST') && @constant('DISPATCHER_PHPUNIT_TEST') === true ) { |
@@ -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 | |
@@ -47,6 +47,7 @@ discard block |
||
| 47 | 47 | * It does nothing special: called at boot time, only notify that events |
| 48 | 48 | * are ready. |
| 49 | 49 | * |
| 50 | + * @param Debug $logger |
|
| 50 | 51 | * @return null |
| 51 | 52 | */ |
| 52 | 53 | final public function __construct($logger) { |
@@ -66,7 +67,7 @@ discard block |
||
| 66 | 67 | * @param string $callback Callback (or callback class) |
| 67 | 68 | * @param string $method (optional) callback method |
| 68 | 69 | * |
| 69 | - * @return Object $this |
|
| 70 | + * @return Events $this |
|
| 70 | 71 | */ |
| 71 | 72 | final public function add($event, $callback, $method=null) { |
| 72 | 73 | |
@@ -68,11 +68,11 @@ discard block |
||
| 68 | 68 | * |
| 69 | 69 | * @return Object $this |
| 70 | 70 | */ |
| 71 | - final public function add($event, $callback, $method=null) { |
|
| 71 | + final public function add($event, $callback, $method = null) { |
|
| 72 | 72 | |
| 73 | - if ( is_null($method) ) { |
|
| 73 | + if (is_null($method)) { |
|
| 74 | 74 | |
| 75 | - if ( isset($this->hooks[$event]) ) array_push($this->hooks[$event], $callback); |
|
| 75 | + if (isset($this->hooks[$event])) array_push($this->hooks[$event], $callback); |
|
| 76 | 76 | |
| 77 | 77 | else $this->hooks[$event] = Array($callback); |
| 78 | 78 | |
@@ -80,7 +80,7 @@ discard block |
||
| 80 | 80 | |
| 81 | 81 | else { |
| 82 | 82 | |
| 83 | - if ( isset($this->hooks[$event]) ) array_push($this->hooks[$event], Array($callback, $method)); |
|
| 83 | + if (isset($this->hooks[$event])) array_push($this->hooks[$event], Array($callback, $method)); |
|
| 84 | 84 | |
| 85 | 85 | else $this->hooks[$event] = Array(Array($callback, $method)); |
| 86 | 86 | |
@@ -102,9 +102,9 @@ discard block |
||
| 102 | 102 | * |
| 103 | 103 | * @return bool |
| 104 | 104 | */ |
| 105 | - final public function remove($event, $callback=null) { |
|
| 105 | + final public function remove($event, $callback = null) { |
|
| 106 | 106 | |
| 107 | - if ( is_null($callback) AND isset($this->hooks[$event]) ) { |
|
| 107 | + if (is_null($callback) AND isset($this->hooks[$event])) { |
|
| 108 | 108 | |
| 109 | 109 | unset($this->hooks[$event]); |
| 110 | 110 | |
@@ -112,13 +112,13 @@ discard block |
||
| 112 | 112 | |
| 113 | 113 | } |
| 114 | 114 | |
| 115 | - else if ( isset($this->hooks[$event]) ) { |
|
| 115 | + else if (isset($this->hooks[$event])) { |
|
| 116 | 116 | |
| 117 | 117 | foreach ($this->hooks[$event] as $key => $hook) { |
| 118 | 118 | |
| 119 | - if ( is_array($hook) ) { |
|
| 119 | + if (is_array($hook)) { |
|
| 120 | 120 | |
| 121 | - if ( $hook[0] == $callback ) { |
|
| 121 | + if ($hook[0] == $callback) { |
|
| 122 | 122 | |
| 123 | 123 | unset($this->hooks[$event][$key]); |
| 124 | 124 | |
@@ -129,7 +129,7 @@ discard block |
||
| 129 | 129 | } |
| 130 | 130 | else { |
| 131 | 131 | |
| 132 | - if ( $hook == $callback ) { |
|
| 132 | + if ($hook == $callback) { |
|
| 133 | 133 | |
| 134 | 134 | unset($this->hooks[$event][$key]); |
| 135 | 135 | |
@@ -166,15 +166,15 @@ discard block |
||
| 166 | 166 | |
| 167 | 167 | $value = $data; |
| 168 | 168 | |
| 169 | - if ( isset($this->hooks[$event]) ) { |
|
| 169 | + if (isset($this->hooks[$event])) { |
|
| 170 | 170 | |
| 171 | - foreach($this->hooks[$event] as $callback) { |
|
| 171 | + foreach ($this->hooks[$event] as $callback) { |
|
| 172 | 172 | |
| 173 | 173 | $return_value = null; |
| 174 | 174 | |
| 175 | - if ( is_array($callback) ) { |
|
| 175 | + if (is_array($callback)) { |
|
| 176 | 176 | |
| 177 | - if ( is_callable(Array($callback[0], $callback[1])) ) { |
|
| 177 | + if (is_callable(Array($callback[0], $callback[1]))) { |
|
| 178 | 178 | |
| 179 | 179 | try { |
| 180 | 180 | |
@@ -210,7 +210,7 @@ discard block |
||
| 210 | 210 | } |
| 211 | 211 | else { |
| 212 | 212 | |
| 213 | - if ( is_callable($callback) ) { |
|
| 213 | + if (is_callable($callback)) { |
|
| 214 | 214 | |
| 215 | 215 | try { |
| 216 | 216 | |
@@ -72,17 +72,19 @@ discard block |
||
| 72 | 72 | |
| 73 | 73 | if ( is_null($method) ) { |
| 74 | 74 | |
| 75 | - if ( isset($this->hooks[$event]) ) array_push($this->hooks[$event], $callback); |
|
| 76 | - |
|
| 77 | - else $this->hooks[$event] = Array($callback); |
|
| 78 | - |
|
| 79 | - } |
|
| 80 | - |
|
| 81 | - else { |
|
| 75 | + if ( isset($this->hooks[$event]) ) { |
|
| 76 | + array_push($this->hooks[$event], $callback); |
|
| 77 | + } else { |
|
| 78 | + $this->hooks[$event] = Array($callback); |
|
| 79 | + } |
|
| 82 | 80 | |
| 83 | - if ( isset($this->hooks[$event]) ) array_push($this->hooks[$event], Array($callback, $method)); |
|
| 81 | + } else { |
|
| 84 | 82 | |
| 85 | - else $this->hooks[$event] = Array(Array($callback, $method)); |
|
| 83 | + if ( isset($this->hooks[$event]) ) { |
|
| 84 | + array_push($this->hooks[$event], Array($callback, $method)); |
|
| 85 | + } else { |
|
| 86 | + $this->hooks[$event] = Array(Array($callback, $method)); |
|
| 87 | + } |
|
| 86 | 88 | |
| 87 | 89 | } |
| 88 | 90 | |
@@ -110,9 +112,7 @@ discard block |
||
| 110 | 112 | |
| 111 | 113 | return true; |
| 112 | 114 | |
| 113 | - } |
|
| 114 | - |
|
| 115 | - else if ( isset($this->hooks[$event]) ) { |
|
| 115 | + } else if ( isset($this->hooks[$event]) ) { |
|
| 116 | 116 | |
| 117 | 117 | foreach ($this->hooks[$event] as $key => $hook) { |
| 118 | 118 | |
@@ -126,8 +126,7 @@ discard block |
||
| 126 | 126 | |
| 127 | 127 | } |
| 128 | 128 | |
| 129 | - } |
|
| 130 | - else { |
|
| 129 | + } else { |
|
| 131 | 130 | |
| 132 | 131 | if ( $hook == $callback ) { |
| 133 | 132 | |
@@ -143,10 +142,10 @@ discard block |
||
| 143 | 142 | |
| 144 | 143 | return false; |
| 145 | 144 | |
| 145 | + } else { |
|
| 146 | + return false; |
|
| 146 | 147 | } |
| 147 | 148 | |
| 148 | - else return false; |
|
| 149 | - |
|
| 150 | 149 | } |
| 151 | 150 | |
| 152 | 151 | /** |
@@ -194,8 +193,7 @@ discard block |
||
| 194 | 193 | |
| 195 | 194 | } |
| 196 | 195 | |
| 197 | - } |
|
| 198 | - else { |
|
| 196 | + } else { |
|
| 199 | 197 | |
| 200 | 198 | $this->logger->warning('Skipping not-callable hook', array( |
| 201 | 199 | 'EVENT' => $event, |
@@ -207,8 +205,7 @@ discard block |
||
| 207 | 205 | |
| 208 | 206 | } |
| 209 | 207 | |
| 210 | - } |
|
| 211 | - else { |
|
| 208 | + } else { |
|
| 212 | 209 | |
| 213 | 210 | if ( is_callable($callback) ) { |
| 214 | 211 | |
@@ -229,8 +226,7 @@ discard block |
||
| 229 | 226 | |
| 230 | 227 | } |
| 231 | 228 | |
| 232 | - } |
|
| 233 | - else { |
|
| 229 | + } else { |
|
| 234 | 230 | |
| 235 | 231 | $this->logger->warning('Skipping not-callable hook', array( |
| 236 | 232 | 'EVENT' => $event, |
@@ -57,8 +57,8 @@ discard block |
||
| 57 | 57 | * Set $header with a $value. If value is null, only $header will be used |
| 58 | 58 | * |
| 59 | 59 | * @param string $header Header name |
| 60 | - * @param mixed $value Header value (if not included in $header) |
|
| 61 | - * @return Object $this |
|
| 60 | + * @param string $value Header value (if not included in $header) |
|
| 61 | + * @return Header $this |
|
| 62 | 62 | */ |
| 63 | 63 | final public function set($header, $value=null) { |
| 64 | 64 | |
@@ -86,7 +86,7 @@ discard block |
||
| 86 | 86 | /** |
| 87 | 87 | * Free recorded headers (re-init array) |
| 88 | 88 | * |
| 89 | - * @return Object $this |
|
| 89 | + * @return Header $this |
|
| 90 | 90 | */ |
| 91 | 91 | final public function free() { |
| 92 | 92 | |
@@ -231,7 +231,7 @@ discard block |
||
| 231 | 231 | * Shortcut to set client cache headers |
| 232 | 232 | * |
| 233 | 233 | * @param integer $ttl Cache time to live |
| 234 | - * @return Object $this |
|
| 234 | + * @return Header $this |
|
| 235 | 235 | */ |
| 236 | 236 | public function setClientCache($ttl) { |
| 237 | 237 | |
@@ -255,7 +255,7 @@ discard block |
||
| 255 | 255 | * |
| 256 | 256 | * @param string $type Content type |
| 257 | 257 | * @param string $charset Charset |
| 258 | - * @return Object $this |
|
| 258 | + * @return Header $this |
|
| 259 | 259 | */ |
| 260 | 260 | public function setContentType($type, $charset=null) { |
| 261 | 261 | |
@@ -47,7 +47,7 @@ discard block |
||
| 47 | 47 | * |
| 48 | 48 | * @param string $time Dispatcher time |
| 49 | 49 | */ |
| 50 | - final public function __construct($time=false) { |
|
| 50 | + final public function __construct($time = false) { |
|
| 51 | 51 | |
| 52 | 52 | $this->current_time = $time !== false ? $time : microtime(true); |
| 53 | 53 | |
@@ -60,7 +60,7 @@ discard block |
||
| 60 | 60 | * @param mixed $value Header value (if not included in $header) |
| 61 | 61 | * @return Object $this |
| 62 | 62 | */ |
| 63 | - final public function set($header, $value=null) { |
|
| 63 | + final public function set($header, $value = null) { |
|
| 64 | 64 | |
| 65 | 65 | $this->headers[$header] = $value; |
| 66 | 66 | |
@@ -77,7 +77,7 @@ 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]; |
|
| 80 | + if (array_key_exists($header, $this->headers)) return $this->headers[$header]; |
|
| 81 | 81 | |
| 82 | 82 | else return null; |
| 83 | 83 | |
@@ -113,7 +113,7 @@ discard block |
||
| 113 | 113 | * @param integer $contentLength Content length |
| 114 | 114 | * @param string $value (optional) value (see method description) |
| 115 | 115 | */ |
| 116 | - final public function compose($status, $contentLength=0, $value=false) { |
|
| 116 | + final public function compose($status, $contentLength = 0, $value = false) { |
|
| 117 | 117 | |
| 118 | 118 | switch ($status) { |
| 119 | 119 | |
@@ -145,7 +145,7 @@ discard block |
||
| 145 | 145 | |
| 146 | 146 | header($_SERVER["SERVER_PROTOCOL"].' 204 No Content'); |
| 147 | 147 | header('Status: 204 No Content'); |
| 148 | - header('Content-Length: 0',true); |
|
| 148 | + header('Content-Length: 0', true); |
|
| 149 | 149 | |
| 150 | 150 | $this->processExtraHeaders($this->headers); |
| 151 | 151 | |
@@ -157,13 +157,13 @@ discard block |
||
| 157 | 157 | case 303: //See Other |
| 158 | 158 | case 307: //Temporary Redirect |
| 159 | 159 | |
| 160 | - header("Location: ".$value,true,$status); |
|
| 160 | + header("Location: ".$value, true, $status); |
|
| 161 | 161 | |
| 162 | 162 | break; |
| 163 | 163 | |
| 164 | 164 | case 304: //Not Modified |
| 165 | 165 | |
| 166 | - if ( $value === false ) header($_SERVER["SERVER_PROTOCOL"].' 304 Not Modified'); |
|
| 166 | + if ($value === false) header($_SERVER["SERVER_PROTOCOL"].' 304 Not Modified'); |
|
| 167 | 167 | else header('Last-Modified: '.gmdate('D, d M Y H:i:s', $value).' GMT', true, 304); |
| 168 | 168 | |
| 169 | 169 | if ($contentLength !== 0) header('Content-Length: '.$contentLength); //is it needed? |
@@ -197,7 +197,7 @@ discard block |
||
| 197 | 197 | |
| 198 | 198 | case 405: //Not allowed |
| 199 | 199 | |
| 200 | - header('Allow: ' . $value, true, 405); |
|
| 200 | + header('Allow: '.$value, true, 405); |
|
| 201 | 201 | |
| 202 | 202 | break; |
| 203 | 203 | |
@@ -209,7 +209,7 @@ discard block |
||
| 209 | 209 | |
| 210 | 210 | case 501: //Not implemented |
| 211 | 211 | |
| 212 | - header('Allow: ' . $value, true, 501); |
|
| 212 | + header('Allow: '.$value, true, 501); |
|
| 213 | 213 | |
| 214 | 214 | break; |
| 215 | 215 | |
@@ -217,7 +217,7 @@ discard block |
||
| 217 | 217 | |
| 218 | 218 | header('HTTP/1.1 503 Service Temporarily Unavailable'); |
| 219 | 219 | header('Status: 503 Service Temporarily Unavailable'); |
| 220 | - if ( $value !== false AND @is_int($value) ) { |
|
| 220 | + if ($value !== false AND @is_int($value)) { |
|
| 221 | 221 | header('Retry-After: '.$value); |
| 222 | 222 | } |
| 223 | 223 | |
@@ -237,13 +237,13 @@ discard block |
||
| 237 | 237 | |
| 238 | 238 | $ttl = filter_var($ttl, FILTER_VALIDATE_INT); |
| 239 | 239 | |
| 240 | - if ( $ttl > 0 ) { |
|
| 241 | - $this->set("Cache-Control","max-age=".$ttl.", must-revalidate"); |
|
| 242 | - $this->set("Expires",gmdate("D, d M Y H:i:s", (int)$this->current_time + $ttl)." GMT"); |
|
| 240 | + if ($ttl > 0) { |
|
| 241 | + $this->set("Cache-Control", "max-age=".$ttl.", must-revalidate"); |
|
| 242 | + $this->set("Expires", gmdate("D, d M Y H:i:s", (int)$this->current_time+$ttl)." GMT"); |
|
| 243 | 243 | } |
| 244 | 244 | else { |
| 245 | - $this->set("Cache-Control","no-cache, must-revalidate"); |
|
| 246 | - $this->set("Expires","Mon, 26 Jul 1997 05:00:00 GMT"); |
|
| 245 | + $this->set("Cache-Control", "no-cache, must-revalidate"); |
|
| 246 | + $this->set("Expires", "Mon, 26 Jul 1997 05:00:00 GMT"); |
|
| 247 | 247 | } |
| 248 | 248 | |
| 249 | 249 | return $this; |
@@ -257,11 +257,11 @@ discard block |
||
| 257 | 257 | * @param string $charset Charset |
| 258 | 258 | * @return Object $this |
| 259 | 259 | */ |
| 260 | - public function setContentType($type, $charset=null) { |
|
| 260 | + public function setContentType($type, $charset = null) { |
|
| 261 | 261 | |
| 262 | 262 | |
| 263 | - if ( is_null($charset) ) $this->set("Content-type",strtolower($type)); |
|
| 264 | - else $this->set("Content-type",strtolower($type)."; charset=".$charset); |
|
| 263 | + if (is_null($charset)) $this->set("Content-type", strtolower($type)); |
|
| 264 | + else $this->set("Content-type", strtolower($type)."; charset=".$charset); |
|
| 265 | 265 | |
| 266 | 266 | return $this; |
| 267 | 267 | |
@@ -298,9 +298,9 @@ discard block |
||
| 298 | 298 | */ |
| 299 | 299 | private function processExtraHeaders($headers) { |
| 300 | 300 | |
| 301 | - foreach ( $headers as $header => $value ) { |
|
| 301 | + foreach ($headers as $header => $value) { |
|
| 302 | 302 | |
| 303 | - if ( is_null($value) ) header($header, true); |
|
| 303 | + if (is_null($value)) header($header, true); |
|
| 304 | 304 | else header($header.": ".$value, true); |
| 305 | 305 | |
| 306 | 306 | } |
@@ -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 | |
@@ -60,7 +60,7 @@ discard block |
||
| 60 | 60 | * |
| 61 | 61 | * @param string $service The service name |
| 62 | 62 | * |
| 63 | - * @return Object $this |
|
| 63 | + * @return ObjectRoute $this |
|
| 64 | 64 | */ |
| 65 | 65 | public function setService($service) { |
| 66 | 66 | |
@@ -85,7 +85,7 @@ discard block |
||
| 85 | 85 | * |
| 86 | 86 | * @param string $type |
| 87 | 87 | * |
| 88 | - * @return Object $this |
|
| 88 | + * @return ObjectRoute $this |
|
| 89 | 89 | */ |
| 90 | 90 | public function setType($type) { |
| 91 | 91 | |
@@ -113,7 +113,7 @@ discard block |
||
| 113 | 113 | * |
| 114 | 114 | * @param string $target |
| 115 | 115 | * |
| 116 | - * @return Object $this |
|
| 116 | + * @return ObjectRoute $this |
|
| 117 | 117 | */ |
| 118 | 118 | public function setTarget($target) { |
| 119 | 119 | |
@@ -239,7 +239,7 @@ discard block |
||
| 239 | 239 | * @param string $header Header name |
| 240 | 240 | * @param string $value Header content (optional) |
| 241 | 241 | * |
| 242 | - * @return ObjectRequest $this |
|
| 242 | + * @return ObjectRoute $this |
|
| 243 | 243 | */ |
| 244 | 244 | public function setHeader($header, $value=null) { |
| 245 | 245 | |
@@ -290,7 +290,7 @@ discard block |
||
| 290 | 290 | * |
| 291 | 291 | * @param array $headers Headers array |
| 292 | 292 | * |
| 293 | - * @return ObjectRequest $this |
|
| 293 | + * @return ObjectRoute $this |
|
| 294 | 294 | */ |
| 295 | 295 | public function setHeaders($headers) { |
| 296 | 296 | |
@@ -303,7 +303,7 @@ discard block |
||
| 303 | 303 | /** |
| 304 | 304 | * Unset headers |
| 305 | 305 | * |
| 306 | - * @return ObjectRequest $this |
|
| 306 | + * @return ObjectRoute $this |
|
| 307 | 307 | */ |
| 308 | 308 | public function unsetHeaders() { |
| 309 | 309 | |
@@ -327,7 +327,7 @@ discard block |
||
| 327 | 327 | /** |
| 328 | 328 | * Set extra parameter |
| 329 | 329 | * |
| 330 | - * @return ObjectRequest $this |
|
| 330 | + * @return ObjectRoute $this |
|
| 331 | 331 | */ |
| 332 | 332 | public function setParameter($parameter, $value=null) { |
| 333 | 333 | |
@@ -47,13 +47,13 @@ discard block |
||
| 47 | 47 | |
| 48 | 48 | private $parameters = array(); |
| 49 | 49 | |
| 50 | - private $supported_route_types = array("ROUTE","REDIRECT","ERROR"); |
|
| 50 | + private $supported_route_types = array("ROUTE", "REDIRECT", "ERROR"); |
|
| 51 | 51 | |
| 52 | - private $supported_redirect_codes = array(201,301,302,303,307); |
|
| 52 | + private $supported_redirect_codes = array(201, 301, 302, 303, 307); |
|
| 53 | 53 | |
| 54 | - private $supported_error_codes = array(400,403,404,405,500,501,503); |
|
| 54 | + private $supported_error_codes = array(400, 403, 404, 405, 500, 501, 503); |
|
| 55 | 55 | |
| 56 | - private $supported_cache_modes = array("SERVER","CLIENT","BOTH"); |
|
| 56 | + private $supported_cache_modes = array("SERVER", "CLIENT", "BOTH"); |
|
| 57 | 57 | |
| 58 | 58 | /** |
| 59 | 59 | * Set service name |
@@ -241,7 +241,7 @@ discard block |
||
| 241 | 241 | * |
| 242 | 242 | * @return ObjectRequest $this |
| 243 | 243 | */ |
| 244 | - public function setHeader($header, $value=null) { |
|
| 244 | + public function setHeader($header, $value = null) { |
|
| 245 | 245 | |
| 246 | 246 | $this->headers[$header] = $value; |
| 247 | 247 | |
@@ -258,7 +258,7 @@ discard block |
||
| 258 | 258 | */ |
| 259 | 259 | public function unsetHeader($header) { |
| 260 | 260 | |
| 261 | - if ( isset($this->headers[$header]) ) { |
|
| 261 | + if (isset($this->headers[$header])) { |
|
| 262 | 262 | |
| 263 | 263 | unset($this->headers[$header]); |
| 264 | 264 | |
@@ -279,7 +279,7 @@ discard block |
||
| 279 | 279 | */ |
| 280 | 280 | public function getHeader($header) { |
| 281 | 281 | |
| 282 | - if ( isset($this->headers[$header]) ) return $this->headers[$header]; |
|
| 282 | + if (isset($this->headers[$header])) return $this->headers[$header]; |
|
| 283 | 283 | |
| 284 | 284 | return null; |
| 285 | 285 | |
@@ -329,7 +329,7 @@ discard block |
||
| 329 | 329 | * |
| 330 | 330 | * @return ObjectRequest $this |
| 331 | 331 | */ |
| 332 | - public function setParameter($parameter, $value=null) { |
|
| 332 | + public function setParameter($parameter, $value = null) { |
|
| 333 | 333 | |
| 334 | 334 | $this->parameters[$parameter] = $value; |
| 335 | 335 | |
@@ -344,7 +344,7 @@ discard block |
||
| 344 | 344 | */ |
| 345 | 345 | public function getParameter($parameter) { |
| 346 | 346 | |
| 347 | - if ( isset($this->parameters[$parameter]) ) return $this->parameters[$parameter]; |
|
| 347 | + if (isset($this->parameters[$parameter])) return $this->parameters[$parameter]; |
|
| 348 | 348 | |
| 349 | 349 | else return null; |
| 350 | 350 | |
@@ -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 | |
@@ -260,7 +260,7 @@ discard block |
||
| 260 | 260 | * @param array $attributes array og attributes that service expects |
| 261 | 261 | * @param array $parameters array of parameters that service expects |
| 262 | 262 | * |
| 263 | - * @return Object $this |
|
| 263 | + * @return Service $this |
|
| 264 | 264 | */ |
| 265 | 265 | final public function expects($method, $attributes, $parameters=array()) { |
| 266 | 266 | |
@@ -280,7 +280,7 @@ discard block |
||
| 280 | 280 | * @param array $attributes array og attributes that service likes |
| 281 | 281 | * @param array $parameters array of parameters that service likes |
| 282 | 282 | * |
| 283 | - * @return Object $this |
|
| 283 | + * @return Service $this |
|
| 284 | 284 | */ |
| 285 | 285 | final public function likes($method, $attributes, $parameters=array()) { |
| 286 | 286 | |
@@ -306,7 +306,7 @@ discard block |
||
| 306 | 306 | * |
| 307 | 307 | * @param string $methods HTTP methods, comma separated |
| 308 | 308 | * |
| 309 | - * @return Object $this |
|
| 309 | + * @return Service $this |
|
| 310 | 310 | */ |
| 311 | 311 | final public function setSupportedMethods($methods) { |
| 312 | 312 | |
@@ -331,7 +331,7 @@ discard block |
||
| 331 | 331 | * Set service content type |
| 332 | 332 | * |
| 333 | 333 | * @param string $type Content Type |
| 334 | - * @return Object $this |
|
| 334 | + * @return Service $this |
|
| 335 | 335 | */ |
| 336 | 336 | final public function setContentType($type) { |
| 337 | 337 | |
@@ -357,7 +357,7 @@ discard block |
||
| 357 | 357 | * |
| 358 | 358 | * @param string $charset Charset |
| 359 | 359 | * |
| 360 | - * @return Object $this |
|
| 360 | + * @return Service $this |
|
| 361 | 361 | */ |
| 362 | 362 | final public function setCharset($charset) { |
| 363 | 363 | |
@@ -382,7 +382,7 @@ discard block |
||
| 382 | 382 | * Set success status code |
| 383 | 383 | * |
| 384 | 384 | * @param integer $code HTTP status code (in case of success) |
| 385 | - * @return Object $this |
|
| 385 | + * @return Service $this |
|
| 386 | 386 | */ |
| 387 | 387 | final public function setStatusCode($code) { |
| 388 | 388 | |
@@ -433,7 +433,7 @@ discard block |
||
| 433 | 433 | * @param string $header Header name |
| 434 | 434 | * @param string $value Header content (optional) |
| 435 | 435 | * |
| 436 | - * @return Object $this |
|
| 436 | + * @return Service $this |
|
| 437 | 437 | */ |
| 438 | 438 | final public function setHeader($header, $value=null) { |
| 439 | 439 | |
@@ -484,7 +484,7 @@ discard block |
||
| 484 | 484 | * |
| 485 | 485 | * @param array $headers Headers array |
| 486 | 486 | * |
| 487 | - * @return Object $this |
|
| 487 | + * @return Service $this |
|
| 488 | 488 | */ |
| 489 | 489 | final public function setHeaders($headers) { |
| 490 | 490 | |
@@ -497,7 +497,7 @@ discard block |
||
| 497 | 497 | /** |
| 498 | 498 | * Unset headers |
| 499 | 499 | * |
| 500 | - * @return Object $this |
|
| 500 | + * @return Service $this |
|
| 501 | 501 | */ |
| 502 | 502 | final public function unsetHeaders() { |
| 503 | 503 | |
@@ -521,7 +521,7 @@ discard block |
||
| 521 | 521 | /** |
| 522 | 522 | * Get service-supported HTTP methods |
| 523 | 523 | * |
| 524 | - * @return array Headers array |
|
| 524 | + * @return string Headers array |
|
| 525 | 525 | */ |
| 526 | 526 | final public function getSupportedMethods() { |
| 527 | 527 | |
@@ -555,7 +555,7 @@ discard block |
||
| 555 | 555 | /** |
| 556 | 556 | * Return the callable class method that reflect the requested one |
| 557 | 557 | * |
| 558 | - * @return array Headers array |
|
| 558 | + * @return string Headers array |
|
| 559 | 559 | */ |
| 560 | 560 | final public function getCallableMethod($method) { |
| 561 | 561 | |
@@ -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 | |
@@ -116,7 +116,7 @@ discard block |
||
| 116 | 116 | * |
| 117 | 117 | * @param bool $bool |
| 118 | 118 | * |
| 119 | - * @return Object $this |
|
| 119 | + * @return XML $this |
|
| 120 | 120 | */ |
| 121 | 121 | final public function setIncludeHeader($bool) { |
| 122 | 122 | |
@@ -131,7 +131,7 @@ discard block |
||
| 131 | 131 | * |
| 132 | 132 | * @param int $int |
| 133 | 133 | * |
| 134 | - * @return Object $this |
|
| 134 | + * @return XML $this |
|
| 135 | 135 | */ |
| 136 | 136 | final public function setCaseFolding($int) { |
| 137 | 137 | |
@@ -146,7 +146,7 @@ discard block |
||
| 146 | 146 | * |
| 147 | 147 | * @param int $int |
| 148 | 148 | * |
| 149 | - * @return Object $this |
|
| 149 | + * @return XML $this |
|
| 150 | 150 | */ |
| 151 | 151 | final public function setSkipWhite($int) { |
| 152 | 152 | |
@@ -161,7 +161,7 @@ discard block |
||
| 161 | 161 | * |
| 162 | 162 | * @param string $encoding |
| 163 | 163 | * |
| 164 | - * @return Object $this |
|
| 164 | + * @return XML $this |
|
| 165 | 165 | */ |
| 166 | 166 | final public function setEncoding($encoding) { |
| 167 | 167 | |
@@ -306,6 +306,7 @@ discard block |
||
| 306 | 306 | /** |
| 307 | 307 | * Get element childs (if any) |
| 308 | 308 | * |
| 309 | + * @param integer $i |
|
| 309 | 310 | * @return array |
| 310 | 311 | */ |
| 311 | 312 | private function getChilds(&$i) { |
@@ -202,7 +202,7 @@ discard block |
||
| 202 | 202 | */ |
| 203 | 203 | public function encode(array $data) { |
| 204 | 204 | |
| 205 | - $structure = ($this->includeHeader ? $this->getHeader() : "") . $this->getParent(); |
|
| 205 | + $structure = ($this->includeHeader ? $this->getHeader() : "").$this->getParent(); |
|
| 206 | 206 | |
| 207 | 207 | $this->ObjectXML = new SimpleXMLElement($structure); |
| 208 | 208 | |
@@ -210,7 +210,7 @@ discard block |
||
| 210 | 210 | |
| 211 | 211 | $xml = $this->ObjectXML->asXML(); |
| 212 | 212 | |
| 213 | - if ( $xml === false ) throw new XMLException("Error formatting object"); |
|
| 213 | + if ($xml === false) throw new XMLException("Error formatting object"); |
|
| 214 | 214 | |
| 215 | 215 | return $xml; |
| 216 | 216 | |
@@ -221,17 +221,17 @@ discard block |
||
| 221 | 221 | * |
| 222 | 222 | * @return array |
| 223 | 223 | */ |
| 224 | - public function decode(string $xml, $encoding=null) { |
|
| 224 | + public function decode(string $xml, $encoding = null) { |
|
| 225 | 225 | |
| 226 | 226 | $this->parser = is_null($encoding) ? xml_parser_create() : xml_parser_create($encoding); |
| 227 | 227 | |
| 228 | - xml_parser_set_option($this->parser,XML_OPTION_TARGET_ENCODING,$this->encoding); |
|
| 229 | - xml_parser_set_option($this->parser,XML_OPTION_CASE_FOLDING,$this->caseFolding); |
|
| 230 | - xml_parser_set_option($this->parser,XML_OPTION_SKIP_WHITE,$this->skipWhite); |
|
| 228 | + xml_parser_set_option($this->parser, XML_OPTION_TARGET_ENCODING, $this->encoding); |
|
| 229 | + xml_parser_set_option($this->parser, XML_OPTION_CASE_FOLDING, $this->caseFolding); |
|
| 230 | + xml_parser_set_option($this->parser, XML_OPTION_SKIP_WHITE, $this->skipWhite); |
|
| 231 | 231 | |
| 232 | 232 | $parser_structs = xml_parse_into_struct($this->parser, $xml, $this->struct, $index); |
| 233 | 233 | |
| 234 | - if ( $parser_structs === 0 ) throw new XMLException("Failed to parse xml data into structs"); |
|
| 234 | + if ($parser_structs === 0) throw new XMLException("Failed to parse xml data into structs"); |
|
| 235 | 235 | |
| 236 | 236 | $this->counter = count($this->struct); |
| 237 | 237 | |
@@ -251,9 +251,9 @@ discard block |
||
| 251 | 251 | */ |
| 252 | 252 | private function sanitizeKeys($input, $key) { |
| 253 | 253 | |
| 254 | - $key_value = explode("_",$this->struct[$key]["tag"]); |
|
| 254 | + $key_value = explode("_", $this->struct[$key]["tag"]); |
|
| 255 | 255 | |
| 256 | - if ( sizeof($key_value) == 2 AND $key_value[0] == "KEY" AND is_numeric($key_value[1]) ) { |
|
| 256 | + if (sizeof($key_value) == 2 AND $key_value[0] == "KEY" AND is_numeric($key_value[1])) { |
|
| 257 | 257 | |
| 258 | 258 | $this->struct[$key]["tag"] = intval($key_value[1]); |
| 259 | 259 | |
@@ -266,7 +266,7 @@ discard block |
||
| 266 | 266 | */ |
| 267 | 267 | private function free() { |
| 268 | 268 | |
| 269 | - if( isset($this->parser) AND @is_resource($this->parser) ) { |
|
| 269 | + if (isset($this->parser) AND @is_resource($this->parser)) { |
|
| 270 | 270 | |
| 271 | 271 | xml_parser_free($this->parser); |
| 272 | 272 | |
@@ -320,7 +320,7 @@ discard block |
||
| 320 | 320 | |
| 321 | 321 | $value = isset($this->struct[$i]["value"]) ? $this->struct[$i]["value"] : ""; |
| 322 | 322 | |
| 323 | - switch($this->struct[$i]["type"]) { |
|
| 323 | + switch ($this->struct[$i]["type"]) { |
|
| 324 | 324 | |
| 325 | 325 | case "open": |
| 326 | 326 | $child = $this->getChilds($i); |
@@ -348,13 +348,13 @@ discard block |
||
| 348 | 348 | */ |
| 349 | 349 | private function addNode($target, $key, $attributes, $child, $value) { |
| 350 | 350 | |
| 351 | - if ( !isset($target[$key]) ) { |
|
| 351 | + if (!isset($target[$key])) { |
|
| 352 | 352 | |
| 353 | 353 | if ($child != "") $target[$key] = $child; |
| 354 | 354 | |
| 355 | - if ($attributes != "") foreach($attributes as $akey => $avalue) $target[$key][$akey] = $avalue; |
|
| 355 | + if ($attributes != "") foreach ($attributes as $akey => $avalue) $target[$key][$akey] = $avalue; |
|
| 356 | 356 | |
| 357 | - else if ( $value != "" ) $target[$key] = $value; |
|
| 357 | + else if ($value != "") $target[$key] = $value; |
|
| 358 | 358 | |
| 359 | 359 | } else { |
| 360 | 360 | |
@@ -363,7 +363,7 @@ discard block |
||
| 363 | 363 | $oldval = $target[$key]; |
| 364 | 364 | $target[$key] = array(); |
| 365 | 365 | $target[$key][0] = $oldval; |
| 366 | - $index=1; |
|
| 366 | + $index = 1; |
|
| 367 | 367 | |
| 368 | 368 | } |
| 369 | 369 | else { |
@@ -372,11 +372,11 @@ discard block |
||
| 372 | 372 | |
| 373 | 373 | } |
| 374 | 374 | |
| 375 | - if ( $child != "" ) $target[$key][$index] = $child; |
|
| 375 | + if ($child != "") $target[$key][$index] = $child; |
|
| 376 | 376 | |
| 377 | - if ( $attributes != "" ) foreach($attributes as $akey => $avalue) $target[$key][$index][$akey] = $avalue; |
|
| 377 | + if ($attributes != "") foreach ($attributes as $akey => $avalue) $target[$key][$index][$akey] = $avalue; |
|
| 378 | 378 | |
| 379 | - elseif ( $value != "" ) $target[$key][$index] = $value; |
|
| 379 | + elseif ($value != "") $target[$key][$index] = $value; |
|
| 380 | 380 | } |
| 381 | 381 | |
| 382 | 382 | return $target; |
@@ -393,7 +393,7 @@ discard block |
||
| 393 | 393 | |
| 394 | 394 | foreach ($data as $key => $value) { |
| 395 | 395 | |
| 396 | - if ( is_array($value) ) $this->pushElement($ObjectXML->addChild(is_numeric($key) ? 'KEY_'.$key : $key), $value); |
|
| 396 | + if (is_array($value)) $this->pushElement($ObjectXML->addChild(is_numeric($key) ? 'KEY_'.$key : $key), $value); |
|
| 397 | 397 | |
| 398 | 398 | else $ObjectXML->addChild(is_numeric($key) ? 'KEY_'.$key : $key, mb_convert_encoding($value, $this->encoding)); |
| 399 | 399 | |
@@ -210,7 +210,9 @@ discard block |
||
| 210 | 210 | |
| 211 | 211 | $xml = $this->ObjectXML->asXML(); |
| 212 | 212 | |
| 213 | - if ( $xml === false ) throw new XMLException("Error formatting object"); |
|
| 213 | + if ( $xml === false ) { |
|
| 214 | + throw new XMLException("Error formatting object"); |
|
| 215 | + } |
|
| 214 | 216 | |
| 215 | 217 | return $xml; |
| 216 | 218 | |
@@ -231,7 +233,9 @@ discard block |
||
| 231 | 233 | |
| 232 | 234 | $parser_structs = xml_parse_into_struct($this->parser, $xml, $this->struct, $index); |
| 233 | 235 | |
| 234 | - if ( $parser_structs === 0 ) throw new XMLException("Failed to parse xml data into structs"); |
|
| 236 | + if ( $parser_structs === 0 ) { |
|
| 237 | + throw new XMLException("Failed to parse xml data into structs"); |
|
| 238 | + } |
|
| 235 | 239 | |
| 236 | 240 | $this->counter = count($this->struct); |
| 237 | 241 | |
@@ -350,11 +354,15 @@ discard block |
||
| 350 | 354 | |
| 351 | 355 | if ( !isset($target[$key]) ) { |
| 352 | 356 | |
| 353 | - if ($child != "") $target[$key] = $child; |
|
| 354 | - |
|
| 355 | - if ($attributes != "") foreach($attributes as $akey => $avalue) $target[$key][$akey] = $avalue; |
|
| 357 | + if ($child != "") { |
|
| 358 | + $target[$key] = $child; |
|
| 359 | + } |
|
| 356 | 360 | |
| 357 | - else if ( $value != "" ) $target[$key] = $value; |
|
| 361 | + if ($attributes != "") { |
|
| 362 | + foreach($attributes as $akey => $avalue) $target[$key][$akey] = $avalue; |
|
| 363 | + } else if ( $value != "" ) { |
|
| 364 | + $target[$key] = $value; |
|
| 365 | + } |
|
| 358 | 366 | |
| 359 | 367 | } else { |
| 360 | 368 | |
@@ -365,18 +373,21 @@ discard block |
||
| 365 | 373 | $target[$key][0] = $oldval; |
| 366 | 374 | $index=1; |
| 367 | 375 | |
| 368 | - } |
|
| 369 | - else { |
|
| 376 | + } else { |
|
| 370 | 377 | |
| 371 | 378 | $index = count($target[$key]); |
| 372 | 379 | |
| 373 | 380 | } |
| 374 | 381 | |
| 375 | - if ( $child != "" ) $target[$key][$index] = $child; |
|
| 376 | - |
|
| 377 | - if ( $attributes != "" ) foreach($attributes as $akey => $avalue) $target[$key][$index][$akey] = $avalue; |
|
| 382 | + if ( $child != "" ) { |
|
| 383 | + $target[$key][$index] = $child; |
|
| 384 | + } |
|
| 378 | 385 | |
| 379 | - elseif ( $value != "" ) $target[$key][$index] = $value; |
|
| 386 | + if ( $attributes != "" ) { |
|
| 387 | + foreach($attributes as $akey => $avalue) $target[$key][$index][$akey] = $avalue; |
|
| 388 | + } elseif ( $value != "" ) { |
|
| 389 | + $target[$key][$index] = $value; |
|
| 390 | + } |
|
| 380 | 391 | } |
| 381 | 392 | |
| 382 | 393 | return $target; |
@@ -393,9 +404,11 @@ discard block |
||
| 393 | 404 | |
| 394 | 405 | foreach ($data as $key => $value) { |
| 395 | 406 | |
| 396 | - if ( is_array($value) ) $this->pushElement($ObjectXML->addChild(is_numeric($key) ? 'KEY_'.$key : $key), $value); |
|
| 397 | - |
|
| 398 | - else $ObjectXML->addChild(is_numeric($key) ? 'KEY_'.$key : $key, mb_convert_encoding($value, $this->encoding)); |
|
| 407 | + if ( is_array($value) ) { |
|
| 408 | + $this->pushElement($ObjectXML->addChild(is_numeric($key) ? 'KEY_'.$key : $key), $value); |
|
| 409 | + } else { |
|
| 410 | + $ObjectXML->addChild(is_numeric($key) ? 'KEY_'.$key : $key, mb_convert_encoding($value, $this->encoding)); |
|
| 411 | + } |
|
| 399 | 412 | |
| 400 | 413 | } |
| 401 | 414 | |
@@ -37,9 +37,9 @@ discard block |
||
| 37 | 37 | * |
| 38 | 38 | * @return string JSON encoded data |
| 39 | 39 | */ |
| 40 | - final public function toJson($data, $flags=null) { |
|
| 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))) throw new Exception("Invalid data for JSON serialization"); |
|
| 43 | 43 | |
| 44 | 44 | return json_encode($data, $flags); |
| 45 | 45 | |
@@ -55,11 +55,11 @@ discard block |
||
| 55 | 55 | * |
| 56 | 56 | * @return string XML encoded data |
| 57 | 57 | */ |
| 58 | - final public function toXml($data, $prettify=false) { |
|
| 58 | + final public function toXml($data, $prettify = false) { |
|
| 59 | 59 | |
| 60 | - if ( !( is_array($data) OR is_object($data) ) ) throw new Exception("Invalid data for XML serialization"); |
|
| 60 | + if (!(is_array($data) OR is_object($data))) throw new Exception("Invalid data for XML serialization"); |
|
| 61 | 61 | |
| 62 | - if ( is_object($data) ) $data = $this->objectToArray($data); |
|
| 62 | + if (is_object($data)) $data = $this->objectToArray($data); |
|
| 63 | 63 | |
| 64 | 64 | $xmlEngine = new XML(); |
| 65 | 65 | |
@@ -103,9 +103,9 @@ discard block |
||
| 103 | 103 | */ |
| 104 | 104 | final public function toYaml($data) { |
| 105 | 105 | |
| 106 | - if ( !( is_array($data) OR is_object($data) ) ) throw new Exception("Invalid data for XML serialization"); |
|
| 106 | + if (!(is_array($data) OR is_object($data))) throw new Exception("Invalid data for XML serialization"); |
|
| 107 | 107 | |
| 108 | - if ( is_object($data) ) $data = $this->objectToArray($data); |
|
| 108 | + if (is_object($data)) $data = $this->objectToArray($data); |
|
| 109 | 109 | |
| 110 | 110 | return \Spyc::YAMLDump($data); |
| 111 | 111 | |
@@ -147,7 +147,7 @@ discard block |
||
| 147 | 147 | |
| 148 | 148 | $indent = ''; |
| 149 | 149 | |
| 150 | - $xmlString = str_replace("\n","",$xmlString); |
|
| 150 | + $xmlString = str_replace("\n", "", $xmlString); |
|
| 151 | 151 | $xmlString = trim(preg_replace("/<\?[^>]+>/", "", $xmlString)); |
| 152 | 152 | $xmlString = preg_replace("/>([\s]+)<\//", "></", $xmlString); |
| 153 | 153 | $xmlString = str_replace(">", ">\n", $xmlString); |
@@ -156,23 +156,23 @@ discard block |
||
| 156 | 156 | |
| 157 | 157 | $_xmlString = ''; |
| 158 | 158 | |
| 159 | - foreach($xmlStringArray as $k=>$tag){ |
|
| 159 | + foreach ($xmlStringArray as $k=>$tag) { |
|
| 160 | 160 | |
| 161 | 161 | if ($tag == "") continue; |
| 162 | 162 | |
| 163 | - if ($tag[0]=="<" AND $tag[1] != "/") { |
|
| 163 | + if ($tag[0] == "<" AND $tag[1] != "/") { |
|
| 164 | 164 | |
| 165 | 165 | $_xmlString .= $indent.$tag."\n"; |
| 166 | 166 | $indent .= ' '; |
| 167 | 167 | |
| 168 | - } elseif($tag[0]=="<" AND $tag[1] == "/") { |
|
| 168 | + } elseif ($tag[0] == "<" AND $tag[1] == "/") { |
|
| 169 | 169 | |
| 170 | - $indent = substr($indent,0,strlen($indent)-2); |
|
| 171 | - $_xmlString .= (substr($_xmlString,strlen($_xmlString)-1)==">" || substr($_xmlString,strlen($_xmlString)-1)=="\n" ? $indent : '').$tag."\n"; |
|
| 170 | + $indent = substr($indent, 0, strlen($indent)-2); |
|
| 171 | + $_xmlString .= (substr($_xmlString, strlen($_xmlString)-1) == ">" || substr($_xmlString, strlen($_xmlString)-1) == "\n" ? $indent : '').$tag."\n"; |
|
| 172 | 172 | |
| 173 | 173 | } else { |
| 174 | 174 | |
| 175 | - $_xmlString = substr($_xmlString,0,strlen($_xmlString)-1); |
|
| 175 | + $_xmlString = substr($_xmlString, 0, strlen($_xmlString)-1); |
|
| 176 | 176 | $_xmlString .= $tag; |
| 177 | 177 | |
| 178 | 178 | } |
@@ -191,11 +191,11 @@ discard block |
||
| 191 | 191 | */ |
| 192 | 192 | private function objectToArray($stdObj) { |
| 193 | 193 | |
| 194 | - if(is_object($stdObj)) { |
|
| 194 | + if (is_object($stdObj)) { |
|
| 195 | 195 | |
| 196 | 196 | $array = array(); |
| 197 | 197 | |
| 198 | - foreach($stdObj as $key=>$val){ |
|
| 198 | + foreach ($stdObj as $key=>$val) { |
|
| 199 | 199 | |
| 200 | 200 | $array[$key] = objectToArray($val); |
| 201 | 201 | |
@@ -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 | |
@@ -48,7 +48,7 @@ discard block |
||
| 48 | 48 | * |
| 49 | 49 | * @var array |
| 50 | 50 | */ |
| 51 | - private $supported_route_types = array("ROUTE","REDIRECT","ERROR"); |
|
| 51 | + private $supported_route_types = array("ROUTE", "REDIRECT", "ERROR"); |
|
| 52 | 52 | |
| 53 | 53 | /** |
| 54 | 54 | * Object constructor. |
@@ -77,7 +77,7 @@ discard block |
||
| 77 | 77 | * |
| 78 | 78 | * @return Object $this |
| 79 | 79 | */ |
| 80 | - public function setRoute($service, $type, $target, $parameters=array()) { |
|
| 80 | + public function setRoute($service, $type, $target, $parameters = array()) { |
|
| 81 | 81 | |
| 82 | 82 | $this->table[$service] = array( |
| 83 | 83 | "type" => $type, |
@@ -98,7 +98,7 @@ discard block |
||
| 98 | 98 | */ |
| 99 | 99 | public function unsetRoute($service) { |
| 100 | 100 | |
| 101 | - if ( isset($this->table[$service]) ) { |
|
| 101 | + if (isset($this->table[$service])) { |
|
| 102 | 102 | |
| 103 | 103 | unset($this->table[$service]); |
| 104 | 104 | |
@@ -121,17 +121,17 @@ 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)) return $this->routeToLanding(); |
|
| 125 | 125 | |
| 126 | 126 | // If service is in table, check if it is routable (in case of "ROUTE" route). |
| 127 | 127 | // If true, route request |
| 128 | 128 | // If false, return a 500 error |
| 129 | 129 | |
| 130 | - if ( isset($this->table[$service]) ) { |
|
| 130 | + if (isset($this->table[$service])) { |
|
| 131 | 131 | |
| 132 | - if ( $this->table[$service]["type"] == "ROUTE" ) { |
|
| 132 | + if ($this->table[$service]["type"] == "ROUTE") { |
|
| 133 | 133 | |
| 134 | - if ( $this->routable($this->table[$service]["target"]) ) return $this->table[$service]; |
|
| 134 | + if ($this->routable($this->table[$service]["target"])) return $this->table[$service]; |
|
| 135 | 135 | |
| 136 | 136 | else return $this->routeToNowhere(); |
| 137 | 137 | |
@@ -144,7 +144,7 @@ discard block |
||
| 144 | 144 | // If autoroute is enabled, try to match service name with a service file. |
| 145 | 145 | // If true, try to route request |
| 146 | 146 | |
| 147 | - else if ( defined('DISPATCHER_AUTO_ROUTE') && DISPATCHER_AUTO_ROUTE === true AND $this->routable($service.".php", true) ) { |
|
| 147 | + else if (defined('DISPATCHER_AUTO_ROUTE') && DISPATCHER_AUTO_ROUTE === true AND $this->routable($service.".php", true)) { |
|
| 148 | 148 | |
| 149 | 149 | return array( |
| 150 | 150 | "type" => "ROUTE", |
@@ -178,9 +178,9 @@ discard block |
||
| 178 | 178 | * |
| 179 | 179 | * @return bool |
| 180 | 180 | */ |
| 181 | - private function routable($target, $relative=false) { |
|
| 181 | + private function routable($target, $relative = false) { |
|
| 182 | 182 | |
| 183 | - if ( $relative ) return is_readable(DISPATCHER_SERVICES_FOLDER.$target) ? true : false; |
|
| 183 | + if ($relative) return is_readable(DISPATCHER_SERVICES_FOLDER.$target) ? true : false; |
|
| 184 | 184 | |
| 185 | 185 | else return is_readable($target) ? true : false; |
| 186 | 186 | |
@@ -193,7 +193,7 @@ discard block |
||
| 193 | 193 | */ |
| 194 | 194 | private function routeToLanding() { |
| 195 | 195 | |
| 196 | - if ( isset($this->table[""]) ) { |
|
| 196 | + if (isset($this->table[""])) { |
|
| 197 | 197 | |
| 198 | 198 | return $this->table[""]; |
| 199 | 199 | |
@@ -210,7 +210,7 @@ discard block |
||
| 210 | 210 | */ |
| 211 | 211 | private function routeToDefault() { |
| 212 | 212 | |
| 213 | - if ( isset($this->table["default"]) ) { |
|
| 213 | + if (isset($this->table["default"])) { |
|
| 214 | 214 | |
| 215 | 215 | return $this->table["default"]; |
| 216 | 216 | |
@@ -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 | /** |