1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Util |
4
|
|
|
* |
5
|
|
|
* @copyright Copyright (c) Gjero Krsteski (http://krsteski.de) |
6
|
|
|
* @license http://opensource.org/licenses/MIT MIT License |
7
|
|
|
*/ |
8
|
|
|
namespace Pimf\Util\Header; |
9
|
|
|
|
10
|
|
|
/** |
11
|
|
|
* Manages a raw HTTP header ResponseStatus sending. |
12
|
|
|
* |
13
|
|
|
* @package Util_Header |
14
|
|
|
* @author Gjero Krsteski <[email protected]> |
15
|
|
|
*/ |
16
|
|
|
abstract class ResponseStatus |
17
|
|
|
{ |
18
|
|
|
/** |
19
|
|
|
* Name and revision of the information protocol |
20
|
|
|
* |
21
|
|
|
* @var string |
22
|
|
|
*/ |
23
|
|
|
public static $protocol; |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* @param string $protocol |
27
|
|
|
*/ |
28
|
|
|
public static function setup($protocol) |
29
|
|
|
{ |
30
|
|
|
self::$protocol = $protocol; |
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* @param int $code HTTP response code |
35
|
|
|
* @param string $status The header string which will be used to figure out the HTTP status code to send. |
36
|
|
|
* @param bool $replace Whether the header should replace a previous similar header. |
37
|
|
|
*/ |
38
|
|
|
public static function send($code, $status, $replace = true) |
39
|
|
|
{ |
40
|
|
|
header('' . self::$protocol . ' ' . $code . ' ' . $status, $replace, $code); |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
public static function sendXFrameDeny() |
44
|
|
|
{ |
45
|
|
|
header('X-Frame-Options: DENY'); |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
public static function sendXFrameSameOrigin() |
49
|
|
|
{ |
50
|
|
|
header('X-Frame-Options: SAMEORIGIN'); |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
public static function sendContinue() |
54
|
|
|
{ |
55
|
|
|
self::send(100, 'Continue'); |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
public static function sendProcessing() |
59
|
|
|
{ |
60
|
|
|
self::send(102, 'Processing'); |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
public static function sendOK() |
64
|
|
|
{ |
65
|
|
|
self::send(200, 'OK'); |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
public static function sendCreated() |
69
|
|
|
{ |
70
|
|
|
self::send(201, 'Created'); |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
public static function sendAccepted() |
74
|
|
|
{ |
75
|
|
|
self::send(202, 'Accepted'); |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
public static function sendNoAuthInfo() |
79
|
|
|
{ |
80
|
|
|
self::send(203, 'Non-Authoritative Information'); |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
public static function sendNoContent() |
84
|
|
|
{ |
85
|
|
|
self::send(204, 'No Content'); |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
public static function sendMovedPermanently() |
89
|
|
|
{ |
90
|
|
|
self::send(301, 'Moved Permanently'); |
91
|
|
|
} |
92
|
|
|
|
93
|
|
|
public static function sendFound() |
94
|
|
|
{ |
95
|
|
|
self::send(302, 'Found'); |
96
|
|
|
} |
97
|
|
|
|
98
|
|
|
public static function sendNotModified() |
99
|
|
|
{ |
100
|
|
|
self::send(304, 'Not Modified'); |
101
|
|
|
} |
102
|
|
|
|
103
|
|
|
public static function sendTemporaryRedirect() |
104
|
|
|
{ |
105
|
|
|
self::send(307, 'Temporary Redirect'); |
106
|
|
|
} |
107
|
|
|
|
108
|
|
|
public static function sendBadRequest() |
109
|
|
|
{ |
110
|
|
|
self::send(400, 'Bad Request'); |
111
|
|
|
} |
112
|
|
|
|
113
|
|
|
public static function sendUnauthorized() |
114
|
|
|
{ |
115
|
|
|
self::send(401, 'Unauthorized'); |
116
|
|
|
} |
117
|
|
|
|
118
|
|
|
public static function sendPaymentRequired() |
119
|
|
|
{ |
120
|
|
|
self::send(402, 'Payment Required'); |
121
|
|
|
} |
122
|
|
|
|
123
|
|
|
public static function sendForbidden() |
124
|
|
|
{ |
125
|
|
|
self::send(403, 'Forbidden'); |
126
|
|
|
} |
127
|
|
|
|
128
|
|
|
public static function sendNotFound() |
129
|
|
|
{ |
130
|
|
|
self::send(404, 'Not Found'); |
131
|
|
|
} |
132
|
|
|
|
133
|
|
|
public static function sendMethodNotAllowed() |
134
|
|
|
{ |
135
|
|
|
self::send(405, 'Method Not Allowed'); |
136
|
|
|
} |
137
|
|
|
|
138
|
|
|
public static function sendNotAcceptable() |
139
|
|
|
{ |
140
|
|
|
self::send(406, 'Not Acceptable'); |
141
|
|
|
} |
142
|
|
|
|
143
|
|
|
public static function sendProxyAuthRequired() |
144
|
|
|
{ |
145
|
|
|
self::send(407, 'Proxy Authentication Required'); |
146
|
|
|
} |
147
|
|
|
|
148
|
|
|
public static function sendRequestTimeout() |
149
|
|
|
{ |
150
|
|
|
self::send(408, 'Request Timeout'); |
151
|
|
|
} |
152
|
|
|
|
153
|
|
|
public static function sendConflict() |
154
|
|
|
{ |
155
|
|
|
self::send(409, 'Conflict'); |
156
|
|
|
} |
157
|
|
|
|
158
|
|
|
public static function sendUnsupportedMediaType() |
159
|
|
|
{ |
160
|
|
|
self::send(415, 'Unsupported Media Type'); |
161
|
|
|
} |
162
|
|
|
|
163
|
|
|
public static function sendLocked() |
164
|
|
|
{ |
165
|
|
|
self::send(423, 'Locked'); |
166
|
|
|
} |
167
|
|
|
|
168
|
|
|
public static function sendServiceUnavailable() |
169
|
|
|
{ |
170
|
|
|
self::send(503, 'Service Unavailable'); |
171
|
|
|
} |
172
|
|
|
} |
173
|
|
|
|