Further refactor handling of request variables, routing works again

This commit is contained in:
Timothy Warren 2016-02-17 11:36:37 -05:00
parent ab19e9db08
commit dd74e85626
6 changed files with 59 additions and 45 deletions

View File

@ -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();
}

View File

@ -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']);
}

View File

@ -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);

View File

@ -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']);
}
}

View File

@ -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())
{
switch($failure->failedRule) {
case 'Aura\Router\Rule\Alows':
$params = [
'http_code' => 405,
'title' => '405 Method Not Allowed',
'message' => 'Invalid HTTP Verb'
];
}
else if ($failure->failedAccept())
{
break;
case 'Aura\Router\Rule\Accepts':
$params = [
'http_code' => 406,
'title' => '406 Not Acceptable',
'message' => 'Unacceptable content type'
];
}
else
{
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;

View File

@ -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;
}