@@ -64,7 +64,7 @@ |
||
| 64 | 64 | } |
| 65 | 65 | |
| 66 | 66 | /** |
| 67 | - * @param $regex |
|
| 67 | + * @param string $regex |
|
| 68 | 68 | * @return bool |
| 69 | 69 | */ |
| 70 | 70 | private function routeMatch($regex) |
@@ -86,7 +86,7 @@ discard block |
||
| 86 | 86 | */ |
| 87 | 87 | private function generateTarget() |
| 88 | 88 | {
|
| 89 | - if(is_callable($this->request['path'])){
|
|
| 89 | + if (is_callable($this->request['path'])) {
|
|
| 90 | 90 | $this->router->route->setCallback($this->request['path']); |
| 91 | 91 | $this->router->route->setDetail($this->request); |
| 92 | 92 | $this->anonymous(); |
@@ -99,10 +99,10 @@ discard block |
||
| 99 | 99 | ? $this->router->route->setCallback($this->request['path']['use']) |
| 100 | 100 | : $this->router->route->setCallback($this->request['path']); |
| 101 | 101 | $this->router->route->setDetail($this->request); |
| 102 | - if($this->validMethod()) {
|
|
| 103 | - $this->anonymous();$this->mvc();$this->template(); |
|
| 102 | + if ($this->validMethod()) {
|
|
| 103 | + $this->anonymous(); $this->mvc(); $this->template(); |
|
| 104 | 104 | $this->router->route->setResponse(['code' => 202, 'message' => 'Accepted']); |
| 105 | - }else |
|
| 105 | + } else |
|
| 106 | 106 | $this->router->route->setResponse(['code' => 405, 'message' => 'Method Not Allowed']); |
| 107 | 107 | } |
| 108 | 108 | return $this->router->route->hasTarget(); |
@@ -144,7 +144,7 @@ discard block |
||
| 144 | 144 | $index = isset($this->request['index']) ? $this->request['index'] : 0; |
| 145 | 145 | $class = (class_exists($routes[0])) |
| 146 | 146 | ? $routes[0] |
| 147 | - : $this->router->collection->getRoutes()['namespace_'.$index].$routes[0]; |
|
| 147 | + : $this->router->collection->getRoutes()['namespace_' . $index] . $routes[0]; |
|
| 148 | 148 | if (!class_exists($class)) |
| 149 | 149 | throw new \Exception('Class "' . $class . '." is not found');
|
| 150 | 150 | if (method_exists($class, $routes[1])) {
|
@@ -167,23 +167,23 @@ discard block |
||
| 167 | 167 | $extension = explode('.', $path);
|
| 168 | 168 | $extension = end($extension); |
| 169 | 169 | $index = isset($this->request['index']) ? $this->request['index'] : 0; |
| 170 | - $block = $this->router->collection->getRoutes('path_'.$index);
|
|
| 170 | + $block = $this->router->collection->getRoutes('path_' . $index);
|
|
| 171 | 171 | if (in_array('.' . $extension, $this->router->getConfig()['viewExtension'])) {
|
| 172 | 172 | if (is_file($block . $path)) {
|
| 173 | 173 | $target = $block . $path; |
| 174 | - $this->router->route->setTarget(['dispatcher' => 'JetFire\Routing\Dispatcher\TemplateDispatcher', 'template' => $target,'block' => $block, 'extension' => $extension]); |
|
| 174 | + $this->router->route->setTarget(['dispatcher' => 'JetFire\Routing\Dispatcher\TemplateDispatcher', 'template' => $target, 'block' => $block, 'extension' => $extension]); |
|
| 175 | 175 | return true; |
| 176 | 176 | } |
| 177 | 177 | throw new \Exception('Template file "' . $path . '" is not found in "' . $block . '"');
|
| 178 | 178 | } else {
|
| 179 | 179 | foreach ($this->router->getConfig()['viewExtension'] as $ext) {
|
| 180 | - if (is_file($block . $path . $ext)){
|
|
| 180 | + if (is_file($block . $path . $ext)) {
|
|
| 181 | 181 | $target = $block . $path . $ext; |
| 182 | - $this->router->route->setTarget(['dispatcher' => 'JetFire\Routing\Dispatcher\TemplateDispatcher', 'template' => $target,'block' => $block, 'extension' => str_replace('.', '', $ext)]);
|
|
| 182 | + $this->router->route->setTarget(['dispatcher' => 'JetFire\Routing\Dispatcher\TemplateDispatcher', 'template' => $target, 'block' => $block, 'extension' => str_replace('.', '', $ext)]);
|
|
| 183 | 183 | return true; |
| 184 | 184 | } |
| 185 | 185 | } |
| 186 | - throw new \Exception('Template file "' . $path . '" is not found in "' .$block . '"');
|
|
| 186 | + throw new \Exception('Template file "' . $path . '" is not found in "' . $block . '"');
|
|
| 187 | 187 | } |
| 188 | 188 | } |
| 189 | 189 | return false; |
@@ -76,7 +76,7 @@ discard block |
||
| 76 | 76 | } |
| 77 | 77 | |
| 78 | 78 | /** |
| 79 | - * @param $url |
|
| 79 | + * @param string $url |
|
| 80 | 80 | */ |
| 81 | 81 | public function setUrl($url) |
| 82 | 82 | {
|
@@ -116,7 +116,7 @@ discard block |
||
| 116 | 116 | } |
| 117 | 117 | |
| 118 | 118 | /** |
| 119 | - * @param null $key |
|
| 119 | + * @param string $key |
|
| 120 | 120 | * @return int |
| 121 | 121 | */ |
| 122 | 122 | public function getResponse($key = null) |
@@ -139,7 +139,7 @@ discard block |
||
| 139 | 139 | } |
| 140 | 140 | |
| 141 | 141 | /** |
| 142 | - * @return array |
|
| 142 | + * @return string |
|
| 143 | 143 | */ |
| 144 | 144 | public function getMethod() |
| 145 | 145 | {
|
@@ -163,7 +163,7 @@ discard block |
||
| 163 | 163 | } |
| 164 | 164 | |
| 165 | 165 | /** |
| 166 | - * @param $key |
|
| 166 | + * @param string $key |
|
| 167 | 167 | * @param $value |
| 168 | 168 | */ |
| 169 | 169 | public function addDetail($key, $value) |
@@ -172,7 +172,7 @@ discard block |
||
| 172 | 172 | } |
| 173 | 173 | |
| 174 | 174 | /** |
| 175 | - * @param null $key |
|
| 175 | + * @param string $key |
|
| 176 | 176 | * @return array|null |
| 177 | 177 | */ |
| 178 | 178 | public function getTarget($key = null) |
@@ -205,8 +205,8 @@ |
||
| 205 | 205 | /** |
| 206 | 206 | * @return array |
| 207 | 207 | */ |
| 208 | - public function getData(){
|
|
| 209 | - return (isset($this->getDetail()['data']) && is_array($this->getDetail()['data']))?$this->getDetail()['data']:[]; |
|
| 208 | + public function getData() {
|
|
| 209 | + return (isset($this->getDetail()['data']) && is_array($this->getDetail()['data'])) ? $this->getDetail()['data'] : []; |
|
| 210 | 210 | } |
| 211 | 211 | |
| 212 | 212 | /** |
@@ -43,9 +43,9 @@ discard block |
||
| 43 | 43 | {
|
| 44 | 44 | foreach ($this->router->getConfig()['viewExtension'] as $extension) {
|
| 45 | 45 | for ($i = 0; $i < $this->router->collection->countRoutes; ++$i) {
|
| 46 | - $url = explode('/', str_replace($this->router->collection->getRoutes('prefix_' . $i), '',$this->router->route->getUrl()));
|
|
| 46 | + $url = explode('/', str_replace($this->router->collection->getRoutes('prefix_' . $i), '', $this->router->route->getUrl()));
|
|
| 47 | 47 | $end = array_pop($url); |
| 48 | - $url = implode('/', array_map('ucwords', $url)).'/'.$end;
|
|
| 48 | + $url = implode('/', array_map('ucwords', $url)) . '/' . $end;
|
|
| 49 | 49 | if (is_file(($template = rtrim($this->router->collection->getRoutes('path_' . $i), '/') . $url . $extension))) {
|
| 50 | 50 | $this->router->route->setTarget(['dispatcher' => 'JetFire\Routing\Dispatcher\TemplateDispatcher', 'template' => $template, 'extension' => str_replace('.', '', $extension)]);
|
| 51 | 51 | $this->router->route->addDetail('block', $this->router->collection->getRoutes('path_' . $i));
|
@@ -63,12 +63,12 @@ discard block |
||
| 63 | 63 | {
|
| 64 | 64 | $routes = array_slice(explode('/', $this->router->route->getUrl()), 1);
|
| 65 | 65 | $i = 0; |
| 66 | - do{
|
|
| 67 | - $route = ('/' . $routes[0] == $this->router->collection->getRoutes('prefix_' . $i))
|
|
| 66 | + do {
|
|
| 67 | + $route = ('/' . $routes[0] == $this->router->collection->getRoutes('prefix_' . $i))
|
|
| 68 | 68 | ? array_slice($routes, 1) : $routes; |
| 69 | 69 | if (isset($route[0])) {
|
| 70 | - $class = (class_exists($this->router->collection->getRoutes('namespace_' . $i). ucfirst($route[0]) . 'Controller'))
|
|
| 71 | - ? $this->router->collection->getRoutes('namespace_' . $i). ucfirst($route[0]) . 'Controller'
|
|
| 70 | + $class = (class_exists($this->router->collection->getRoutes('namespace_' . $i) . ucfirst($route[0]) . 'Controller'))
|
|
| 71 | + ? $this->router->collection->getRoutes('namespace_' . $i) . ucfirst($route[0]) . 'Controller'
|
|
| 72 | 72 | : ucfirst($route[0]) . 'Controller'; |
| 73 | 73 | if (isset($route[1]) && method_exists($class, $route[1])) {
|
| 74 | 74 | $this->router->route->setTarget(['dispatcher' => 'JetFire\Routing\Dispatcher\MvcDispatcher', 'controller' => $class, 'action' => $route[1]]); |
@@ -77,7 +77,7 @@ discard block |
||
| 77 | 77 | } |
| 78 | 78 | } |
| 79 | 79 | ++$i; |
| 80 | - }while($i < $this->router->collection->countRoutes); |
|
| 80 | + }while ($i < $this->router->collection->countRoutes); |
|
| 81 | 81 | return false; |
| 82 | 82 | } |
| 83 | 83 | |
@@ -42,11 +42,11 @@ discard block |
||
| 42 | 42 | */ |
| 43 | 43 | public function addRoutes($routes = null, $options = []) |
| 44 | 44 | {
|
| 45 | - if(!is_null($routes) && !is_array($routes)) {
|
|
| 45 | + if (!is_null($routes) && !is_array($routes)) {
|
|
| 46 | 46 | if (strpos($routes, '.php') === false) $routes = trim($routes, '/') . '/'; |
| 47 | 47 | if (is_file($routes . '/routes.php') && is_array($routesFile = include $routes . '/routes.php')) $routes = $routesFile; |
| 48 | 48 | elseif (is_file($routes) && is_array($routesFile = include $routes)) $routes = $routesFile; |
| 49 | - else throw new \InvalidArgumentException('Argument for "' . get_called_class() . '" constructor is not recognized. Expected argument array or file containing array but "'.$routes.'" given');
|
|
| 49 | + else throw new \InvalidArgumentException('Argument for "' . get_called_class() . '" constructor is not recognized. Expected argument array or file containing array but "' . $routes . '" given');
|
|
| 50 | 50 | } |
| 51 | 51 | $this->routes['routes_' . $this->countRoutes] = is_array($routes) ? $routes : []; |
| 52 | 52 | $this->routes['path_' . $this->countRoutes] = (isset($options['path']) && !empty($options['path'])) ? rtrim($options['path'], '/') . '/' : ''; |
@@ -61,8 +61,8 @@ discard block |
||
| 61 | 61 | */ |
| 62 | 62 | public function getRoutes($key = null) |
| 63 | 63 | {
|
| 64 | - if(!is_null($key)) |
|
| 65 | - return isset($this->routes[$key])?$this->routes[$key]:''; |
|
| 64 | + if (!is_null($key)) |
|
| 65 | + return isset($this->routes[$key]) ? $this->routes[$key] : ''; |
|
| 66 | 66 | return $this->routes; |
| 67 | 67 | } |
| 68 | 68 | |
@@ -78,7 +78,7 @@ discard block |
||
| 78 | 78 | } elseif (is_string($args)) |
| 79 | 79 | for ($i = 0; $i < $this->countRoutes; ++$i) |
| 80 | 80 | $this->routes['prefix_' . $i] = '/' . trim($args, '/'); |
| 81 | - if($this->countRoutes == 0)$this->countRoutes++; |
|
| 81 | + if ($this->countRoutes == 0)$this->countRoutes++; |
|
| 82 | 82 | } |
| 83 | 83 | |
| 84 | 84 | /** |
@@ -88,14 +88,14 @@ discard block |
||
| 88 | 88 | {
|
| 89 | 89 | $nbrArgs = count($args); |
| 90 | 90 | for ($i = 0; $i < $nbrArgs; ++$i) {
|
| 91 | - if(is_array($args[$i])){
|
|
| 91 | + if (is_array($args[$i])) {
|
|
| 92 | 92 | $this->routes['path_' . $i] = (isset($args[$i]['path']) && !empty($args[$i]['path'])) ? rtrim($args[$i]['path'], '/') . '/' : ''; |
| 93 | 93 | $this->routes['namespace_' . $i] = (isset($args[$i]['namespace']) && !empty($args[$i]['namespace'])) ? trim($args[$i]['namespace'], '\\') . '\\' : ''; |
| 94 | - $this->routes['prefix_' . $i] = (isset($args[$i]['prefix']) && !empty($args[$i]['prefix'])) ? '/'.trim($args[$i]['prefix'], '/') : ''; |
|
| 95 | - if(!isset($this->routes['routes_' . $i]))$this->routes['routes_' . $i] = []; |
|
| 94 | + $this->routes['prefix_' . $i] = (isset($args[$i]['prefix']) && !empty($args[$i]['prefix'])) ? '/' . trim($args[$i]['prefix'], '/') : ''; |
|
| 95 | + if (!isset($this->routes['routes_' . $i]))$this->routes['routes_' . $i] = []; |
|
| 96 | 96 | } |
| 97 | 97 | } |
| 98 | - if($this->countRoutes == 0)$this->countRoutes++; |
|
| 98 | + if ($this->countRoutes == 0)$this->countRoutes++; |
|
| 99 | 99 | } |
| 100 | 100 | |
| 101 | 101 | /** |