ILIAS  trunk Revision v11.0_alpha-1761-g6dbbfa7b760
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
ilLTIConsumerServiceResponse Class Reference
+ Collaboration diagram for ilLTIConsumerServiceResponse:

Public Member Functions

 __construct ()
 Class constructor. More...
 
 getCode ()
 Get the response code. More...
 
 setCode (int $code)
 Set the response code. More...
 
 getReason ()
 Get the response reason. More...
 
 setReason (string $reason)
 Set the response reason. More...
 
 getRequestMethod ()
 Get the request method. More...
 
 getAccept ()
 Get the request accept header. More...
 
 setAccept (string $accept)
 Set the request accept header. More...
 
 getContentType ()
 Get the response content type. More...
 
 setContentType (string $contenttype)
 Set the response content type. More...
 
 getRequestData ()
 Get the request body. More...
 
 setRequestData (string $data)
 Set the response body. More...
 
 setBody (string $body)
 Set the response body. More...
 
 send ($debug=true)
 Add an additional header. More...
 

Private Attributes

int $code
 HTTP response code. More...
 
string $reason
 HTTP response reason. More...
 
string $requestmethod
 HTTP request method. More...
 
string $accept
 HTTP request accept header. More...
 
string $contenttype
 HTTP response content type. More...
 
string $data
 HTTP request body. More...
 
string $body
 HTTP response body. More...
 
array $responsecodes
 HTTP response codes. More...
 
array $additionalheaders
 HTTP additional headers. More...
 

Detailed Description

Definition at line 29 of file class.ilLTIConsumerServiceResponse.php.

Constructor & Destructor Documentation

◆ __construct()

ilLTIConsumerServiceResponse::__construct ( )

Class constructor.

Definition at line 61 of file class.ilLTIConsumerServiceResponse.php.

References $_SERVER.

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  $this->additionalheaders = array();
87  }
$_SERVER['HTTP_HOST']
Definition: raiseError.php:26

Member Function Documentation

◆ getAccept()

ilLTIConsumerServiceResponse::getAccept ( )

Get the request accept header.

Definition at line 144 of file class.ilLTIConsumerServiceResponse.php.

References $accept.

144  : string
145  {
146  return $this->accept;
147  }
string $accept
HTTP request accept header.

◆ getCode()

ilLTIConsumerServiceResponse::getCode ( )

Get the response code.

Definition at line 92 of file class.ilLTIConsumerServiceResponse.php.

References $code.

92  : int
93  {
94  return $this->code;
95  }

◆ getContentType()

ilLTIConsumerServiceResponse::getContentType ( )

Get the response content type.

Definition at line 160 of file class.ilLTIConsumerServiceResponse.php.

References $contenttype.

160  : string
161  {
162  return $this->contenttype;
163  }
string $contenttype
HTTP response content type.

◆ getReason()

ilLTIConsumerServiceResponse::getReason ( )

Get the response reason.

Definition at line 109 of file class.ilLTIConsumerServiceResponse.php.

References $code, and $reason.

Referenced by send().

109  : string
110  {
111  $code = $this->code;
112  if (($code < 200) || ($code >= 600)) {
113  $code = 500; // Status code must be between 200 and 599.
114  }
115  if (empty($this->reason) && array_key_exists($code, $this->responsecodes)) {
116  $this->reason = $this->responsecodes[$code];
117  }
118  // Use generic reason for this category (based on first digit) if a specific reason is not defined.
119  if (empty($this->reason)) {
120  $this->reason = $this->responsecodes[intval($code / 100) * 100];
121  }
122  return $this->reason;
123  }
+ Here is the caller graph for this function:

◆ getRequestData()

ilLTIConsumerServiceResponse::getRequestData ( )

Get the request body.

Definition at line 176 of file class.ilLTIConsumerServiceResponse.php.

References $data.

Referenced by ilLTIConsumerGradeServiceScores\execute().

176  : string
177  {
178  return $this->data;
179  }
+ Here is the caller graph for this function:

◆ getRequestMethod()

ilLTIConsumerServiceResponse::getRequestMethod ( )

Get the request method.

Definition at line 136 of file class.ilLTIConsumerServiceResponse.php.

References $requestmethod.

136  : string
137  {
138  return $this->requestmethod;
139  }

◆ send()

ilLTIConsumerServiceResponse::send (   $debug = true)

Add an additional header.

Send the response.

Definition at line 208 of file class.ilLTIConsumerServiceResponse.php.

References $_SERVER, $body, $code, ilObjLTIConsumer\getLogger(), getReason(), and ILIAS\UI\examples\Symbol\Glyph\Header\header().

208  : void
209  {
210  header("HTTP/1.0 {$this->code} {$this->getReason()}");
211  foreach ($this->additionalheaders as $header) {
212  header($header);
213  }
214  if ($debug) {
215  if ($this->code >= 200 && $this->code < 400) {
216  ilObjLTIConsumer::getLogger()->debug("$this->code {$this->getReason()}");
217  } else {
218  ilObjLTIConsumer::getLogger()->error("$this->code {$this->getReason()}");
219  }
220  }
221  if ((($this->code >= 200) && ($this->code < 300)) || !empty($this->body)) {
222  if (!empty($this->contenttype)) {
223  header("Content-Type: $this->contenttype; charset=utf-8");
224  }
225  if (!empty($this->body)) {
226  echo $this->body;
227  }
228  } elseif ($this->code >= 400) {
229  header("Content-Type: application/json; charset=utf-8");
230  $body = new stdClass();
231  $body->status = $this->code;
232  $body->reason = $this->getReason();
233  $body->request = new stdClass();
234  $body->request->method = $_SERVER['REQUEST_METHOD'];
235  $body->request->url = $_SERVER['REQUEST_URI'];
236  if (isset($_SERVER['HTTP_ACCEPT'])) {
237  $body->request->accept = $_SERVER['HTTP_ACCEPT'];
238  }
239  if (isset($_SERVER['CONTENT_TYPE'])) {
240  $body->request->contentType = explode(';', $_SERVER['CONTENT_TYPE'], 2)[0];
241  }
242  echo json_encode($body, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES);
243  }
244  }
$_SERVER['HTTP_HOST']
Definition: raiseError.php:26
header()
expected output: > ILIAS shows the rendered Component.
Definition: header.php:29
+ Here is the call graph for this function:

◆ setAccept()

ilLTIConsumerServiceResponse::setAccept ( string  $accept)

Set the request accept header.

Definition at line 152 of file class.ilLTIConsumerServiceResponse.php.

References $accept.

152  : void
153  {
154  $this->accept = $accept;
155  }
string $accept
HTTP request accept header.

◆ setBody()

ilLTIConsumerServiceResponse::setBody ( string  $body)

Set the response body.

Definition at line 192 of file class.ilLTIConsumerServiceResponse.php.

References $body.

192  : void
193  {
194  $this->body = $body;
195  }

◆ setCode()

ilLTIConsumerServiceResponse::setCode ( int  $code)

Set the response code.

Definition at line 100 of file class.ilLTIConsumerServiceResponse.php.

References $code.

Referenced by ilLTIConsumerGradeServiceScores\execute().

100  : void
101  {
102  $this->code = $code;
103  $this->reason = '';
104  }
+ Here is the caller graph for this function:

◆ setContentType()

ilLTIConsumerServiceResponse::setContentType ( string  $contenttype)

Set the response content type.

Definition at line 168 of file class.ilLTIConsumerServiceResponse.php.

References $contenttype.

168  : void
169  {
170  $this->contenttype = $contenttype;
171  }
string $contenttype
HTTP response content type.

◆ setReason()

ilLTIConsumerServiceResponse::setReason ( string  $reason)

Set the response reason.

Definition at line 128 of file class.ilLTIConsumerServiceResponse.php.

References $reason.

Referenced by ilLTIConsumerGradeServiceScores\execute().

128  : void
129  {
130  $this->reason = $reason;
131  }
+ Here is the caller graph for this function:

◆ setRequestData()

ilLTIConsumerServiceResponse::setRequestData ( string  $data)

Set the response body.

Definition at line 184 of file class.ilLTIConsumerServiceResponse.php.

References $data.

184  : void
185  {
186  $this->data = $data;
187  }

Field Documentation

◆ $accept

string ilLTIConsumerServiceResponse::$accept
private

HTTP request accept header.

Definition at line 41 of file class.ilLTIConsumerServiceResponse.php.

Referenced by getAccept(), and setAccept().

◆ $additionalheaders

array ilLTIConsumerServiceResponse::$additionalheaders
private

HTTP additional headers.

Definition at line 56 of file class.ilLTIConsumerServiceResponse.php.

◆ $body

string ilLTIConsumerServiceResponse::$body
private

HTTP response body.

Definition at line 50 of file class.ilLTIConsumerServiceResponse.php.

Referenced by send(), and setBody().

◆ $code

int ilLTIConsumerServiceResponse::$code
private

HTTP response code.

Definition at line 32 of file class.ilLTIConsumerServiceResponse.php.

Referenced by getCode(), getReason(), send(), and setCode().

◆ $contenttype

string ilLTIConsumerServiceResponse::$contenttype
private

HTTP response content type.

Definition at line 44 of file class.ilLTIConsumerServiceResponse.php.

Referenced by getContentType(), and setContentType().

◆ $data

string ilLTIConsumerServiceResponse::$data
private

HTTP request body.

Definition at line 47 of file class.ilLTIConsumerServiceResponse.php.

Referenced by getRequestData(), and setRequestData().

◆ $reason

string ilLTIConsumerServiceResponse::$reason
private

HTTP response reason.

Definition at line 35 of file class.ilLTIConsumerServiceResponse.php.

Referenced by getReason(), and setReason().

◆ $requestmethod

string ilLTIConsumerServiceResponse::$requestmethod
private

HTTP request method.

Definition at line 38 of file class.ilLTIConsumerServiceResponse.php.

Referenced by getRequestMethod().

◆ $responsecodes

array ilLTIConsumerServiceResponse::$responsecodes
private

HTTP response codes.

Definition at line 53 of file class.ilLTIConsumerServiceResponse.php.


The documentation for this class was generated from the following file: