@@ -49,17 +49,21 @@ discard block |
||
| 49 | 49 | } |
| 50 | 50 | if($count == count($this->route->getParameters()) || ($this->route->getParameters() == '' && $count == 0)) { |
| 51 | 51 | $dependencies = array_merge($dependencies, ($this->route->getParameters() == '') ? [] : $this->route->getParameters()); |
| 52 | - if ($this->response->getStatusCode() == 202) |
|
| 53 | - $this->response->setStatusCode(200); |
|
| 52 | + if ($this->response->getStatusCode() == 202) {
|
|
| 53 | + $this->response->setStatusCode(200); |
|
| 54 | + } |
|
| 54 | 55 | if (is_array($content = $reflectionMethod->invokeArgs($this->getController(), $dependencies))){ |
| 55 | 56 | $this->route->addTarget('data', $content); |
| 56 | 57 | if(isset($this->route->getParams()['ajax']) && $this->route->getParams()['ajax'] == true){ |
| 57 | 58 | $this->response->setContent(json_encode($content)); |
| 58 | 59 | $this->response->setHeaders(['Content-Type' => 'application/json']); |
| 59 | 60 | } |
| 60 | - } elseif (!is_null($content)) $this->response->setContent($content); |
|
| 61 | - }else |
|
| 62 | - $this->response->setStatusCode(404); |
|
| 61 | + } elseif (!is_null($content)) {
|
|
| 62 | + $this->response->setContent($content); |
|
| 63 | + } |
|
| 64 | + } else {
|
|
| 65 | + $this->response->setStatusCode(404); |
|
| 66 | + } |
|
| 63 | 67 | } |
| 64 | 68 | |
| 65 | 69 | |
@@ -70,8 +74,9 @@ discard block |
||
| 70 | 74 | private function getController() |
| 71 | 75 | { |
| 72 | 76 | $reflector = new ReflectionClass($this->route->getTarget('controller')); |
| 73 | - if (!$reflector->isInstantiable()) |
|
| 74 | - throw new \Exception('Target [' . $this->route->getTarget('controller') . '] is not instantiable.'); |
|
| 77 | + if (!$reflector->isInstantiable()) {
|
|
| 78 | + throw new \Exception('Target [' . $this->route->getTarget('controller') . '] is not instantiable.');
|
|
| 79 | + } |
|
| 75 | 80 | $constructor = $reflector->getConstructor(); |
| 76 | 81 | if (is_null($constructor)) { |
| 77 | 82 | $class = $this->route->getTarget('controller'); |
@@ -27,7 +27,7 @@ discard block |
||
| 27 | 27 | /** |
| 28 | 28 | * @param Route $route |
| 29 | 29 | */ |
| 30 | - public function __construct(Route $route,ResponseInterface $response) |
|
| 30 | + public function __construct(Route $route, ResponseInterface $response) |
|
| 31 | 31 | { |
| 32 | 32 | $this->route = $route; |
| 33 | 33 | $this->response = $response; |
@@ -47,18 +47,18 @@ discard block |
||
| 47 | 47 | ? $count++ |
| 48 | 48 | : $dependencies[] = call_user_func_array($this->route->getTarget('di'), [$arg->getClass()->name]); |
| 49 | 49 | } |
| 50 | - if($count == count($this->route->getParameters()) || ($this->route->getParameters() == '' && $count == 0)) { |
|
| 50 | + if ($count == count($this->route->getParameters()) || ($this->route->getParameters() == '' && $count == 0)) { |
|
| 51 | 51 | $dependencies = array_merge($dependencies, ($this->route->getParameters() == '') ? [] : $this->route->getParameters()); |
| 52 | 52 | if ($this->response->getStatusCode() == 202) |
| 53 | 53 | $this->response->setStatusCode(200); |
| 54 | - if (is_array($content = $reflectionMethod->invokeArgs($this->getController(), $dependencies))){ |
|
| 54 | + if (is_array($content = $reflectionMethod->invokeArgs($this->getController(), $dependencies))) { |
|
| 55 | 55 | $this->route->addTarget('data', $content); |
| 56 | - if(isset($this->route->getParams()['ajax']) && $this->route->getParams()['ajax'] === true){ |
|
| 56 | + if (isset($this->route->getParams()['ajax']) && $this->route->getParams()['ajax'] === true) { |
|
| 57 | 57 | $this->response->setContent(json_encode($content)); |
| 58 | 58 | $this->response->setHeaders(['Content-Type' => 'application/json']); |
| 59 | 59 | } |
| 60 | 60 | } elseif (!is_null($content)) $this->response->setContent($content); |
| 61 | - }else |
|
| 61 | + } else |
|
| 62 | 62 | $this->response->setStatusCode(404); |
| 63 | 63 | } |
| 64 | 64 | |
@@ -71,17 +71,17 @@ discard block |
||
| 71 | 71 | { |
| 72 | 72 | $reflector = new ReflectionClass($this->route->getTarget('controller')); |
| 73 | 73 | if (!$reflector->isInstantiable()) |
| 74 | - throw new \Exception('Target [' . $this->route->getTarget('controller') . '] is not instantiable.'); |
|
| 74 | + throw new \Exception('Target ['.$this->route->getTarget('controller').'] is not instantiable.'); |
|
| 75 | 75 | $constructor = $reflector->getConstructor(); |
| 76 | 76 | if (is_null($constructor)) { |
| 77 | 77 | $class = $this->route->getTarget('controller'); |
| 78 | - return call_user_func_array($this->route->getTarget('di'),[$class]); |
|
| 78 | + return call_user_func_array($this->route->getTarget('di'), [$class]); |
|
| 79 | 79 | } |
| 80 | 80 | $dependencies = $constructor->getParameters(); |
| 81 | 81 | $arguments = []; |
| 82 | 82 | foreach ($dependencies as $dep) { |
| 83 | 83 | $class = $dep->getClass()->name; |
| 84 | - array_push($arguments, call_user_func_array($this->route->getTarget('di'),[$class])); |
|
| 84 | + array_push($arguments, call_user_func_array($this->route->getTarget('di'), [$class])); |
|
| 85 | 85 | } |
| 86 | 86 | return $reflector->newInstanceArgs($arguments); |
| 87 | 87 | } |
@@ -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 | } |