|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Jaxon\Response; |
|
4
|
|
|
|
|
5
|
|
|
abstract class AbstractResponse |
|
6
|
|
|
{ |
|
7
|
|
|
use \Jaxon\Features\Config; |
|
8
|
|
|
use \Jaxon\Features\Manager; |
|
9
|
|
|
|
|
10
|
|
|
/** |
|
11
|
|
|
* Get the content type, which is always set to 'text/json' |
|
12
|
|
|
* |
|
13
|
|
|
* @return string |
|
14
|
|
|
*/ |
|
15
|
|
|
abstract public function getContentType(); |
|
16
|
|
|
|
|
17
|
|
|
/** |
|
18
|
|
|
* Get the configured character encoding |
|
19
|
|
|
* |
|
20
|
|
|
* @return string |
|
21
|
|
|
*/ |
|
22
|
|
|
public function getCharacterEncoding() |
|
23
|
|
|
{ |
|
24
|
|
|
return trim($this->getOption('core.encoding')); |
|
25
|
|
|
} |
|
26
|
|
|
|
|
27
|
|
|
/** |
|
28
|
|
|
* Used internally to generate the response headers |
|
29
|
|
|
* |
|
30
|
|
|
* @return void |
|
31
|
|
|
*/ |
|
32
|
|
|
public function sendHeaders() |
|
33
|
|
|
{ |
|
34
|
|
|
if($this->getRequesthandler()->requestMethodIsGet()) |
|
35
|
|
|
{ |
|
36
|
|
|
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); |
|
37
|
|
|
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT"); |
|
38
|
|
|
header("Cache-Control: no-cache, must-revalidate"); |
|
39
|
|
|
header("Pragma: no-cache"); |
|
40
|
|
|
} |
|
41
|
|
|
|
|
42
|
|
|
$sCharacterSet = ''; |
|
43
|
|
|
$sCharacterEncoding = $this->getCharacterEncoding(); |
|
44
|
|
|
if(is_string($sCharacterEncoding) && strlen($sCharacterEncoding) > 0) |
|
45
|
|
|
{ |
|
46
|
|
|
$sCharacterSet = '; charset="' . $sCharacterEncoding . '"'; |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
header('content-type: ' . $this->getContentType() . ' ' . $sCharacterSet); |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
|
|
/** |
|
53
|
|
|
* Merge the response commands from the specified <Response> object with |
|
54
|
|
|
* the response commands in this <Response> object |
|
55
|
|
|
* |
|
56
|
|
|
* @param AbstractResponse $mCommands The <Response> object |
|
57
|
|
|
* @param boolean $bBefore Add the new commands to the beginning of the list |
|
58
|
|
|
* |
|
59
|
|
|
* @return void |
|
60
|
|
|
*/ |
|
61
|
|
|
public function appendResponse(AbstractResponse $mCommands, $bBefore = false) |
|
62
|
|
|
{ |
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
|
|
/** |
|
66
|
|
|
* Add a command to display a debug message to the user |
|
67
|
|
|
* |
|
68
|
|
|
* @param string $sMessage The message to be displayed |
|
69
|
|
|
* |
|
70
|
|
|
* @return AbstractResponse |
|
71
|
|
|
*/ |
|
72
|
|
|
abstract public function debug($sMessage); |
|
73
|
|
|
|
|
74
|
|
|
/** |
|
75
|
|
|
* Return the output, generated from the commands added to the response, that will be sent to the browser |
|
76
|
|
|
* |
|
77
|
|
|
* @return string |
|
78
|
|
|
*/ |
|
79
|
|
|
abstract public function getOutput(); |
|
80
|
|
|
|
|
81
|
|
|
/** |
|
82
|
|
|
* Print the output, generated from the commands added to the response, that will be sent to the browser |
|
83
|
|
|
* |
|
84
|
|
|
* @return void |
|
85
|
|
|
*/ |
|
86
|
|
|
public function printOutput() |
|
87
|
|
|
{ |
|
88
|
|
|
print $this->getOutput(); |
|
89
|
|
|
} |
|
90
|
|
|
} |
|
91
|
|
|
|