Fix http verb for update route, add correct http codes for http errors
This commit is contained in:
parent
ae4530b5d2
commit
45b04105f1
@ -99,7 +99,6 @@ return [
|
|||||||
'login' => [
|
'login' => [
|
||||||
'path' => '/{controller}/login',
|
'path' => '/{controller}/login',
|
||||||
'action' => 'login',
|
'action' => 'login',
|
||||||
'verb' => 'get'
|
|
||||||
],
|
],
|
||||||
'login_post' => [
|
'login_post' => [
|
||||||
'path' => '/{controller}/login',
|
'path' => '/{controller}/login',
|
||||||
@ -113,6 +112,7 @@ return [
|
|||||||
'update' => [
|
'update' => [
|
||||||
'path' => '/{controller}/update',
|
'path' => '/{controller}/update',
|
||||||
'action' => 'update',
|
'action' => 'update',
|
||||||
|
'verb' => 'post',
|
||||||
'tokens' => [
|
'tokens' => [
|
||||||
'controller' => '[a-z_]+'
|
'controller' => '[a-z_]+'
|
||||||
]
|
]
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
<main>
|
<main>
|
||||||
<h1><?= $title ?></h1>
|
<h1><?= $title ?></h1>
|
||||||
<h2><?= $message ?></h2>
|
<h2><?= $message ?></h2>
|
||||||
<div><?= $log_message ?></div>
|
<div><?= $long_message ?></div>
|
||||||
</main>
|
</main>
|
@ -1,6 +1,6 @@
|
|||||||
sonar.projectKey=animeclient
|
sonar.projectKey=animeclient
|
||||||
sonar.projectName=Anime Client
|
sonar.projectName=Anime Client
|
||||||
sonar.projectVersion=2.0.0
|
sonar.projectVersion=2.1.0
|
||||||
sonar.sources=src
|
sonar.sources=src
|
||||||
sonar.php.coverage.reportPath=build/logs/clover.xml
|
sonar.php.coverage.reportPath=build/logs/clover.xml
|
||||||
sonar.php.tests.reportPath=build/logs/junit.xml
|
sonar.php.tests.reportPath=build/logs/junit.xml
|
@ -306,24 +306,25 @@ class Controller {
|
|||||||
{
|
{
|
||||||
$this->outputHTML('404', [
|
$this->outputHTML('404', [
|
||||||
'title' => 'Sorry, page not found'
|
'title' => 'Sorry, page not found'
|
||||||
]);
|
], NULL, 404);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Display a generic error page
|
* Display a generic error page
|
||||||
*
|
*
|
||||||
|
* @param int $http_code
|
||||||
* @param string $title
|
* @param string $title
|
||||||
* @param string $message
|
* @param string $message
|
||||||
* @param string $long_message
|
* @param string $long_message
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function error_page($title, $message, $long_message = "")
|
public function error_page($http_code, $title, $message, $long_message = "")
|
||||||
{
|
{
|
||||||
$this->outputHTML('error', [
|
$this->outputHTML('error', [
|
||||||
'title' => $title,
|
'title' => $title,
|
||||||
'message' => $message,
|
'message' => $message,
|
||||||
'long_message' => $long_message
|
'long_message' => $long_message
|
||||||
]);
|
], NULL, $http_code);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -365,15 +366,17 @@ class Controller {
|
|||||||
* @param string $template
|
* @param string $template
|
||||||
* @param array $data
|
* @param array $data
|
||||||
* @param HtmlView|null $view
|
* @param HtmlView|null $view
|
||||||
|
* @param int $code
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
protected function outputHTML($template, array $data = [], $view = NULL)
|
protected function outputHTML($template, array $data = [], $view = NULL, $code = 200)
|
||||||
{
|
{
|
||||||
if (is_null($view))
|
if (is_null($view))
|
||||||
{
|
{
|
||||||
$view = new HtmlView($this->container);
|
$view = new HtmlView($this->container);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$view->setStatusCode($code);
|
||||||
$this->render_full_page($view, $template, $data);
|
$this->render_full_page($view, $template, $data);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -113,11 +113,13 @@ class Dispatcher extends RoutingBase {
|
|||||||
switch(TRUE)
|
switch(TRUE)
|
||||||
{
|
{
|
||||||
case $failure->failedMethod():
|
case $failure->failedMethod():
|
||||||
|
$params['http_code'] = 405;
|
||||||
$params['title'] = '405 Method Not Allowed';
|
$params['title'] = '405 Method Not Allowed';
|
||||||
$params['message'] = 'Invalid HTTP Verb';
|
$params['message'] = 'Invalid HTTP Verb';
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case $failure->failedAccept():
|
case $failure->failedAccept():
|
||||||
|
$params['http_code'] = 406;
|
||||||
$params['title'] = '406 Not Acceptable';
|
$params['title'] = '406 Not Acceptable';
|
||||||
$params['message'] = 'Unacceptable content type';
|
$params['message'] = 'Unacceptable content type';
|
||||||
break;
|
break;
|
||||||
|
@ -124,23 +124,6 @@ abstract class View {
|
|||||||
/**
|
/**
|
||||||
* Send output to client
|
* Send output to client
|
||||||
*/
|
*/
|
||||||
public function send()
|
abstract 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');
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
// End of View.php
|
// End of View.php
|
@ -33,15 +33,39 @@ class HttpView extends BaseView {
|
|||||||
$this->response->redirect->to($url, $code);
|
$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
|
* Send the appropriate response
|
||||||
*
|
*
|
||||||
* @codeCoverageIgnore
|
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
protected function output()
|
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 = new ResponseSender($this->response);
|
||||||
$sender->__invoke();
|
$sender->__invoke();
|
||||||
|
Loading…
Reference in New Issue
Block a user