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