Version 5.1 - All the GraphQL #32

Closed
timw4mail wants to merge 1160 commits from develop into master
7 changed files with 59 additions and 47 deletions
Showing only changes of commit 27ac7e8063 - Show all commits

View File

@ -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_]+'
] ]

View File

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

View File

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

View File

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

View File

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

View File

@ -72,7 +72,7 @@ abstract class View {
{ {
$this->send(); $this->send();
} }
} }
/** /**
* Return rendered output * Return rendered output
@ -119,28 +119,11 @@ abstract class View {
public function getOutput() public function getOutput()
{ {
return $this->string($this->output)->__toString(); return $this->string($this->output)->__toString();
} }
/** /**
* 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

View File

@ -31,20 +31,44 @@ class HttpView extends BaseView {
public function redirect($url, $code) public function redirect($url, $code)
{ {
$this->response->redirect->to($url, $code); $this->response->redirect->to($url, $code);
} }
/** /**
* Send the appropriate response * Set the status code of the request
* *
* @codeCoverageIgnore * @param int $code
* @return void * @return HttpView
*/ */
protected function output() public function setStatusCode($code)
{ {
parent::output(); $this->response->status->setCode($code);
$this->response->status->setVersion(1.1);
$sender = new ResponseSender($this->response); return $this;
$sender->__invoke(); }
}
/**
* 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');
$sender = new ResponseSender($this->response);
$sender->__invoke();
}
} }