-
Notifications
You must be signed in to change notification settings - Fork 175
/
Error.php
67 lines (61 loc) · 2.03 KB
/
Error.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
<?php
/**
* This file implements a HTTP error, a simple wrapper which provide
* a html response using smarthy templates. It rely on the Diactoros implementation
* of the Response object to provide the reason phrase according to the status code.
*
* PHP Version 7
*
* @category PSR7
* @package Http
* @author Xavier Lecours Boucher <xavier.lecoursboucher@mcgill.ca>
* @license http://www.gnu.org/licenses/gpl-3.0.txt GPLv3
* @link https://www.github.com/aces/Loris/
*
* @see https://www.php-fig.org/psr/psr-7/
*/
namespace LORIS\Http;
use \Zend\Diactoros\Response\HtmlResponse;
use \Psr\Http\Message\ServerRequestInterface;
/**
* A html representation of a http error
*
* @category PSR7
* @package Http
* @author Xavier Lecours Boucher <xavier.lecoursboucher@mcgill.ca>
* @license http://www.gnu.org/licenses/gpl-3.0.txt GPLv3
* @link https://www.github.com/aces/Loris/
*/
class Error extends HtmlResponse
{
/**
* Takes the status code and and use the Zend\Response constructor to provide
* the approcriate reason phrase. It also add the appropriate body using
* smarty templates based on status code.
*
* @param ServerRequestInterface $request this HTTP request.
* @param int $status The HTTP status code to use.
* @param string $message A value to pass to smarty template
*/
public function __construct(
ServerRequestInterface $request,
int $status,
string $message = ''
) {
$uri = $request->getURI();
$baseurl = $uri->getScheme() .'://'. $uri->getAuthority();
$tpl_data = array(
'message' => $message,
'baseurl' => $baseurl,
);
$template_file = (string) $status . '.tpl';
$body = (new \Smarty_neurodb())
->assign($tpl_data)
->fetch($template_file);
parent::__construct(
(new \LORIS\Http\StringStream($body)),
$status,
array()
);
}
}