1
|
|
|
<?php namespace Comodojo\Dispatcher\Response; |
2
|
|
|
|
3
|
|
|
use \Exception; |
4
|
|
|
|
5
|
|
|
/** |
6
|
|
|
* @package Comodojo Dispatcher |
7
|
|
|
* @author Marco Giovinazzi <[email protected]> |
8
|
|
|
* @author Marco Castiello <[email protected]> |
9
|
|
|
* @license GPL-3.0+ |
10
|
|
|
* |
11
|
|
|
* LICENSE: |
12
|
|
|
* |
13
|
|
|
* This program is free software: you can redistribute it and/or modify |
14
|
|
|
* it under the terms of the GNU Affero General Public License as |
15
|
|
|
* published by the Free Software Foundation, either version 3 of the |
16
|
|
|
* License, or (at your option) any later version. |
17
|
|
|
* |
18
|
|
|
* This program is distributed in the hope that it will be useful, |
19
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
20
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
21
|
|
|
* GNU Affero General Public License for more details. |
22
|
|
|
* |
23
|
|
|
* You should have received a copy of the GNU Affero General Public License |
24
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>. |
25
|
|
|
*/ |
26
|
|
|
|
27
|
|
|
class Content { |
28
|
|
|
|
29
|
|
|
private $content; |
30
|
|
|
|
31
|
|
|
private $type = "text/plain"; |
32
|
|
|
|
33
|
|
|
private $charset = "utf-8"; |
34
|
|
|
|
35
|
|
|
public function get() { |
36
|
|
|
|
37
|
|
|
return $this->content; |
38
|
|
|
|
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
public function set($content) { |
42
|
|
|
|
43
|
|
|
if ( !is_scalar($content) ) { |
44
|
|
|
|
45
|
|
|
throw new Exception("Invalid HTTP content"); |
46
|
|
|
|
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
$this->content = $content; |
50
|
|
|
|
51
|
|
|
return $this; |
52
|
|
|
|
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
public function type($type = null) { |
56
|
|
|
|
57
|
|
|
if ( is_null($type) ) { |
58
|
|
|
|
59
|
|
|
return $this->type; |
60
|
|
|
|
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
$this->type = $type; |
64
|
|
|
|
65
|
|
|
return $this; |
66
|
|
|
|
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
public function charset($charset = null) { |
70
|
|
|
|
71
|
|
|
if ( is_null($charset) ) { |
72
|
|
|
|
73
|
|
|
return $this->charset; |
74
|
|
|
|
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
$this->charset = $charset; |
78
|
|
|
|
79
|
|
|
return $this; |
80
|
|
|
|
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
public function length() { |
84
|
|
|
|
85
|
|
|
return sizeof($this->content); |
86
|
|
|
|
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
} |
90
|
|
|
|