@@ -36,7 +36,7 @@ discard block |
||
| 36 | 36 | /** |
| 37 | 37 | * @param Route $route |
| 38 | 38 | */ |
| 39 | - public function __construct(Route $route,ResponseInterface $response) |
|
| 39 | + public function __construct(Route $route, ResponseInterface $response) |
|
| 40 | 40 | { |
| 41 | 41 | $this->route = $route; |
| 42 | 42 | $this->response = $response; |
@@ -53,8 +53,8 @@ discard block |
||
| 53 | 53 | $this->response->setContent(call_user_func_array($this->route->getTarget('callback')[$this->route->getTarget('extension')], [$this->route])); |
| 54 | 54 | else { |
| 55 | 55 | ob_start(); |
| 56 | - if(isset($this->route->getTarget()['data']))extract($this->route->getTarget('data')); |
|
| 57 | - if(isset($this->route->getParams()['data']))extract($this->route->getParams()['data']); |
|
| 56 | + if (isset($this->route->getTarget()['data']))extract($this->route->getTarget('data')); |
|
| 57 | + if (isset($this->route->getParams()['data']))extract($this->route->getParams()['data']); |
|
| 58 | 58 | require($this->route->getTarget('template')); |
| 59 | 59 | $this->response->setContent(ob_get_clean()); |
| 60 | 60 | } |
@@ -63,7 +63,7 @@ discard block |
||
| 63 | 63 | /** |
| 64 | 64 | * @param $extension |
| 65 | 65 | */ |
| 66 | - public function setContentType($extension){ |
|
| 66 | + public function setContentType($extension) { |
|
| 67 | 67 | $this->response->setStatusCode(200); |
| 68 | 68 | isset($this->types[$extension]) |
| 69 | 69 | ? $this->response->setHeaders(['Content-Type' => $this->types[$extension]]) |
@@ -47,14 +47,19 @@ |
||
| 47 | 47 | */ |
| 48 | 48 | public function call() |
| 49 | 49 | { |
| 50 | - if ($this->response->getStatusCode() == 202) |
|
| 51 | - $this->setContentType($this->route->getTarget('extension')); |
|
| 52 | - if (isset($this->route->getTarget('callback')[$this->route->getTarget('extension')])) |
|
| 53 | - $this->response->setContent(call_user_func_array($this->route->getTarget('callback')[$this->route->getTarget('extension')], [$this->route])); |
|
| 54 | - else { |
|
| 50 | + if ($this->response->getStatusCode() == 202) {
|
|
| 51 | + $this->setContentType($this->route->getTarget('extension'));
|
|
| 52 | + } |
|
| 53 | + if (isset($this->route->getTarget('callback')[$this->route->getTarget('extension')])) {
|
|
| 54 | + $this->response->setContent(call_user_func_array($this->route->getTarget('callback')[$this->route->getTarget('extension')], [$this->route]));
|
|
| 55 | + } else { |
|
| 55 | 56 | ob_start(); |
| 56 | - if(isset($this->route->getTarget()['data']))extract($this->route->getTarget('data')); |
|
| 57 | - if(isset($this->route->getParams()['data']))extract($this->route->getParams()['data']); |
|
| 57 | + if(isset($this->route->getTarget()['data'])) {
|
|
| 58 | + extract($this->route->getTarget('data'));
|
|
| 59 | + } |
|
| 60 | + if(isset($this->route->getParams()['data'])) {
|
|
| 61 | + extract($this->route->getParams()['data']); |
|
| 62 | + } |
|
| 58 | 63 | require($this->route->getTarget('template')); |
| 59 | 64 | $this->response->setContent(ob_get_clean()); |
| 60 | 65 | } |
@@ -32,7 +32,7 @@ discard block |
||
| 32 | 32 | private $dispatcher = [ |
| 33 | 33 | 'isTemplate' => 'JetFire\Routing\Dispatcher\TemplateDispatcher', |
| 34 | 34 | 'isController' => 'JetFire\Routing\Dispatcher\ControllerDispatcher', |
| 35 | - 'isControllerAndTemplate' => ['JetFire\Routing\Dispatcher\ControllerDispatcher','JetFire\Routing\Dispatcher\TemplateDispatcher'], |
|
| 35 | + 'isControllerAndTemplate' => ['JetFire\Routing\Dispatcher\ControllerDispatcher', 'JetFire\Routing\Dispatcher\TemplateDispatcher'], |
|
| 36 | 36 | ]; |
| 37 | 37 | |
| 38 | 38 | /** |
@@ -46,14 +46,14 @@ discard block |
||
| 46 | 46 | /** |
| 47 | 47 | * @param array $resolver |
| 48 | 48 | */ |
| 49 | - public function setResolver($resolver = []){ |
|
| 49 | + public function setResolver($resolver = []) { |
|
| 50 | 50 | $this->resolver = $resolver; |
| 51 | 51 | } |
| 52 | 52 | |
| 53 | 53 | /** |
| 54 | 54 | * @param string $resolver |
| 55 | 55 | */ |
| 56 | - public function addResolver($resolver){ |
|
| 56 | + public function addResolver($resolver) { |
|
| 57 | 57 | $this->resolver[] = $resolver; |
| 58 | 58 | } |
| 59 | 59 | |
@@ -78,7 +78,7 @@ discard block |
||
| 78 | 78 | * @param $class |
| 79 | 79 | * @return mixed|void |
| 80 | 80 | */ |
| 81 | - public function addDispatcher($method,$class){ |
|
| 81 | + public function addDispatcher($method, $class) { |
|
| 82 | 82 | $this->dispatcher[$method] = $class; |
| 83 | 83 | } |
| 84 | 84 | |
@@ -87,8 +87,8 @@ discard block |
||
| 87 | 87 | */ |
| 88 | 88 | public function match() |
| 89 | 89 | { |
| 90 | - foreach($this->resolver as $resolver){ |
|
| 91 | - if(is_array($target = call_user_func([$this,$resolver]))) { |
|
| 90 | + foreach ($this->resolver as $resolver) { |
|
| 91 | + if (is_array($target = call_user_func([$this, $resolver]))) { |
|
| 92 | 92 | $this->setTarget($target); |
| 93 | 93 | $this->router->response->setStatusCode(202); |
| 94 | 94 | return true; |
@@ -100,7 +100,7 @@ discard block |
||
| 100 | 100 | /** |
| 101 | 101 | * @param array $target |
| 102 | 102 | */ |
| 103 | - public function setTarget($target = []){ |
|
| 103 | + public function setTarget($target = []) { |
|
| 104 | 104 | $index = isset($this->request['collection_index']) ? $this->request['collection_index'] : 0; |
| 105 | 105 | $this->router->route->setDetail($this->request); |
| 106 | 106 | $this->router->route->setTarget($target); |
@@ -111,10 +111,10 @@ discard block |
||
| 111 | 111 | /** |
| 112 | 112 | * @return array|bool |
| 113 | 113 | */ |
| 114 | - public function isControllerAndTemplate(){ |
|
| 115 | - if(is_array($ctrl = $this->isController())) { |
|
| 114 | + public function isControllerAndTemplate() { |
|
| 115 | + if (is_array($ctrl = $this->isController())) { |
|
| 116 | 116 | if (is_array($tpl = $this->isTemplate())) { |
| 117 | - return array_merge(array_merge($ctrl, $tpl),[ |
|
| 117 | + return array_merge(array_merge($ctrl, $tpl), [ |
|
| 118 | 118 | 'dispatcher' => $this->dispatcher['isControllerAndTemplate'] |
| 119 | 119 | ]); |
| 120 | 120 | } |
@@ -130,10 +130,10 @@ discard block |
||
| 130 | 130 | { |
| 131 | 131 | foreach ($this->router->getConfig()['templateExtension'] as $extension) { |
| 132 | 132 | for ($i = 0; $i < $this->router->collection->countRoutes; ++$i) { |
| 133 | - $url = explode('/', str_replace($this->router->collection->getRoutes('prefix_' . $i), '',$this->router->route->getUrl())); |
|
| 133 | + $url = explode('/', str_replace($this->router->collection->getRoutes('prefix_'.$i), '', $this->router->route->getUrl())); |
|
| 134 | 134 | $end = array_pop($url); |
| 135 | 135 | $url = implode('/', array_map('ucwords', $url)).'/'.$end; |
| 136 | - if (is_file(($template = rtrim($this->router->collection->getRoutes('view_dir_' . $i), '/') . $url . $extension))) { |
|
| 136 | + if (is_file(($template = rtrim($this->router->collection->getRoutes('view_dir_'.$i), '/').$url.$extension))) { |
|
| 137 | 137 | $this->request['collection_index'] = $i; |
| 138 | 138 | return [ |
| 139 | 139 | 'dispatcher' => $this->dispatcher['isTemplate'], |
@@ -154,13 +154,13 @@ discard block |
||
| 154 | 154 | { |
| 155 | 155 | $routes = array_slice(explode('/', $this->router->route->getUrl()), 1); |
| 156 | 156 | $i = 0; |
| 157 | - do{ |
|
| 158 | - $route = ('/' . $routes[0] == $this->router->collection->getRoutes('prefix_' . $i)) ? array_slice($routes, 1) : $routes; |
|
| 157 | + do { |
|
| 158 | + $route = ('/'.$routes[0] == $this->router->collection->getRoutes('prefix_'.$i)) ? array_slice($routes, 1) : $routes; |
|
| 159 | 159 | if (isset($route[0])) { |
| 160 | - $class = (class_exists($this->router->collection->getRoutes('ctrl_namespace_' . $i). ucfirst($route[0]) . 'Controller')) |
|
| 161 | - ? $this->router->collection->getRoutes('ctrl_namespace_' . $i). ucfirst($route[0]) . 'Controller' |
|
| 162 | - : ucfirst($route[0]) . 'Controller'; |
|
| 163 | - $route[1] = isset($route[1])?$route[1]:'index'; |
|
| 160 | + $class = (class_exists($this->router->collection->getRoutes('ctrl_namespace_'.$i).ucfirst($route[0]).'Controller')) |
|
| 161 | + ? $this->router->collection->getRoutes('ctrl_namespace_'.$i).ucfirst($route[0]).'Controller' |
|
| 162 | + : ucfirst($route[0]).'Controller'; |
|
| 163 | + $route[1] = isset($route[1]) ? $route[1] : 'index'; |
|
| 164 | 164 | if (method_exists($class, $route[1])) { |
| 165 | 165 | $this->request['parameters'] = array_slice($route, 2); |
| 166 | 166 | $this->request['collection_index'] = $i; |
@@ -173,7 +173,7 @@ discard block |
||
| 173 | 173 | } |
| 174 | 174 | } |
| 175 | 175 | ++$i; |
| 176 | - }while($i < $this->router->collection->countRoutes); |
|
| 176 | + }while ($i < $this->router->collection->countRoutes); |
|
| 177 | 177 | return false; |
| 178 | 178 | } |
| 179 | 179 | |