1 | <?php |
---|
2 | // TODO GPLのあれ |
---|
3 | class SC_Response{ |
---|
4 | |
---|
5 | /** |
---|
6 | * |
---|
7 | * @var HTTP_Response |
---|
8 | */ |
---|
9 | var $http; |
---|
10 | /** |
---|
11 | * コンテンツタイプ |
---|
12 | * Enter description here ... |
---|
13 | * @var unknown_type |
---|
14 | */ |
---|
15 | var $contentType; |
---|
16 | var $body; |
---|
17 | var $statuscode; |
---|
18 | var $header = array(); |
---|
19 | |
---|
20 | var $statusTexts = array( |
---|
21 | '100' => 'Continue', |
---|
22 | '101' => 'Switching Protocols', |
---|
23 | '200' => 'OK', |
---|
24 | '201' => 'Created', |
---|
25 | '202' => 'Accepted', |
---|
26 | '203' => 'Non-Authoritative Information', |
---|
27 | '204' => 'No Content', |
---|
28 | '205' => 'Reset Content', |
---|
29 | '206' => 'Partial Content', |
---|
30 | '300' => 'Multiple Choices', |
---|
31 | '301' => 'Moved Permanently', |
---|
32 | '302' => 'Found', |
---|
33 | '303' => 'See Other', |
---|
34 | '304' => 'Not Modified', |
---|
35 | '305' => 'Use Proxy', |
---|
36 | '306' => '(Unused)', |
---|
37 | '307' => 'Temporary Redirect', |
---|
38 | '400' => 'Bad Request', |
---|
39 | '401' => 'Unauthorized', |
---|
40 | '402' => 'Payment Required', |
---|
41 | '403' => 'Forbidden', |
---|
42 | '404' => 'Not Found', |
---|
43 | '405' => 'Method Not Allowed', |
---|
44 | '406' => 'Not Acceptable', |
---|
45 | '407' => 'Proxy Authentication Required', |
---|
46 | '408' => 'Request Timeout', |
---|
47 | '409' => 'Conflict', |
---|
48 | '410' => 'Gone', |
---|
49 | '411' => 'Length Required', |
---|
50 | '412' => 'Precondition Failed', |
---|
51 | '413' => 'Request Entity Too Large', |
---|
52 | '414' => 'Request-URI Too Long', |
---|
53 | '415' => 'Unsupported Media Type', |
---|
54 | '416' => 'Requested Range Not Satisfiable', |
---|
55 | '417' => 'Expectation Failed', |
---|
56 | '500' => 'Internal Server Error', |
---|
57 | '501' => 'Not Implemented', |
---|
58 | '502' => 'Bad Gateway', |
---|
59 | '503' => 'Service Unavailable', |
---|
60 | '504' => 'Gateway Timeout', |
---|
61 | '505' => 'HTTP Version Not Supported', |
---|
62 | ); |
---|
63 | |
---|
64 | |
---|
65 | /** |
---|
66 | * |
---|
67 | * Enter description here ... |
---|
68 | */ |
---|
69 | var $encoding; |
---|
70 | |
---|
71 | function SC_Response(){ |
---|
72 | } |
---|
73 | |
---|
74 | function response(){ |
---|
75 | $this->sendHeader(); |
---|
76 | |
---|
77 | echo $this->body; |
---|
78 | } |
---|
79 | |
---|
80 | function sendHeader(){ |
---|
81 | // HTTPのヘッダ |
---|
82 | // header('HTTP/1.1 '.$this->statuscode.' '.$this->statusTexts[$this->statuscode]); |
---|
83 | foreach ($this->header as $name => $head){ |
---|
84 | header($name.': '.$head); |
---|
85 | } |
---|
86 | } |
---|
87 | |
---|
88 | |
---|
89 | function setContentType($contentType){ |
---|
90 | $this->header['Content-Type'] = $contentType; |
---|
91 | } |
---|
92 | |
---|
93 | function setResposeBody($body){ |
---|
94 | $this->body = $body; |
---|
95 | } |
---|
96 | |
---|
97 | /* function addDateHdeader($name, $date){ |
---|
98 | * |
---|
99 | * } |
---|
100 | */ |
---|
101 | |
---|
102 | function addHeader($name, $value){ |
---|
103 | $this->header[$name] = $value; |
---|
104 | } |
---|
105 | |
---|
106 | function containsHeader($name){ |
---|
107 | return isset($this->header[$name]); |
---|
108 | } |
---|
109 | |
---|
110 | function sendError($errorcode){ |
---|
111 | header('HTTP/1.1 '.$errorcode.' '.$this->statusTexts[$errorcode]); |
---|
112 | } |
---|
113 | |
---|
114 | function sendRedirect($location){ |
---|
115 | if (preg_match("/(" . preg_quote(SITE_URL, '/') |
---|
116 | . "|" . preg_quote(SSL_URL, '/') . ")/", $location)) { |
---|
117 | |
---|
118 | $netURL = new Net_URL($location); |
---|
119 | if (!empty($_SERVER['QUERY_STRING'])) { |
---|
120 | $netURL->addRawQueryString($_SERVER['QUERY_STRING']); |
---|
121 | } |
---|
122 | |
---|
123 | $session = SC_SessionFactory::getInstance(); |
---|
124 | if (SC_MobileUserAgent::isMobile() || $session->useCookie() == false) { |
---|
125 | $netURL->addQueryString(session_name(), session_id()); |
---|
126 | } |
---|
127 | |
---|
128 | $netURL->addQueryString(TRANSACTION_ID_NAME, SC_Helper_Session_Ex::getToken()); |
---|
129 | header("Location: " . $netURL->getURL()); |
---|
130 | exit; |
---|
131 | } |
---|
132 | return false; |
---|
133 | } |
---|
134 | |
---|
135 | function reload($queryString = array(), $removeQueryString = false) { |
---|
136 | // 現在の URL を取得 |
---|
137 | $netURL = new Net_URL($_SERVER['REQUEST_URI']); |
---|
138 | |
---|
139 | if ($removeQueryString) { |
---|
140 | $netURL->querystring = array(); |
---|
141 | $_SERVER['QUERY_STRING'] = ''; // sendRedirect() での処理用らしい |
---|
142 | } |
---|
143 | |
---|
144 | // QueryString を付与 |
---|
145 | if (!empty($queryString)) { |
---|
146 | foreach ($queryString as $key => $val) { |
---|
147 | $netURL->addQueryString($key, $val); |
---|
148 | } |
---|
149 | } |
---|
150 | |
---|
151 | $this->sendRedirect($netURL->getURL()); |
---|
152 | } |
---|
153 | |
---|
154 | function setHeader($headers){ |
---|
155 | $this->header = $headers; |
---|
156 | } |
---|
157 | |
---|
158 | function setStatus($sc = 202){ |
---|
159 | $this->statuscode = $sc; |
---|
160 | } |
---|
161 | |
---|
162 | } |
---|