diff --git a/src/Aviat/AnimeClient/Controller.php b/src/Aviat/AnimeClient/Controller.php index 51801d70..dc39e98c 100644 --- a/src/Aviat/AnimeClient/Controller.php +++ b/src/Aviat/AnimeClient/Controller.php @@ -95,7 +95,11 @@ class Controller { $this->session = $session->getSegment(AnimeClient::SESSION_SEGMENT); // Set a 'previous' flash value for better redirects - $this->session->setFlash('previous', $this->request->getServerParams()['HTTP_REFERER']); + $server_params = $this->request->getServerParams(); + if (array_key_exists('HTTP_REFERER', $server_params)) + { + $this->session->setFlash('previous', $server_params['HTTP_REFERER']); + } // Set a message box if available $this->base_data['message'] = $this->session->getFlash('message'); @@ -274,7 +278,8 @@ class Controller { public function login_action() { $auth = $this->container->get('auth'); - if ($auth->authenticate($this->request->post->get('password'))) + $post = $this->request->getParsedBody(); + if ($auth->authenticate($post['password'])) { return $this->session_redirect(); } diff --git a/src/Aviat/AnimeClient/Controller/Anime.php b/src/Aviat/AnimeClient/Controller/Anime.php index e1654982..e156fe81 100644 --- a/src/Aviat/AnimeClient/Controller/Anime.php +++ b/src/Aviat/AnimeClient/Controller/Anime.php @@ -144,7 +144,7 @@ class Anime extends BaseController { */ public function add() { - $data = $this->request->post->get(); + $data = $this->request->getParsedBody(); if ( ! array_key_exists('id', $data)) { $this->redirect("anime/add", 303); @@ -216,7 +216,7 @@ class Anime extends BaseController { */ public function form_update() { - $post_data = $this->request->post->get(); + $post_data = $this->request->getParsedBody(); // Do some minor data manipulation for // large form-based updates @@ -247,7 +247,7 @@ class Anime extends BaseController { */ public function update() { - $response = $this->model->update($this->request->post->get()); + $response = $this->model->update($this->request->getParsedBody()); $this->outputJSON($response['body'], $response['statusCode']); } @@ -256,7 +256,7 @@ class Anime extends BaseController { */ public function delete() { - $response = $this->model->update($this->request->post->get()); + $response = $this->model->update($this->request->getParsedBody()); $this->outputJSON($response['body'], $response['statusCode']); } diff --git a/src/Aviat/AnimeClient/Controller/Collection.php b/src/Aviat/AnimeClient/Controller/Collection.php index 8b31a0f7..a3b6ed3e 100644 --- a/src/Aviat/AnimeClient/Controller/Collection.php +++ b/src/Aviat/AnimeClient/Controller/Collection.php @@ -130,7 +130,7 @@ class Collection extends BaseController { */ public function edit() { - $data = $this->request->post->get(); + $data = $this->request->getParsedBody(); if (array_key_exists('hummingbird_id', $data)) { $this->anime_collection_model->update($data); @@ -151,7 +151,7 @@ class Collection extends BaseController { */ public function add() { - $data = $this->request->post->get(); + $data = $this->request->getParsedBody(); if (array_key_exists('id', $data)) { $this->anime_collection_model->add($data); @@ -172,7 +172,7 @@ class Collection extends BaseController { */ public function delete() { - $data = $this->request->post->get(); + $data = $this->request->getParsedBody(); if ( ! array_key_exists('id', $data)) { $this->redirect("collection/view", 303); diff --git a/src/Aviat/AnimeClient/Controller/Manga.php b/src/Aviat/AnimeClient/Controller/Manga.php index e6bc8207..d0080544 100644 --- a/src/Aviat/AnimeClient/Controller/Manga.php +++ b/src/Aviat/AnimeClient/Controller/Manga.php @@ -127,7 +127,7 @@ class Manga extends Controller { */ public function add() { - $data = $this->request->post->get(); + $data = $this->request->getParsedBody(); if ( ! array_key_exists('id', $data)) { $this->redirect("manga/add", 303); @@ -176,8 +176,8 @@ class Manga extends Controller { */ public function search() { - $query = $this->request->query->get('query'); - $this->outputJSON($this->model->search($query)); + $query_data = $this->request->getQueryParams(); + $this->outputJSON($this->model->search($query_data['query'])); } /** @@ -187,7 +187,7 @@ class Manga extends Controller { */ public function form_update() { - $post_data = $this->request->post->get(); + $post_data = $this->request->getParsedBody(); // Do some minor data manipulation for // large form-based updates @@ -221,7 +221,7 @@ class Manga extends Controller { */ public function update() { - $result = $this->model->update($this->request->post->get()); + $result = $this->model->update($this->request->getParsedBody()); $this->outputJSON($result['body'], $result['statusCode']); } } diff --git a/src/Aviat/AnimeClient/Dispatcher.php b/src/Aviat/AnimeClient/Dispatcher.php index 598f70d7..837152c9 100644 --- a/src/Aviat/AnimeClient/Dispatcher.php +++ b/src/Aviat/AnimeClient/Dispatcher.php @@ -262,7 +262,7 @@ class Dispatcher extends RoutingBase { protected function get_error_params() { $logger = $this->container->getLogger('default'); - $failure = $this->router->getFailedRoute(); + $failure = $this->matcher->getFailedRoute(); $logger->info('Dispatcher - failed route'); $logger->info(print_r($failure, TRUE)); @@ -271,26 +271,27 @@ class Dispatcher extends RoutingBase { $params = []; - if ($failure->failedMethod()) - { - $params = [ - 'http_code' => 405, - 'title' => '405 Method Not Allowed', - 'message' => 'Invalid HTTP Verb' - ]; - } - else if ($failure->failedAccept()) - { - $params = [ - 'http_code' => 406, - 'title' => '406 Not Acceptable', - 'message' => 'Unacceptable content type' - ]; - } - else - { - // Fall back to a 404 message - $action_method = AnimeClient::NOT_FOUND_METHOD; + switch($failure->failedRule) { + case 'Aura\Router\Rule\Alows': + $params = [ + 'http_code' => 405, + 'title' => '405 Method Not Allowed', + 'message' => 'Invalid HTTP Verb' + ]; + break; + + case 'Aura\Router\Rule\Accepts': + $params = [ + 'http_code' => 406, + 'title' => '406 Not Acceptable', + 'message' => 'Unacceptable content type' + ]; + break; + + default: + // Fall back to a 404 message + $action_method = AnimeClient::NOT_FOUND_METHOD; + break; } return [ @@ -334,19 +335,19 @@ class Dispatcher extends RoutingBase { : "get"; // Add the route to the router object - //if ( ! array_key_exists('tokens', $route)) + if ( ! array_key_exists('tokens', $route)) { - $routes[] = $this->router->$add($name, $path);//->addValues($route); + $routes[] = $this->router->$add($name, $path)->defaults($route); } - /*else + else { $tokens = $route['tokens']; unset($route['tokens']); $routes[] = $this->router->$add($name, $path) - ->addValues($route) - ->addTokens($tokens); - }*/ + ->defaults($route) + ->tokens($tokens); + } } return $routes; diff --git a/src/Aviat/Ion/View/HttpView.php b/src/Aviat/Ion/View/HttpView.php index 5466b1f2..06f2d1fc 100644 --- a/src/Aviat/Ion/View/HttpView.php +++ b/src/Aviat/Ion/View/HttpView.php @@ -12,6 +12,7 @@ namespace Aviat\Ion\View; +use Zend\Diactoros\Response; use Zend\Diactoros\Response\SapiEmitter; use Aviat\Ion\View as BaseView; @@ -29,8 +30,15 @@ class HttpView extends BaseView { */ public function redirect($url, $code) { - $this->response->withStatus($code); - $this->response->withHeader('Location', $url); + ob_start(); + $response = new Response(); + $message = $response->getReasonPhrase($code); + + header("HTTP/1.1 ${code} ${message}"); + header("Location: {$url}"); + + $this->hasRendered = TRUE; + ob_end_clean(); } /** @@ -41,8 +49,8 @@ class HttpView extends BaseView { */ public function setStatusCode($code) { - $this->response->withStatus($code); - $this->response->withProtocolVersion(1.1); + $this->response->withStatus($code) + ->withProtocolVersion(1.1); return $this; }