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