[ Index ] |
PHP Cross Reference of Unnamed Project |
[Summary view] [Print] [Text view]
1 <?php 2 // This file is part of Moodle - http://moodle.org/ 3 // 4 // Moodle is free software: you can redistribute it and/or modify 5 // it under the terms of the GNU General Public License as published by 6 // the Free Software Foundation, either version 3 of the License, or 7 // (at your option) any later version. 8 // 9 // Moodle is distributed in the hope that it will be useful, 10 // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 // GNU General Public License for more details. 13 // 14 // You should have received a copy of the GNU General Public License 15 // along with Moodle. If not, see <http://www.gnu.org/licenses/>. 16 17 /** 18 * This file contains an abstract definition of an LTI service 19 * 20 * @package mod_lti 21 * @copyright 2014 Vital Source Technologies http://vitalsource.com 22 * @author Stephen Vickers 23 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 24 */ 25 26 27 namespace mod_lti\local\ltiservice; 28 29 defined('MOODLE_INTERNAL') || die; 30 31 /** 32 * The mod_lti\local\ltiservice\response class. 33 * 34 * @package mod_lti 35 * @since Moodle 2.8 36 * @copyright 2014 Vital Source Technologies http://vitalsource.com 37 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 38 */ 39 class response { 40 41 /** @var int HTTP response code. */ 42 private $code; 43 /** @var string HTTP response reason. */ 44 private $reason; 45 /** @var string HTTP request method. */ 46 private $requestmethod; 47 /** @var string HTTP request accept header. */ 48 private $accept; 49 /** @var string HTTP response content type. */ 50 private $contenttype; 51 /** @var string HTTP request body. */ 52 private $data; 53 /** @var string HTTP response body. */ 54 private $body; 55 /** @var array HTTP response codes. */ 56 private $responsecodes; 57 58 /** 59 * Class constructor. 60 */ 61 public function __construct() { 62 63 $this->code = 200; 64 $this->reason = ''; 65 $this->requestmethod = $_SERVER['REQUEST_METHOD']; 66 $this->accept = ''; 67 $this->contenttype = ''; 68 $this->data = ''; 69 $this->body = ''; 70 $this->responsecodes = array( 71 200 => 'OK', 72 201 => 'Created', 73 202 => 'Accepted', 74 300 => 'Multiple Choices', 75 400 => 'Bad Request', 76 401 => 'Unauthorized', 77 402 => 'Payment Required', 78 403 => 'Forbidden', 79 404 => 'Not Found', 80 405 => 'Method Not Allowed', 81 406 => 'Not Acceptable', 82 415 => 'Unsupported Media Type', 83 500 => 'Internal Server Error', 84 501 => 'Not Implemented' 85 ); 86 87 } 88 89 /** 90 * Get the response code. 91 * 92 * @return int 93 */ 94 public function get_code() { 95 return $this->code; 96 } 97 98 /** 99 * Set the response code. 100 * 101 * @param int $code Response code 102 */ 103 public function set_code($code) { 104 $this->code = $code; 105 $this->reason = ''; 106 } 107 108 /** 109 * Get the response reason. 110 * 111 * @return string 112 */ 113 public function get_reason() { 114 if (empty($this->reason)) { 115 $this->reason = $this->responsecodes[$this->code]; 116 } 117 // Use generic reason for this category (based on first digit) if a specific reason is not defined. 118 if (empty($this->reason)) { 119 $this->reason = $this->responsecodes[intval($this->code / 100) * 100]; 120 } 121 return $this->reason; 122 } 123 124 /** 125 * Set the response reason. 126 * 127 * @param string $reason Reason 128 */ 129 public function set_reason($reason) { 130 $this->reason = $reason; 131 } 132 133 /** 134 * Get the request method. 135 * 136 * @return string 137 */ 138 public function get_request_method() { 139 return $this->requestmethod; 140 } 141 142 /** 143 * Get the request accept header. 144 * 145 * @return string 146 */ 147 public function get_accept() { 148 return $this->accept; 149 } 150 151 /** 152 * Set the request accept header. 153 * 154 * @param string $accept Accept header value 155 */ 156 public function set_accept($accept) { 157 $this->accept = $accept; 158 } 159 160 /** 161 * Get the response content type. 162 * 163 * @return string 164 */ 165 public function get_content_type() { 166 return $this->contenttype; 167 } 168 169 /** 170 * Set the response content type. 171 * 172 * @param string $contenttype Content type 173 */ 174 public function set_content_type($contenttype) { 175 $this->contenttype = $contenttype; 176 } 177 178 /** 179 * Get the request body. 180 * 181 * @return string 182 */ 183 public function get_request_data() { 184 return $this->data; 185 } 186 187 /** 188 * Set the response body. 189 * 190 * @param string $data Body data 191 */ 192 public function set_request_data($data) { 193 $this->data = $data; 194 } 195 196 /** 197 * Set the response body. 198 * 199 * @param string $body Body data 200 */ 201 public function set_body($body) { 202 $this->body = $body; 203 } 204 205 /** 206 * Send the response. 207 */ 208 public function send() { 209 header("HTTP/1.0 {$this->code} {$this->get_reason()}"); 210 if (($this->code >= 200) && ($this->code < 300)) { 211 if (!empty($this->contenttype)) { 212 header("Content-Type: {$this->contenttype};charset=UTF-8"); 213 } 214 if (!empty($this->body)) { 215 echo $this->body; 216 } 217 } 218 } 219 220 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Thu Aug 11 10:00:09 2016 | Cross-referenced by PHPXref 0.7.1 |