ILIAS  release_8 Revision v8.19
All Data Structures Namespaces Files Functions Variables 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 30 of file class.ilLTIConsumerServiceResponse.php.

Constructor & Destructor Documentation

◆ __construct()

ilLTIConsumerServiceResponse::__construct ( )

Class constructor.

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

References $_SERVER.

63  {
64  $this->code = 200;
65  $this->reason = '';
66  $this->requestmethod = $_SERVER['REQUEST_METHOD'];
67  $this->accept = '';
68  $this->contenttype = '';
69  $this->data = '';
70  $this->body = '';
71  $this->responsecodes = array(
72  200 => 'OK',
73  201 => 'Created',
74  202 => 'Accepted',
75  300 => 'Multiple Choices',
76  400 => 'Bad Request',
77  401 => 'Unauthorized',
78  402 => 'Payment Required',
79  403 => 'Forbidden',
80  404 => 'Not Found',
81  405 => 'Method Not Allowed',
82  406 => 'Not Acceptable',
83  415 => 'Unsupported Media Type',
84  500 => 'Internal Server Error',
85  501 => 'Not Implemented'
86  );
87  $this->additionalheaders = array();
88  }
$_SERVER['HTTP_HOST']
Definition: raiseError.php:10

Member Function Documentation

◆ getAccept()

ilLTIConsumerServiceResponse::getAccept ( )

Get the request accept header.

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

References $accept.

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

◆ getCode()

ilLTIConsumerServiceResponse::getCode ( )

Get the response code.

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

References $code.

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

◆ getContentType()

ilLTIConsumerServiceResponse::getContentType ( )

Get the response content type.

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

References $contenttype.

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

◆ getReason()

ilLTIConsumerServiceResponse::getReason ( )

Get the response reason.

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

References $code, and $reason.

Referenced by send().

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

◆ getRequestData()

ilLTIConsumerServiceResponse::getRequestData ( )

Get the request body.

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

References $data.

Referenced by ilLTIConsumerGradeServiceScores\execute().

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

◆ getRequestMethod()

ilLTIConsumerServiceResponse::getRequestMethod ( )

Get the request method.

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

References $requestmethod.

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

◆ send()

ilLTIConsumerServiceResponse::send (   $debug = true)

Add an additional header.

Send the response.

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

References $_SERVER, $body, $code, ilObjLTIConsumer\getLogger(), and getReason().

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

◆ setAccept()

ilLTIConsumerServiceResponse::setAccept ( string  $accept)

Set the request accept header.

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

References $accept.

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

◆ setBody()

ilLTIConsumerServiceResponse::setBody ( string  $body)

Set the response body.

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

References $body.

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

◆ setCode()

ilLTIConsumerServiceResponse::setCode ( int  $code)

Set the response code.

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

References $code.

Referenced by ilLTIConsumerGradeServiceScores\execute().

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

◆ setContentType()

ilLTIConsumerServiceResponse::setContentType ( string  $contenttype)

Set the response content type.

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

References $contenttype.

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

◆ setReason()

ilLTIConsumerServiceResponse::setReason ( string  $reason)

Set the response reason.

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

References $reason.

Referenced by ilLTIConsumerGradeServiceScores\execute().

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

◆ setRequestData()

ilLTIConsumerServiceResponse::setRequestData ( string  $data)

Set the response body.

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

References $data.

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

Field Documentation

◆ $accept

string ilLTIConsumerServiceResponse::$accept
private

HTTP request accept header.

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

Referenced by getAccept(), and setAccept().

◆ $additionalheaders

array ilLTIConsumerServiceResponse::$additionalheaders
private

HTTP additional headers.

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

◆ $body

string ilLTIConsumerServiceResponse::$body
private

HTTP response body.

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

Referenced by send(), and setBody().

◆ $code

int ilLTIConsumerServiceResponse::$code
private

HTTP response code.

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

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

◆ $contenttype

string ilLTIConsumerServiceResponse::$contenttype
private

HTTP response content type.

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

Referenced by getContentType(), and setContentType().

◆ $data

string ilLTIConsumerServiceResponse::$data
private

HTTP request body.

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

Referenced by getRequestData(), and setRequestData().

◆ $reason

string ilLTIConsumerServiceResponse::$reason
private

HTTP response reason.

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

Referenced by getReason(), and setReason().

◆ $requestmethod

string ilLTIConsumerServiceResponse::$requestmethod
private

HTTP request method.

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

Referenced by getRequestMethod().

◆ $responsecodes

array ilLTIConsumerServiceResponse::$responsecodes
private

HTTP response codes.

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


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