jsOMS response fixes and formatting

This commit is contained in:
Dennis Eichhorn 2016-05-03 20:52:00 +02:00
parent 02e5185e74
commit 292ac8d739
3 changed files with 14 additions and 14 deletions

View File

@ -115,14 +115,15 @@ class Dispatcher
*/ */
private function dispatchString(string $controller, RequestAbstract $request, ResponseAbstract $response, $data = null) : array private function dispatchString(string $controller, RequestAbstract $request, ResponseAbstract $response, $data = null) : array
{ {
$views =[]; $views = [];
$dispatch = explode(':', $controller); $dispatch = explode(':', $controller);
$this->getController($dispatch[0]); $this->getController($dispatch[0]);
if (($c = count($dispatch)) == 3) { if (($c = count($dispatch)) === 3) {
/* Handling static functions */ /* Handling static functions */
$views[$controller] = $dispatch[0]::$dispatch[2](); $function = $dispatch[0] . '::' . $dispatch[2];
} elseif ($c == 2) { $views[$controller] = $function($request, $response, $data);
} elseif ($c === 2) {
$views[$controller] = $this->controllers[$dispatch[0]]->{$dispatch[1]}($request, $response, $data); $views[$controller] = $this->controllers[$dispatch[0]]->{$dispatch[1]}($request, $response, $data);
} else { } else {
throw new \UnexpectedValueException('Unexpected function.'); throw new \UnexpectedValueException('Unexpected function.');

View File

@ -144,6 +144,7 @@ class Request extends RequestAbstract
private function initCurrentRequest() private function initCurrentRequest()
{ {
$this->data = $_GET ?? []; $this->data = $_GET ?? [];
$this->files = $_FILES ?? [];
if (isset($_SERVER['CONTENT_TYPE'])) { if (isset($_SERVER['CONTENT_TYPE'])) {
if (strpos($_SERVER['CONTENT_TYPE'], 'application/json') !== false) { 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) { } elseif (strpos($_SERVER['CONTENT_TYPE'], 'application/x-www-form-urlencoded') !== false) {
parse_str(file_get_contents('php://input'), $temp); parse_str(file_get_contents('php://input'), $temp);
$this->data += $temp; $this->data += $temp;
} elseif (strpos($_SERVER['CONTENT_TYPE'], 'multipart/form-data') !== false) {
$this->files = $_FILES;
} }
} }

View File

@ -69,8 +69,8 @@ class Router
* Add route. * Add route.
* *
* @param string $route Route regex * @param string $route Route regex
* @param mixed $destination Destination e.g. Module:function & verb * @param mixed $destination Destination e.g. Module:function & verb
* @param string $verb Request verb * @param string $verb Request verb
* *
* @return void * @return void
* *
@ -80,7 +80,7 @@ class Router
public function add(string $route, $destination, string $verb = RouteVerb::GET) public function add(string $route, $destination, string $verb = RouteVerb::GET)
{ {
$this->routes[$route][] = [ $this->routes[$route][] = [
'dest' => $destination, 'dest' => $destination,
'verb' => $verb, 'verb' => $verb,
]; ];
} }
@ -112,9 +112,9 @@ class Router
/** /**
* Match route and uri. * Match route and uri.
* *
* @param string $route Route * @param string $route Route
* @param string $routeVerb GET,POST for this route * @param string $routeVerb GET,POST for this route
* @param string $uri Uri * @param string $uri Uri
* @param string $remoteVerb Verb this request is using * @param string $remoteVerb Verb this request is using
* *
* @return bool * @return bool