@@ -62,7 +62,7 @@ discard block |
||
| 62 | 62 | $output_class_name = "\\Comodojo\\Dispatcher\\Response\\Preprocessor\\Status".$status; |
| 63 | 63 | |
| 64 | 64 | // @TODO: this condition will be removed when all preprocessors ready |
| 65 | - if ( class_exists($output_class_name) ) { |
|
| 65 | + if (class_exists($output_class_name)) { |
|
| 66 | 66 | $output = new $output_class_name($this); |
| 67 | 67 | } else { |
| 68 | 68 | $output = new \Comodojo\Dispatcher\Response\Preprocessor\Status200($this); |
@@ -70,13 +70,13 @@ discard block |
||
| 70 | 70 | |
| 71 | 71 | $output->consolidate(); |
| 72 | 72 | |
| 73 | - if ( $route != null ) { |
|
| 73 | + if ($route != null) { |
|
| 74 | 74 | $this->setClientCache($request, $route); |
| 75 | 75 | } |
| 76 | 76 | |
| 77 | 77 | // extra checks |
| 78 | 78 | |
| 79 | - if ( $request->method->get() == 'HEAD' && !in_array($status, array(100,101,102,204,304)) ) { |
|
| 79 | + if ($request->method->get() == 'HEAD' && !in_array($status, array(100, 101, 102, 204, 304))) { |
|
| 80 | 80 | $length = $this->content->length(); |
| 81 | 81 | $this->content->set(null); |
| 82 | 82 | if ($length) $this->headers->set('Content-Length', $length); |
@@ -86,7 +86,7 @@ discard block |
||
| 86 | 86 | $this->headers->delete('Content-Length'); |
| 87 | 87 | } |
| 88 | 88 | |
| 89 | - if ( $request->version->get() == '1.0' && false !== strpos($this->headers->get('Cache-Control'), 'no-cache')) { |
|
| 89 | + if ($request->version->get() == '1.0' && false !== strpos($this->headers->get('Cache-Control'), 'no-cache')) { |
|
| 90 | 90 | $this->headers->set('pragma', 'no-cache'); |
| 91 | 91 | $this->headers->set('expires', -1); |
| 92 | 92 | } |
@@ -106,15 +106,15 @@ discard block |
||
| 106 | 106 | // the cache layer will be improoved in future versions. |
| 107 | 107 | ) { |
| 108 | 108 | |
| 109 | - if ( $ttl > 0 ) { |
|
| 109 | + if ($ttl > 0) { |
|
| 110 | 110 | |
| 111 | - $this->headers->set("Cache-Control","max-age=".$ttl.", must-revalidate"); |
|
| 112 | - $this->headers->set("Expires",gmdate("D, d M Y H:i:s", (int)$this->getTimestamp() + $ttl)." GMT"); |
|
| 111 | + $this->headers->set("Cache-Control", "max-age=".$ttl.", must-revalidate"); |
|
| 112 | + $this->headers->set("Expires", gmdate("D, d M Y H:i:s", (int)$this->getTimestamp()+$ttl)." GMT"); |
|
| 113 | 113 | |
| 114 | 114 | } else { |
| 115 | 115 | |
| 116 | - $this->headers->set("Cache-Control","no-cache, must-revalidate"); |
|
| 117 | - $this->headers->set("Expires","Mon, 26 Jul 1997 05:00:00 GMT"); |
|
| 116 | + $this->headers->set("Cache-Control", "no-cache, must-revalidate"); |
|
| 117 | + $this->headers->set("Expires", "Mon, 26 Jul 1997 05:00:00 GMT"); |
|
| 118 | 118 | |
| 119 | 119 | } |
| 120 | 120 | |
@@ -48,7 +48,7 @@ discard block |
||
| 48 | 48 | |
| 49 | 49 | public function set($code) { |
| 50 | 50 | |
| 51 | - if ( !$this->codes->exists($code) ) { |
|
| 51 | + if (!$this->codes->exists($code)) { |
|
| 52 | 52 | |
| 53 | 53 | throw new Exception("Invalid HTTP Status Code $code"); |
| 54 | 54 | |
@@ -60,9 +60,9 @@ discard block |
||
| 60 | 60 | |
| 61 | 61 | } |
| 62 | 62 | |
| 63 | - public function description($code=null) { |
|
| 63 | + public function description($code = null) { |
|
| 64 | 64 | |
| 65 | - if ( is_null($code) ) return $this->codes->getMessage($this->status_code); |
|
| 65 | + if (is_null($code)) return $this->codes->getMessage($this->status_code); |
|
| 66 | 66 | |
| 67 | 67 | return $this->codes->getMessage($code); |
| 68 | 68 | |
@@ -32,11 +32,11 @@ |
||
| 32 | 32 | |
| 33 | 33 | $location = $this->response->location->get(); |
| 34 | 34 | |
| 35 | - if ( empty($location) ) throw new Exception("Invalid location, cannot redirect"); |
|
| 35 | + if (empty($location)) throw new Exception("Invalid location, cannot redirect"); |
|
| 36 | 36 | |
| 37 | 37 | $this->response->headers->set("Location: ".$location); |
| 38 | 38 | |
| 39 | - if ( empty($this->response->content->get()) ) { |
|
| 39 | + if (empty($this->response->content->get())) { |
|
| 40 | 40 | |
| 41 | 41 | $this->response->content->set(sprintf('<!DOCTYPE html> |
| 42 | 42 | <html> |
@@ -28,9 +28,9 @@ |
||
| 28 | 28 | |
| 29 | 29 | public function consolidate() { |
| 30 | 30 | |
| 31 | - $this->response->content>set(null); |
|
| 32 | - $this->response->headers>delete('Content-Type'); |
|
| 33 | - $this->response->headers>delete('Content-Length'); |
|
| 31 | + $this->response->content > set(null); |
|
| 32 | + $this->response->headers > delete('Content-Type'); |
|
| 33 | + $this->response->headers > delete('Content-Length'); |
|
| 34 | 34 | |
| 35 | 35 | } |
| 36 | 36 | |
@@ -30,7 +30,7 @@ |
||
| 30 | 30 | |
| 31 | 31 | $location = $this->response->location->get(); |
| 32 | 32 | |
| 33 | - if ( $location != null ) $this->response->headers->set("Location: ".$location); |
|
| 33 | + if ($location != null) $this->response->headers->set("Location: ".$location); |
|
| 34 | 34 | |
| 35 | 35 | parent::consolidate(); |
| 36 | 36 | |
@@ -60,7 +60,7 @@ discard block |
||
| 60 | 60 | $this->setTimestamp(); |
| 61 | 61 | |
| 62 | 62 | // parsing configuration |
| 63 | - $this->configuration = new Configuration( DefaultConfiguration::get() ); |
|
| 63 | + $this->configuration = new Configuration(DefaultConfiguration::get()); |
|
| 64 | 64 | |
| 65 | 65 | $this->configuration->merge($configuration); |
| 66 | 66 | |
@@ -91,9 +91,9 @@ discard block |
||
| 91 | 91 | |
| 92 | 92 | $this->logger->debug("Emitting global dispatcher event."); |
| 93 | 93 | |
| 94 | - $this->events->emit( new DispatcherEvent($this) ); |
|
| 94 | + $this->events->emit(new DispatcherEvent($this)); |
|
| 95 | 95 | |
| 96 | - if ( $this->configuration->get('enabled') === false ) { |
|
| 96 | + if ($this->configuration->get('enabled') === false) { |
|
| 97 | 97 | |
| 98 | 98 | $this->logger->debug("Dispatcher disabled, shutting down gracefully."); |
| 99 | 99 | |
@@ -109,13 +109,13 @@ discard block |
||
| 109 | 109 | |
| 110 | 110 | } |
| 111 | 111 | |
| 112 | - $this->events->emit( $this->emitServiceSpecializedEvents('dispatcher.request') ); |
|
| 112 | + $this->events->emit($this->emitServiceSpecializedEvents('dispatcher.request')); |
|
| 113 | 113 | |
| 114 | - $this->events->emit( $this->emitServiceSpecializedEvents('dispatcher.request.'.$this->request->method->get()) ); |
|
| 114 | + $this->events->emit($this->emitServiceSpecializedEvents('dispatcher.request.'.$this->request->method->get())); |
|
| 115 | 115 | |
| 116 | - $this->events->emit( $this->emitServiceSpecializedEvents('dispatcher.request.#') ); |
|
| 116 | + $this->events->emit($this->emitServiceSpecializedEvents('dispatcher.request.#')); |
|
| 117 | 117 | |
| 118 | - if ( $this->readCache() ) { |
|
| 118 | + if ($this->readCache()) { |
|
| 119 | 119 | |
| 120 | 120 | return $this->shutdown(); |
| 121 | 121 | |
@@ -145,13 +145,13 @@ discard block |
||
| 145 | 145 | |
| 146 | 146 | $this->logger->debug("Route acquired, type $route_type directed to $route_service."); |
| 147 | 147 | |
| 148 | - $this->events->emit( $this->emitServiceSpecializedEvents('dispatcher.route') ); |
|
| 148 | + $this->events->emit($this->emitServiceSpecializedEvents('dispatcher.route')); |
|
| 149 | 149 | |
| 150 | - $this->events->emit( $this->emitServiceSpecializedEvents('dispatcher.route.'.$route_type) ); |
|
| 150 | + $this->events->emit($this->emitServiceSpecializedEvents('dispatcher.route.'.$route_type)); |
|
| 151 | 151 | |
| 152 | - $this->events->emit( $this->emitServiceSpecializedEvents('dispatcher.route.'.$route_service) ); |
|
| 152 | + $this->events->emit($this->emitServiceSpecializedEvents('dispatcher.route.'.$route_service)); |
|
| 153 | 153 | |
| 154 | - $this->events->emit( $this->emitServiceSpecializedEvents('dispatcher.route.#') ); |
|
| 154 | + $this->events->emit($this->emitServiceSpecializedEvents('dispatcher.route.#')); |
|
| 155 | 155 | |
| 156 | 156 | // translate route to service |
| 157 | 157 | |
@@ -179,11 +179,11 @@ discard block |
||
| 179 | 179 | |
| 180 | 180 | private function readCache() { |
| 181 | 181 | |
| 182 | - $name = (string) $this->request->uri; |
|
| 182 | + $name = (string)$this->request->uri; |
|
| 183 | 183 | |
| 184 | 184 | $cache = $this->cache->setNamespace('dispatcherservice')->get($name); |
| 185 | 185 | |
| 186 | - if ( is_null($cache) ) return false; |
|
| 186 | + if (is_null($cache)) return false; |
|
| 187 | 187 | |
| 188 | 188 | $this->response->import($cache); |
| 189 | 189 | |
@@ -195,7 +195,7 @@ discard block |
||
| 195 | 195 | |
| 196 | 196 | $cache = strtoupper($route->getParameter('cache')); |
| 197 | 197 | $ttl = $route->getParameter('ttl'); |
| 198 | - $name = (string) $this->request->uri; |
|
| 198 | + $name = (string)$this->request->uri; |
|
| 199 | 199 | $method = $this->request->method->get(); |
| 200 | 200 | $status = $this->response->status->get(); |
| 201 | 201 | |
@@ -203,10 +203,10 @@ discard block |
||
| 203 | 203 | // because of dispatcher internal structure: if post request is cached |
| 204 | 204 | // subsequent requests will never reach the service. |
| 205 | 205 | if ( |
| 206 | - ( $cache == 'SERVER' || $cache == 'BOTH' ) && |
|
| 206 | + ($cache == 'SERVER' || $cache == 'BOTH') && |
|
| 207 | 207 | in_array($request->method->get(), array('GET', 'HEAD')) && |
| 208 | 208 | in_array($this->status->get(), array(200, 203, 300, 301, 302, 404, 410)) |
| 209 | - ){ |
|
| 209 | + ) { |
|
| 210 | 210 | |
| 211 | 211 | $this->cache->setNamespace('dispatcherservice')->set($name, $this->response->export(), $ttl); |
| 212 | 212 | |
@@ -218,9 +218,9 @@ discard block |
||
| 218 | 218 | |
| 219 | 219 | $params = $route->getParameter('headers'); |
| 220 | 220 | |
| 221 | - if ( !empty($params) && is_array($params) ) { |
|
| 221 | + if (!empty($params) && is_array($params)) { |
|
| 222 | 222 | |
| 223 | - foreach($params as $name=>$value) $this->response->headers->set($name, $value); |
|
| 223 | + foreach ($params as $name=>$value) $this->response->headers->set($name, $value); |
|
| 224 | 224 | } |
| 225 | 225 | |
| 226 | 226 | } |
@@ -260,11 +260,11 @@ discard block |
||
| 260 | 260 | |
| 261 | 261 | $this->response->consolidate($this->request, $this->route); |
| 262 | 262 | |
| 263 | - $this->events->emit( $this->emitServiceSpecializedEvents('dispatcher.response') ); |
|
| 263 | + $this->events->emit($this->emitServiceSpecializedEvents('dispatcher.response')); |
|
| 264 | 264 | |
| 265 | - $this->events->emit( $this->emitServiceSpecializedEvents('dispatcher.response.'.$this->response->status->get()) ); |
|
| 265 | + $this->events->emit($this->emitServiceSpecializedEvents('dispatcher.response.'.$this->response->status->get())); |
|
| 266 | 266 | |
| 267 | - $this->events->emit( $this->emitServiceSpecializedEvents('dispatcher.response.#') ); |
|
| 267 | + $this->events->emit($this->emitServiceSpecializedEvents('dispatcher.response.#')); |
|
| 268 | 268 | |
| 269 | 269 | $this->logger->debug("Composing return value."); |
| 270 | 270 | |
@@ -272,7 +272,7 @@ discard block |
||
| 272 | 272 | |
| 273 | 273 | $this->logger->debug("Dispatcher run-cycle ends."); |
| 274 | 274 | |
| 275 | - if ( function_exists('fastcgi_finish_request') ) fastcgi_finish_request(); |
|
| 275 | + if (function_exists('fastcgi_finish_request')) fastcgi_finish_request(); |
|
| 276 | 276 | else ob_end_clean(); |
| 277 | 277 | |
| 278 | 278 | return $return; |
@@ -61,7 +61,7 @@ |
||
| 61 | 61 | |
| 62 | 62 | $status = $this->response->status->get(); |
| 63 | 63 | |
| 64 | - if ( !$this->codes->exists($status) ) throw new Exception("Invalid HTTP status code in response"); |
|
| 64 | + if (!$this->codes->exists($status)) throw new Exception("Invalid HTTP status code in response"); |
|
| 65 | 65 | |
| 66 | 66 | $message = $this->codes->getMessage($status); |
| 67 | 67 | |
@@ -35,25 +35,25 @@ discard block |
||
| 35 | 35 | |
| 36 | 36 | $cache = $this->configuration->get('cache');
|
| 37 | 37 | |
| 38 | - if ( empty($cache) ) {
|
|
| 38 | + if (empty($cache)) {
|
|
| 39 | 39 | |
| 40 | 40 | $manager = new ComodojoCacheManager(self::getAlgorithm(), $this->logger); |
| 41 | 41 | |
| 42 | 42 | } else {
|
| 43 | 43 | |
| 44 | - $enabled = ( empty($cache['enabled']) || $cache['enabled'] === true ) ? true : false; |
|
| 44 | + $enabled = (empty($cache['enabled']) || $cache['enabled'] === true) ? true : false; |
|
| 45 | 45 | |
| 46 | - $algorithm = self::getAlgorithm( empty($cache['algorithm']) ? null : $cache['algorithm']); |
|
| 46 | + $algorithm = self::getAlgorithm(empty($cache['algorithm']) ? null : $cache['algorithm']); |
|
| 47 | 47 | |
| 48 | 48 | $manager = new ComodojoCacheManager($algorithm, $this->logger); |
| 49 | 49 | |
| 50 | - if ( $enabled && !empty($cache['providers']) ) {
|
|
| 50 | + if ($enabled && !empty($cache['providers'])) {
|
|
| 51 | 51 | |
| 52 | 52 | foreach ($cache['providers'] as $provider => $parameters) {
|
| 53 | 53 | |
| 54 | 54 | $handler = $this->getHandler($provider, $parameters); |
| 55 | 55 | |
| 56 | - if ( $handler instanceof CacheInterface ) $manager->addProvider($handler); |
|
| 56 | + if ($handler instanceof CacheInterface) $manager->addProvider($handler); |
|
| 57 | 57 | |
| 58 | 58 | } |
| 59 | 59 | |
@@ -80,13 +80,13 @@ discard block |
||
| 80 | 80 | |
| 81 | 81 | protected function getHandler($provider, $parameters) {
|
| 82 | 82 | |
| 83 | - switch ( strtolower($parameters['type']) ) {
|
|
| 83 | + switch (strtolower($parameters['type'])) {
|
|
| 84 | 84 | |
| 85 | 85 | case 'filecache': |
| 86 | 86 | |
| 87 | 87 | $base = $this->configuration->get('base-path');
|
| 88 | 88 | |
| 89 | - if ( empty($parameters['folder']) || empty($base) ) {
|
|
| 89 | + if (empty($parameters['folder']) || empty($base)) {
|
|
| 90 | 90 | $this->logger->warning("Wrong cache provider, disabling $provider", $parameters);
|
| 91 | 91 | break; |
| 92 | 92 | } |
@@ -99,7 +99,7 @@ discard block |
||
| 99 | 99 | |
| 100 | 100 | case 'memcached': |
| 101 | 101 | |
| 102 | - if ( empty($parameters['host']) ) {
|
|
| 102 | + if (empty($parameters['host'])) {
|
|
| 103 | 103 | $this->logger->warning("Wrong cache provider, disabling $provider", $parameters);
|
| 104 | 104 | break; |
| 105 | 105 | } |
@@ -132,7 +132,7 @@ discard block |
||
| 132 | 132 | */ |
| 133 | 133 | protected static function getAlgorithm($algorithm = null) {
|
| 134 | 134 | |
| 135 | - switch ( strtoupper($algorithm) ) {
|
|
| 135 | + switch (strtoupper($algorithm)) {
|
|
| 136 | 136 | |
| 137 | 137 | case 'PICK_LAST': |
| 138 | 138 | $selected = ComodojoCacheManager::PICK_LAST; |
@@ -29,7 +29,7 @@ |
||
| 29 | 29 | |
| 30 | 30 | public function __get($name) { |
| 31 | 31 | |
| 32 | - if ( array_key_exists($name, $this->data) ) { |
|
| 32 | + if (array_key_exists($name, $this->data)) { |
|
| 33 | 33 | |
| 34 | 34 | return $this->data[$name]; |
| 35 | 35 | |