| 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 | $this->http = new HTTP_Response(); |
|---|
| 72 | } |
|---|
| 73 | |
|---|
| 74 | function response(){ |
|---|
| 75 | $this->sendHeader(); |
|---|
| 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 sendRedirect(String $location){ |
|---|
| 110 | |
|---|
| 111 | } |
|---|
| 112 | |
|---|
| 113 | function setHeader(Array $headers){ |
|---|
| 114 | $this->header = $headers; |
|---|
| 115 | } |
|---|
| 116 | |
|---|
| 117 | function setStatus(int $sc = 202){ |
|---|
| 118 | $this->statuscode = $sc; |
|---|
| 119 | } |
|---|
| 120 | |
|---|
| 121 | } |
|---|