diff --git a/Dispatcher/Dispatcher.php b/Dispatcher/Dispatcher.php index 90b75aef8..2a25839d6 100644 --- a/Dispatcher/Dispatcher.php +++ b/Dispatcher/Dispatcher.php @@ -115,14 +115,15 @@ class Dispatcher */ private function dispatchString(string $controller, RequestAbstract $request, ResponseAbstract $response, $data = null) : array { - $views =[]; + $views = []; $dispatch = explode(':', $controller); $this->getController($dispatch[0]); - if (($c = count($dispatch)) == 3) { + if (($c = count($dispatch)) === 3) { /* Handling static functions */ - $views[$controller] = $dispatch[0]::$dispatch[2](); - } elseif ($c == 2) { + $function = $dispatch[0] . '::' . $dispatch[2]; + $views[$controller] = $function($request, $response, $data); + } elseif ($c === 2) { $views[$controller] = $this->controllers[$dispatch[0]]->{$dispatch[1]}($request, $response, $data); } else { throw new \UnexpectedValueException('Unexpected function.'); @@ -215,7 +216,7 @@ class Dispatcher return true; } - + return false; } } diff --git a/Message/Http/Request.php b/Message/Http/Request.php index 8b5d24c68..9a986c5a7 100644 --- a/Message/Http/Request.php +++ b/Message/Http/Request.php @@ -144,6 +144,7 @@ class Request extends RequestAbstract private function initCurrentRequest() { $this->data = $_GET ?? []; + $this->files = $_FILES ?? []; if (isset($_SERVER['CONTENT_TYPE'])) { if (strpos($_SERVER['CONTENT_TYPE'], 'application/json') !== false) { @@ -155,8 +156,6 @@ class Request extends RequestAbstract } elseif (strpos($_SERVER['CONTENT_TYPE'], 'application/x-www-form-urlencoded') !== false) { parse_str(file_get_contents('php://input'), $temp); $this->data += $temp; - } elseif (strpos($_SERVER['CONTENT_TYPE'], 'multipart/form-data') !== false) { - $this->files = $_FILES; } } diff --git a/Router/Router.php b/Router/Router.php index a3ce9d256..185b55a87 100644 --- a/Router/Router.php +++ b/Router/Router.php @@ -59,7 +59,7 @@ class Router * @since 1.0.0 * @author Dennis Eichhorn */ - public function importFromFile(string $path) + public function importFromFile(string $path) { /** @noinspection PhpIncludeInspection */ $this->routes += include $path; @@ -69,8 +69,8 @@ class Router * Add route. * * @param string $route Route regex - * @param mixed $destination Destination e.g. Module:function & verb - * @param string $verb Request verb + * @param mixed $destination Destination e.g. Module:function & verb + * @param string $verb Request verb * * @return void * @@ -80,7 +80,7 @@ class Router public function add(string $route, $destination, string $verb = RouteVerb::GET) { $this->routes[$route][] = [ - 'dest' => $destination, + 'dest' => $destination, 'verb' => $verb, ]; } @@ -112,9 +112,9 @@ class Router /** * Match route and uri. * - * @param string $route Route - * @param string $routeVerb GET,POST for this route - * @param string $uri Uri + * @param string $route Route + * @param string $routeVerb GET,POST for this route + * @param string $uri Uri * @param string $remoteVerb Verb this request is using * * @return bool