@@ -116,6 +116,10 @@ |
||
| 116 | 116 | } |
| 117 | 117 | |
| 118 | 118 | // This method read a single parameter and build the regular expression |
| 119 | + |
|
| 120 | + /** |
|
| 121 | + * @param Route $value |
|
| 122 | + */ |
|
| 119 | 123 | private function param($key, $string, $value) { |
| 120 | 124 | |
| 121 | 125 | $field_required = false; |
@@ -90,6 +90,11 @@ |
||
| 90 | 90 | |
| 91 | 91 | } |
| 92 | 92 | |
| 93 | + /** |
|
| 94 | + * @param string $key |
|
| 95 | + * |
|
| 96 | + * @return string |
|
| 97 | + */ |
|
| 93 | 98 | public function getParameter($key) { |
| 94 | 99 | |
| 95 | 100 | return (isset($this->parameters[$key]))?$this->parameters[$key]:null; |
@@ -223,7 +223,10 @@ |
||
| 223 | 223 | */ |
| 224 | 224 | if (preg_match('/^' . $value['regex'] . '$/', $bits[$key], $matches)) { |
| 225 | 225 | |
| 226 | - if (count($matches) == 1) $matches = $matches[0]; // This is the case where no backreferences are present or available. |
|
| 226 | + if (count($matches) == 1) { |
|
| 227 | + $matches = $matches[0]; |
|
| 228 | + } |
|
| 229 | + // This is the case where no backreferences are present or available. |
|
| 227 | 230 | |
| 228 | 231 | // The extracted value (with any backreference available) is added to the query parameters. |
| 229 | 232 | $this->request->query()->set($key, $matches); |
@@ -62,7 +62,7 @@ discard block |
||
| 62 | 62 | public function getLocalName() { |
| 63 | 63 | |
| 64 | 64 | if (!empty($this->path)) |
| 65 | - return $this->path . "/" . $this->slug; |
|
| 65 | + return $this->path."/".$this->slug; |
|
| 66 | 66 | else |
| 67 | 67 | return ''; |
| 68 | 68 | |
@@ -117,7 +117,7 @@ discard block |
||
| 117 | 117 | !empty($this->path) && |
| 118 | 118 | !empty($this->slug) && |
| 119 | 119 | file_exists($this->getLocalName()) && |
| 120 | - file_exists($this->getLocalName() . ".data") |
|
| 120 | + file_exists($this->getLocalName().".data") |
|
| 121 | 121 | ); |
| 122 | 122 | |
| 123 | 123 | } |
@@ -202,7 +202,7 @@ discard block |
||
| 202 | 202 | |
| 203 | 203 | private function loadFileInfo() { |
| 204 | 204 | |
| 205 | - $info = $this->getLocalName() . ".data"; |
|
| 205 | + $info = $this->getLocalName().".data"; |
|
| 206 | 206 | |
| 207 | 207 | if (file_exists($info)) { |
| 208 | 208 | |
@@ -223,7 +223,7 @@ discard block |
||
| 223 | 223 | |
| 224 | 224 | private function saveFileInfo() { |
| 225 | 225 | |
| 226 | - $info = $this->getLocalName() . ".data"; |
|
| 226 | + $info = $this->getLocalName().".data"; |
|
| 227 | 227 | |
| 228 | 228 | if (!empty($this->path) && file_exists($this->path)) { |
| 229 | 229 | |
@@ -248,17 +248,17 @@ discard block |
||
| 248 | 248 | |
| 249 | 249 | preg_match_all("/[a-z0-9]+/", iconv("UTF-8", "ASCII//TRANSLIT", strtolower(preg_replace('/\..*?$/', '', $this->fname))), $matches); |
| 250 | 250 | |
| 251 | - $this->slug = implode('-', $matches[0]); |
|
| 251 | + $this->slug = implode('-', $matches[0]); |
|
| 252 | 252 | |
| 253 | 253 | if (!empty($this->path)) { |
| 254 | 254 | |
| 255 | - $files = glob($this->path . "/" . $slug . "*"); |
|
| 255 | + $files = glob($this->path."/".$slug."*"); |
|
| 256 | 256 | |
| 257 | - $count = count ($files); |
|
| 257 | + $count = count($files); |
|
| 258 | 258 | |
| 259 | 259 | if ($count > 0) { |
| 260 | 260 | |
| 261 | - $this->slug .= "-" . $count; |
|
| 261 | + $this->slug .= "-".$count; |
|
| 262 | 262 | |
| 263 | 263 | } |
| 264 | 264 | |
@@ -61,10 +61,11 @@ discard block |
||
| 61 | 61 | |
| 62 | 62 | public function getLocalName() { |
| 63 | 63 | |
| 64 | - if (!empty($this->path)) |
|
| 65 | - return $this->path . "/" . $this->slug; |
|
| 66 | - else |
|
| 67 | - return ''; |
|
| 64 | + if (!empty($this->path)) { |
|
| 65 | + return $this->path . "/" . $this->slug; |
|
| 66 | + } else { |
|
| 67 | + return ''; |
|
| 68 | + } |
|
| 68 | 69 | |
| 69 | 70 | } |
| 70 | 71 | |
@@ -101,11 +102,13 @@ discard block |
||
| 101 | 102 | public function getFileData() { |
| 102 | 103 | |
| 103 | 104 | $file = $this->getTemporaryName(); |
| 104 | - if (empty($file)) |
|
| 105 | - $file = $this->getLocalName(); |
|
| 105 | + if (empty($file)) { |
|
| 106 | + $file = $this->getLocalName(); |
|
| 107 | + } |
|
| 106 | 108 | |
| 107 | - if (file_exists($file)) |
|
| 108 | - return file_get_contents($file); |
|
| 109 | + if (file_exists($file)) { |
|
| 110 | + return file_get_contents($file); |
|
| 111 | + } |
|
| 109 | 112 | |
| 110 | 113 | throw new DispatcherException("File does not exists"); |
| 111 | 114 | |
@@ -105,7 +105,9 @@ discard block |
||
| 105 | 105 | |
| 106 | 106 | if (!$this->bypass_routing) { |
| 107 | 107 | |
| 108 | - if (!$this->parse()) throw new DispatcherException("Unable to find a valid route for the specified uri", 0, null, 404); |
|
| 108 | + if (!$this->parse()) { |
|
| 109 | + throw new DispatcherException("Unable to find a valid route for the specified uri", 0, null, 404); |
|
| 110 | + } |
|
| 109 | 111 | |
| 110 | 112 | } |
| 111 | 113 | |
@@ -133,8 +135,9 @@ discard block |
||
| 133 | 135 | $this->extra |
| 134 | 136 | ); |
| 135 | 137 | |
| 138 | + } else { |
|
| 139 | + return null; |
|
| 136 | 140 | } |
| 137 | - else return null; |
|
| 138 | 141 | |
| 139 | 142 | } |
| 140 | 143 | |
@@ -117,9 +117,9 @@ discard block |
||
| 117 | 117 | |
| 118 | 118 | public function load($routes) { |
| 119 | 119 | |
| 120 | - if ( !empty($routes) ) { |
|
| 120 | + if (!empty($routes)) { |
|
| 121 | 121 | |
| 122 | - foreach( $routes as $name => $route ) { |
|
| 122 | + foreach ($routes as $name => $route) { |
|
| 123 | 123 | |
| 124 | 124 | $this->add($route['route'], $route['type'], $route['class'], $route['parameters']); |
| 125 | 125 | |
@@ -135,7 +135,7 @@ discard block |
||
| 135 | 135 | |
| 136 | 136 | private function readCache() { |
| 137 | 137 | |
| 138 | - if ( $this->configuration()->get('routing-table-cache') !== true ) return; |
|
| 138 | + if ($this->configuration()->get('routing-table-cache') !== true) return; |
|
| 139 | 139 | |
| 140 | 140 | $this->routes = $this->cache->setNamespace('dispatcherinternals')->get("dispatcher-routes"); |
| 141 | 141 | |
@@ -147,7 +147,7 @@ discard block |
||
| 147 | 147 | |
| 148 | 148 | private function dumpCache() { |
| 149 | 149 | |
| 150 | - if ( $this->configuration()->get('routing-table-cache') !== true ) return; |
|
| 150 | + if ($this->configuration()->get('routing-table-cache') !== true) return; |
|
| 151 | 151 | |
| 152 | 152 | $ttl = $this->configuration()->get('routing-table-ttl'); |
| 153 | 153 | |
@@ -166,14 +166,14 @@ discard block |
||
| 166 | 166 | ->setClassName($class) // Class to be invoked |
| 167 | 167 | ->setParameters($parameters); // Parameters passed via the composer.json configuration (cache, ttl, etc...) |
| 168 | 168 | |
| 169 | - $this->logger->debug("ROUTE: " . implode("/", $folders)); |
|
| 169 | + $this->logger->debug("ROUTE: ".implode("/", $folders)); |
|
| 170 | 170 | |
| 171 | 171 | //$this->logger->debug("PARAMETERS: " . var_export($value, true)); |
| 172 | 172 | |
| 173 | 173 | // This method generate a global regular expression which will be able to match all the URI supported by the route |
| 174 | 174 | $regex = $this->parser->read($folders, $route); |
| 175 | 175 | |
| 176 | - $this->logger->debug("ROUTE: " . $regex); |
|
| 176 | + $this->logger->debug("ROUTE: ".$regex); |
|
| 177 | 177 | |
| 178 | 178 | //$this->logger->debug("PARAMETERS: " . var_export($value, true)); |
| 179 | 179 | |