Fix http verb for update route, add correct http codes for http errors

This commit is contained in:
Timothy Warren 2016-01-07 20:48:18 -05:00
parent ae4530b5d2
commit 45b04105f1
7 changed files with 59 additions and 47 deletions

View File

@ -99,7 +99,6 @@ return [
'login' => [
'path' => '/{controller}/login',
'action' => 'login',
'verb' => 'get'
],
'login_post' => [
'path' => '/{controller}/login',
@ -113,6 +112,7 @@ return [
'update' => [
'path' => '/{controller}/update',
'action' => 'update',
'verb' => 'post',
'tokens' => [
'controller' => '[a-z_]+'
]

View File

@ -1,5 +1,5 @@
<main>
<h1><?= $title ?></h1>
<h2><?= $message ?></h2>
<div><?= $log_message ?></div>
<div><?= $long_message ?></div>
</main>

View File

@ -1,6 +1,6 @@
sonar.projectKey=animeclient
sonar.projectName=Anime Client
sonar.projectVersion=2.0.0
sonar.projectVersion=2.1.0
sonar.sources=src
sonar.php.coverage.reportPath=build/logs/clover.xml
sonar.php.tests.reportPath=build/logs/junit.xml

View File

@ -306,24 +306,25 @@ class Controller {
{
$this->outputHTML('404', [
'title' => 'Sorry, page not found'
]);
], NULL, 404);
}
/**
* Display a generic error page
*
* @param int $http_code
* @param string $title
* @param string $message
* @param string $long_message
* @return void
*/
public function error_page($title, $message, $long_message = "")
public function error_page($http_code, $title, $message, $long_message = "")
{
$this->outputHTML('error', [
'title' => $title,
'message' => $message,
'long_message' => $long_message
]);
], NULL, $http_code);
}
/**
@ -365,15 +366,17 @@ class Controller {
* @param string $template
* @param array $data
* @param HtmlView|null $view
* @param int $code
* @return void
*/
protected function outputHTML($template, array $data = [], $view = NULL)
protected function outputHTML($template, array $data = [], $view = NULL, $code = 200)
{
if (is_null($view))
{
$view = new HtmlView($this->container);
}
$view->setStatusCode($code);
$this->render_full_page($view, $template, $data);
}

View File

@ -113,11 +113,13 @@ class Dispatcher extends RoutingBase {
switch(TRUE)
{
case $failure->failedMethod():
$params['http_code'] = 405;
$params['title'] = '405 Method Not Allowed';
$params['message'] = 'Invalid HTTP Verb';
break;
case $failure->failedAccept():
$params['http_code'] = 406;
$params['title'] = '406 Not Acceptable';
$params['message'] = 'Unacceptable content type';
break;

View File

@ -124,23 +124,6 @@ abstract class View {
/**
* Send output to client
*/
public function send()
{
$this->hasRendered = TRUE;
$this->output();
}
/**
* Send the appropriate response
*
* @return void
*/
protected function output()
{
$content =& $this->response->content;
$content->set($this->output);
$content->setType($this->contentType);
$content->setCharset('utf-8');
}
abstract public function send();
}
// End of View.php

View File

@ -33,15 +33,39 @@ class HttpView extends BaseView {
$this->response->redirect->to($url, $code);
}
/**
* Set the status code of the request
*
* @param int $code
* @return HttpView
*/
public function setStatusCode($code)
{
$this->response->status->setCode($code);
$this->response->status->setVersion(1.1);
return $this;
}
/**
* Send output to client
*/
public function send()
{
$this->hasRendered = TRUE;
$this->output();
}
/**
* Send the appropriate response
*
* @codeCoverageIgnore
* @return void
*/
protected function output()
{
parent::output();
$content =& $this->response->content;
$content->set($this->output);
$content->setType($this->contentType);
$content->setCharset('utf-8');
$sender = new ResponseSender($this->response);
$sender->__invoke();