@@ -44,6 +44,9 @@ |
||
44 | 44 | |
45 | 45 | } |
46 | 46 | |
47 | + /** |
|
48 | + * @return string |
|
49 | + */ |
|
47 | 50 | public function getTemporaryName() { |
48 | 51 | |
49 | 52 | return $this->tname; |
@@ -108,9 +108,9 @@ discard block |
||
108 | 108 | |
109 | 109 | if (!empty($this->path) && file_exists($this->path)) { |
110 | 110 | |
111 | - $local_name = "$this->path/" . ($as_slug ? $this->getSlug() : $this->getFileName()); |
|
111 | + $local_name = "$this->path/".($as_slug ? $this->getSlug() : $this->getFileName()); |
|
112 | 112 | |
113 | - if ( file_exists($local_name) ) { |
|
113 | + if (file_exists($local_name)) { |
|
114 | 114 | |
115 | 115 | $files = glob("$local_name*"); |
116 | 116 | |
@@ -120,7 +120,7 @@ discard block |
||
120 | 120 | |
121 | 121 | } |
122 | 122 | |
123 | - if ( move_uploaded_file($this->getTemporaryName(), $local_name) ) { |
|
123 | + if (move_uploaded_file($this->getTemporaryName(), $local_name)) { |
|
124 | 124 | |
125 | 125 | // return file_exists($local_name); |
126 | 126 | return true; |
@@ -84,7 +84,9 @@ |
||
84 | 84 | |
85 | 85 | $file = $this->getTemporaryName(); |
86 | 86 | |
87 | - if (file_exists($file)) return file_get_contents($file); |
|
87 | + if (file_exists($file)) { |
|
88 | + return file_get_contents($file); |
|
89 | + } |
|
88 | 90 | |
89 | 91 | throw new Exception("File does not exists"); |
90 | 92 |
@@ -29,7 +29,7 @@ |
||
29 | 29 | |
30 | 30 | protected $dispatcher; |
31 | 31 | |
32 | - public function __construct( Dispatcher $dispatcher ) { |
|
32 | + public function __construct(Dispatcher $dispatcher) { |
|
33 | 33 | |
34 | 34 | parent::__construct('dispatcher'); |
35 | 35 |
@@ -28,9 +28,9 @@ discard block |
||
28 | 28 | |
29 | 29 | public function get($header = null) { |
30 | 30 | |
31 | - if ( is_null($header) ) return $this->headers; |
|
31 | + if (is_null($header)) return $this->headers; |
|
32 | 32 | |
33 | - else if ( array_key_exists($header, $this->headers) ) return $this->headers[$header]; |
|
33 | + else if (array_key_exists($header, $this->headers)) return $this->headers[$header]; |
|
34 | 34 | |
35 | 35 | else return null; |
36 | 36 | |
@@ -38,14 +38,14 @@ discard block |
||
38 | 38 | |
39 | 39 | public function getAsString($header = null) { |
40 | 40 | |
41 | - if ( is_null($header) ) { |
|
41 | + if (is_null($header)) { |
|
42 | 42 | |
43 | - return array_map( [$this, 'headerToString'], |
|
43 | + return array_map([$this, 'headerToString'], |
|
44 | 44 | array_keys($this->headers), |
45 | 45 | array_values($this->headers) |
46 | 46 | ); |
47 | 47 | |
48 | - } else if ( array_key_exists($header, $this->headers) ) { |
|
48 | + } else if (array_key_exists($header, $this->headers)) { |
|
49 | 49 | |
50 | 50 | return self::headerToString($header, $this->headers[$header]); |
51 | 51 | |
@@ -53,9 +53,9 @@ discard block |
||
53 | 53 | |
54 | 54 | } |
55 | 55 | |
56 | - public function set($header, $value=null) { |
|
56 | + public function set($header, $value = null) { |
|
57 | 57 | |
58 | - if ( is_null($value) ) { |
|
58 | + if (is_null($value)) { |
|
59 | 59 | |
60 | 60 | $header = explode(":", $header); |
61 | 61 | |
@@ -73,13 +73,13 @@ discard block |
||
73 | 73 | |
74 | 74 | public function delete($header = null) { |
75 | 75 | |
76 | - if ( is_null($header) ) { |
|
76 | + if (is_null($header)) { |
|
77 | 77 | |
78 | 78 | $this->headers = array(); |
79 | 79 | |
80 | 80 | return true; |
81 | 81 | |
82 | - } else if ( array_key_exists($header, $this->headers) ) { |
|
82 | + } else if (array_key_exists($header, $this->headers)) { |
|
83 | 83 | |
84 | 84 | unset($this->headers[$header]); |
85 | 85 |
@@ -78,7 +78,7 @@ discard block |
||
78 | 78 | |
79 | 79 | // init core components |
80 | 80 | // create new configuration object and merge configuration |
81 | - $configuration_object = new Configuration( DefaultConfiguration::get() ); |
|
81 | + $configuration_object = new Configuration(DefaultConfiguration::get()); |
|
82 | 82 | $configuration_object->merge($configuration); |
83 | 83 | $logger = is_null($logger) ? LogManager::createFromConfiguration($configuration_object)->getLogger() : $logger; |
84 | 84 | |
@@ -104,9 +104,9 @@ discard block |
||
104 | 104 | |
105 | 105 | $this->logger->debug("Emitting global dispatcher event."); |
106 | 106 | |
107 | - $this->events->emit( new DispatcherEvent($this) ); |
|
107 | + $this->events->emit(new DispatcherEvent($this)); |
|
108 | 108 | |
109 | - if ( $this->configuration->get('enabled') === false ) { |
|
109 | + if ($this->configuration->get('enabled') === false) { |
|
110 | 110 | |
111 | 111 | $this->logger->debug("Dispatcher disabled, shutting down gracefully."); |
112 | 112 | |
@@ -124,13 +124,13 @@ discard block |
||
124 | 124 | |
125 | 125 | $cache = new ServerCache($this->cache); |
126 | 126 | |
127 | - $this->events->emit( $this->emitServiceSpecializedEvents('dispatcher.request') ); |
|
127 | + $this->events->emit($this->emitServiceSpecializedEvents('dispatcher.request')); |
|
128 | 128 | |
129 | - $this->events->emit( $this->emitServiceSpecializedEvents('dispatcher.request.'.$this->request->method->get()) ); |
|
129 | + $this->events->emit($this->emitServiceSpecializedEvents('dispatcher.request.'.$this->request->method->get())); |
|
130 | 130 | |
131 | - $this->events->emit( $this->emitServiceSpecializedEvents('dispatcher.request.#') ); |
|
131 | + $this->events->emit($this->emitServiceSpecializedEvents('dispatcher.request.#')); |
|
132 | 132 | |
133 | - if ( $cache->read($this->request, $this->response) ) { |
|
133 | + if ($cache->read($this->request, $this->response)) { |
|
134 | 134 | |
135 | 135 | return $this->shutdown(); |
136 | 136 | |
@@ -158,13 +158,13 @@ discard block |
||
158 | 158 | |
159 | 159 | $this->logger->debug("Route acquired, type $route_type directed to $route_service."); |
160 | 160 | |
161 | - $this->events->emit( $this->emitServiceSpecializedEvents('dispatcher.route') ); |
|
161 | + $this->events->emit($this->emitServiceSpecializedEvents('dispatcher.route')); |
|
162 | 162 | |
163 | - $this->events->emit( $this->emitServiceSpecializedEvents('dispatcher.route.'.$route_type) ); |
|
163 | + $this->events->emit($this->emitServiceSpecializedEvents('dispatcher.route.'.$route_type)); |
|
164 | 164 | |
165 | - $this->events->emit( $this->emitServiceSpecializedEvents('dispatcher.route.'.$route_service) ); |
|
165 | + $this->events->emit($this->emitServiceSpecializedEvents('dispatcher.route.'.$route_service)); |
|
166 | 166 | |
167 | - $this->events->emit( $this->emitServiceSpecializedEvents('dispatcher.route.#') ); |
|
167 | + $this->events->emit($this->emitServiceSpecializedEvents('dispatcher.route.#')); |
|
168 | 168 | |
169 | 169 | // translate route to service |
170 | 170 | |
@@ -194,9 +194,9 @@ discard block |
||
194 | 194 | |
195 | 195 | $params = $route->getParameter('headers'); |
196 | 196 | |
197 | - if ( !empty($params) && is_array($params) ) { |
|
197 | + if (!empty($params) && is_array($params)) { |
|
198 | 198 | |
199 | - foreach($params as $name=>$value) $this->response->headers->set($name, $value); |
|
199 | + foreach ($params as $name=>$value) $this->response->headers->set($name, $value); |
|
200 | 200 | } |
201 | 201 | |
202 | 202 | } |
@@ -236,11 +236,11 @@ discard block |
||
236 | 236 | |
237 | 237 | $this->response->consolidate($this->request, $this->route); |
238 | 238 | |
239 | - $this->events->emit( $this->emitServiceSpecializedEvents('dispatcher.response') ); |
|
239 | + $this->events->emit($this->emitServiceSpecializedEvents('dispatcher.response')); |
|
240 | 240 | |
241 | - $this->events->emit( $this->emitServiceSpecializedEvents('dispatcher.response.'.$this->response->status->get()) ); |
|
241 | + $this->events->emit($this->emitServiceSpecializedEvents('dispatcher.response.'.$this->response->status->get())); |
|
242 | 242 | |
243 | - $this->events->emit( $this->emitServiceSpecializedEvents('dispatcher.response.#') ); |
|
243 | + $this->events->emit($this->emitServiceSpecializedEvents('dispatcher.response.#')); |
|
244 | 244 | |
245 | 245 | $this->logger->debug("Composing return value."); |
246 | 246 | |
@@ -248,7 +248,7 @@ discard block |
||
248 | 248 | |
249 | 249 | $this->logger->debug("Dispatcher run-cycle ends."); |
250 | 250 | |
251 | - if ( function_exists('fastcgi_finish_request') ) fastcgi_finish_request(); |
|
251 | + if (function_exists('fastcgi_finish_request')) fastcgi_finish_request(); |
|
252 | 252 | else ob_end_clean(); |
253 | 253 | |
254 | 254 | return $return; |
@@ -121,9 +121,9 @@ discard block |
||
121 | 121 | |
122 | 122 | public function load($routes) { |
123 | 123 | |
124 | - if ( !empty($routes) ) { |
|
124 | + if (!empty($routes)) { |
|
125 | 125 | |
126 | - foreach( $routes as $name => $route ) { |
|
126 | + foreach ($routes as $name => $route) { |
|
127 | 127 | |
128 | 128 | $this->add($route['route'], $route['type'], $route['class'], $route['parameters']); |
129 | 129 | |
@@ -139,11 +139,11 @@ discard block |
||
139 | 139 | |
140 | 140 | private function readCache() { |
141 | 141 | |
142 | - if ( $this->configuration->get('routing-table-cache') !== true ) return; |
|
142 | + if ($this->configuration->get('routing-table-cache') !== true) return; |
|
143 | 143 | |
144 | 144 | $data = $this->cache->read(); |
145 | 145 | |
146 | - if ( is_null($data) ) { |
|
146 | + if (is_null($data)) { |
|
147 | 147 | |
148 | 148 | $this->routes = []; |
149 | 149 | |
@@ -159,11 +159,11 @@ discard block |
||
159 | 159 | |
160 | 160 | private function dumpCache() { |
161 | 161 | |
162 | - if ( $this->configuration->get('routing-table-cache') !== true ) return; |
|
162 | + if ($this->configuration->get('routing-table-cache') !== true) return; |
|
163 | 163 | |
164 | 164 | $ttl = $this->configuration->get('routing-table-ttl'); |
165 | 165 | |
166 | - if ( $this->cache->dump($this->routes, $ttl) ) { |
|
166 | + if ($this->cache->dump($this->routes, $ttl)) { |
|
167 | 167 | $this->logger->debug("Routing table saved to cache"); |
168 | 168 | } else { |
169 | 169 | $this->logger->warning("Cannot save routing table to cache"); |
@@ -180,14 +180,14 @@ discard block |
||
180 | 180 | ->setClassName($class) // Class to be invoked |
181 | 181 | ->setParameters($parameters); // Parameters passed via the composer.json configuration (cache, ttl, etc...) |
182 | 182 | |
183 | - $this->logger->debug("ROUTE: " . implode("/", $folders)); |
|
183 | + $this->logger->debug("ROUTE: ".implode("/", $folders)); |
|
184 | 184 | |
185 | 185 | //$this->logger->debug("PARAMETERS: " . var_export($value, true)); |
186 | 186 | |
187 | 187 | // This method generate a global regular expression which will be able to match all the URI supported by the route |
188 | 188 | $regex = $this->parser->read($folders, $route); |
189 | 189 | |
190 | - $this->logger->debug("ROUTE: " . $regex); |
|
190 | + $this->logger->debug("ROUTE: ".$regex); |
|
191 | 191 | |
192 | 192 | //$this->logger->debug("PARAMETERS: " . var_export($value, true)); |
193 | 193 |