| 1 | <?php |
|---|
| 2 | /* |
|---|
| 3 | * This file is part of EC-CUBE |
|---|
| 4 | * |
|---|
| 5 | * Copyright(c) 2000-2010 LOCKON CO.,LTD. All Rights Reserved. |
|---|
| 6 | * |
|---|
| 7 | * http://www.lockon.co.jp/ |
|---|
| 8 | * |
|---|
| 9 | * This program is free software; you can redistribute it and/or |
|---|
| 10 | * modify it under the terms of the GNU General Public License |
|---|
| 11 | * as published by the Free Software Foundation; either version 2 |
|---|
| 12 | * of the License, or (at your option) any later version. |
|---|
| 13 | * |
|---|
| 14 | * This program is distributed in the hope that it will be useful, |
|---|
| 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|---|
| 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|---|
| 17 | * GNU General Public License for more details. |
|---|
| 18 | * |
|---|
| 19 | * You should have received a copy of the GNU General Public License |
|---|
| 20 | * along with this program; if not, write to the Free Software |
|---|
| 21 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
|---|
| 22 | */ |
|---|
| 23 | |
|---|
| 24 | /** |
|---|
| 25 | * HttpResponse を扱うクラス. |
|---|
| 26 | * |
|---|
| 27 | * @author Ryuichi Tokugami |
|---|
| 28 | * @version $Id$ |
|---|
| 29 | */ |
|---|
| 30 | class SC_Response{ |
|---|
| 31 | |
|---|
| 32 | /** |
|---|
| 33 | * コンテンツタイプ |
|---|
| 34 | * Enter description here ... |
|---|
| 35 | * @var unknown_type |
|---|
| 36 | */ |
|---|
| 37 | var $contentType; |
|---|
| 38 | var $body; |
|---|
| 39 | var $statuscode; |
|---|
| 40 | var $header = array(); |
|---|
| 41 | |
|---|
| 42 | var $statusTexts = array( |
|---|
| 43 | '100' => 'Continue', |
|---|
| 44 | '101' => 'Switching Protocols', |
|---|
| 45 | '200' => 'OK', |
|---|
| 46 | '201' => 'Created', |
|---|
| 47 | '202' => 'Accepted', |
|---|
| 48 | '203' => 'Non-Authoritative Information', |
|---|
| 49 | '204' => 'No Content', |
|---|
| 50 | '205' => 'Reset Content', |
|---|
| 51 | '206' => 'Partial Content', |
|---|
| 52 | '300' => 'Multiple Choices', |
|---|
| 53 | '301' => 'Moved Permanently', |
|---|
| 54 | '302' => 'Found', |
|---|
| 55 | '303' => 'See Other', |
|---|
| 56 | '304' => 'Not Modified', |
|---|
| 57 | '305' => 'Use Proxy', |
|---|
| 58 | '306' => '(Unused)', |
|---|
| 59 | '307' => 'Temporary Redirect', |
|---|
| 60 | '400' => 'Bad Request', |
|---|
| 61 | '401' => 'Unauthorized', |
|---|
| 62 | '402' => 'Payment Required', |
|---|
| 63 | '403' => 'Forbidden', |
|---|
| 64 | '404' => 'Not Found', |
|---|
| 65 | '405' => 'Method Not Allowed', |
|---|
| 66 | '406' => 'Not Acceptable', |
|---|
| 67 | '407' => 'Proxy Authentication Required', |
|---|
| 68 | '408' => 'Request Timeout', |
|---|
| 69 | '409' => 'Conflict', |
|---|
| 70 | '410' => 'Gone', |
|---|
| 71 | '411' => 'Length Required', |
|---|
| 72 | '412' => 'Precondition Failed', |
|---|
| 73 | '413' => 'Request Entity Too Large', |
|---|
| 74 | '414' => 'Request-URI Too Long', |
|---|
| 75 | '415' => 'Unsupported Media Type', |
|---|
| 76 | '416' => 'Requested Range Not Satisfiable', |
|---|
| 77 | '417' => 'Expectation Failed', |
|---|
| 78 | '500' => 'Internal Server Error', |
|---|
| 79 | '501' => 'Not Implemented', |
|---|
| 80 | '502' => 'Bad Gateway', |
|---|
| 81 | '503' => 'Service Unavailable', |
|---|
| 82 | '504' => 'Gateway Timeout', |
|---|
| 83 | '505' => 'HTTP Version Not Supported', |
|---|
| 84 | ); |
|---|
| 85 | |
|---|
| 86 | |
|---|
| 87 | /** |
|---|
| 88 | * |
|---|
| 89 | * Enter description here ... |
|---|
| 90 | */ |
|---|
| 91 | var $encoding; |
|---|
| 92 | |
|---|
| 93 | function SC_Response() { |
|---|
| 94 | } |
|---|
| 95 | |
|---|
| 96 | /** |
|---|
| 97 | * レスポンス出力を書き込む. |
|---|
| 98 | */ |
|---|
| 99 | function write() { |
|---|
| 100 | $this->sendHeader(); |
|---|
| 101 | echo $this->body; |
|---|
| 102 | } |
|---|
| 103 | |
|---|
| 104 | function sendHeader() { |
|---|
| 105 | // HTTPのヘッダ |
|---|
| 106 | // header('HTTP/1.1 '.$this->statuscode.' '.$this->statusTexts[$this->statuscode]); |
|---|
| 107 | foreach ($this->header as $name => $head){ |
|---|
| 108 | header($name.': '.$head); |
|---|
| 109 | } |
|---|
| 110 | } |
|---|
| 111 | |
|---|
| 112 | |
|---|
| 113 | function setContentType($contentType) { |
|---|
| 114 | $this->header['Content-Type'] = $contentType; |
|---|
| 115 | } |
|---|
| 116 | |
|---|
| 117 | function setResposeBody($body){ |
|---|
| 118 | $this->body = $body; |
|---|
| 119 | } |
|---|
| 120 | |
|---|
| 121 | function addHeader($name, $value) { |
|---|
| 122 | $this->header[$name] = $value; |
|---|
| 123 | } |
|---|
| 124 | |
|---|
| 125 | function containsHeader($name) { |
|---|
| 126 | return isset($this->header[$name]); |
|---|
| 127 | } |
|---|
| 128 | |
|---|
| 129 | function sendError($errorcode) { |
|---|
| 130 | header('HTTP/1.1 '.$errorcode.' '.$this->statusTexts[$errorcode]); |
|---|
| 131 | } |
|---|
| 132 | |
|---|
| 133 | function sendRedirect($location) { |
|---|
| 134 | if (preg_match("/(" . preg_quote(HTTP_URL, '/') |
|---|
| 135 | . "|" . preg_quote(HTTPS_URL, '/') . ")/", $location)) { |
|---|
| 136 | |
|---|
| 137 | $netURL = new Net_URL($location); |
|---|
| 138 | $arrQueryString = $netURL->querystring; |
|---|
| 139 | |
|---|
| 140 | if (!empty($_SERVER['QUERY_STRING'])) { |
|---|
| 141 | $netURL->addRawQueryString($_SERVER['QUERY_STRING']); |
|---|
| 142 | } |
|---|
| 143 | |
|---|
| 144 | foreach ($arrQueryString as $key => $val) { |
|---|
| 145 | $netURL->addQueryString($key, $val); |
|---|
| 146 | } |
|---|
| 147 | |
|---|
| 148 | $session = SC_SessionFactory::getInstance(); |
|---|
| 149 | if (SC_MobileUserAgent::isMobile() || $session->useCookie() == false) { |
|---|
| 150 | $netURL->addQueryString(session_name(), session_id()); |
|---|
| 151 | } |
|---|
| 152 | |
|---|
| 153 | $netURL->addQueryString(TRANSACTION_ID_NAME, SC_Helper_Session_Ex::getToken()); |
|---|
| 154 | header("Location: " . $netURL->getURL()); |
|---|
| 155 | exit; |
|---|
| 156 | } |
|---|
| 157 | return false; |
|---|
| 158 | } |
|---|
| 159 | |
|---|
| 160 | function reload($queryString = array(), $removeQueryString = false) { |
|---|
| 161 | // 現在の URL を取得 |
|---|
| 162 | $netURL = new Net_URL($_SERVER['REQUEST_URI']); |
|---|
| 163 | |
|---|
| 164 | if ($removeQueryString) { |
|---|
| 165 | $netURL->querystring = array(); |
|---|
| 166 | $_SERVER['QUERY_STRING'] = ''; // sendRedirect() での処理用らしい |
|---|
| 167 | } |
|---|
| 168 | |
|---|
| 169 | // QueryString を付与 |
|---|
| 170 | if (!empty($queryString)) { |
|---|
| 171 | foreach ($queryString as $key => $val) { |
|---|
| 172 | $netURL->addQueryString($key, $val); |
|---|
| 173 | } |
|---|
| 174 | } |
|---|
| 175 | |
|---|
| 176 | $this->sendRedirect($netURL->getURL()); |
|---|
| 177 | } |
|---|
| 178 | |
|---|
| 179 | function setHeader($headers) { |
|---|
| 180 | $this->header = $headers; |
|---|
| 181 | } |
|---|
| 182 | |
|---|
| 183 | function setStatus($sc = 202) { |
|---|
| 184 | $this->statuscode = $sc; |
|---|
| 185 | } |
|---|
| 186 | |
|---|
| 187 | } |
|---|