This repository has been archived by the owner on Nov 9, 2017. It is now read-only.
/
Header.php
90 lines (79 loc) · 2 KB
/
Header.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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
<?php
/**
* For the full copyright and license information, please view the LICENSE file
* that was distributed with this source code.
*
* @copyright ©Talus, Talus' Works 2010+
* @link http://www.talus-works.net Talus' Works
* @license http://www.opensource.org/licenses/BSD-3-Clause Modified BSD License
* @version $Id$
*/
namespace Http;
/**
* Represents a Header
*
* @author Baptiste "Talus" Clavié <clavie.b@gmail.com>
* @package twk.http
*/
class Header {
protected
$_header = null,
$_value = null,
$_replace = false,
$_status = Response::CONTINU,
$_sent = false;
/**
* Construct this header
*
* @param string $_header Header to send
* @param string $_value Value of this header
* @param bool $_replace Does this header replace an already existing value ?
* @param int $_status Status code to be sent with this header
*/
function __construct($_header, $_value = null, $_replace = true, $_status = Response::OK) {
$this->_header = $_header;
$this->_value = $_value;
$this->_replace = $_replace;
$this->_status = $_status;
}
/**
* Sends the header
*
* @param bool $force forces the header to be sent... even if it was already sent
*/
public function send($force = false) {
if ($this->_sent === false || $force === true) {
$header = $this->_header . ': ' . $this->_value;
if ($this->_value === null) {
$header = $this->_header;
}
\Debug::info('Sending header (' . $header . ', ' . (int) $this->_replace . ', ' . $this->_status . ')');
\header($header, $this->_replace, $this->_status);
$this->_sent = true;
}
}
/**
* @ignore
*/
public function getHeader() {
return $this->_header;
}
/**
* @ignore
*/
public function getReplace() {
return $this->_replace;
}
/**
* @ignore
*/
public function getStatus() {
return $this->_status;
}
/**
* @ignore
*/
public function getValue() {
return $this->_value;
}
}