19declare(strict_types=1);
50 'X-Experience-API-Version: 1.0.3'
54 $ch = curl_init(
$url);
55 curl_setopt_array($ch, [
56 CURLOPT_RETURNTRANSFER =>
true,
57 CURLOPT_HTTPHEADER => $headers,
58 CURLOPT_CONNECTTIMEOUT => 10,
59 CURLOPT_TIMEOUT => 30,
60 CURLOPT_SSL_VERIFYPEER =>
true,
61 CURLOPT_FOLLOWLOCATION =>
true
65 $body = curl_exec($ch);
66 $error = curl_error($ch);
67 $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
73 throw new Exception(
"LRS Connection Problems: " . $error);
76 if ($httpCode < 200 || $httpCode >= 300) {
78 throw new Exception(
"LRS Connection Problems (HTTP {$httpCode})");
81 if ($body ===
false || $body ===
'') {
83 throw new Exception(
"Empty response from LRS");
93 $status =
$response[
'value']->getStatusCode();
94 if (in_array($status, $allowedStatus)) {
95 $body =
$response[
'value']->getBody()->getContents();
104 }
catch (Exception
$e) {
118 if ($encoding ===
false) {
119 $encoder = fn($str) => $str;
120 } elseif ($encoding === PHP_QUERY_RFC3986) {
121 $encoder =
'rawurlencode';
122 } elseif ($encoding === PHP_QUERY_RFC1738) {
123 $encoder =
'urlencode';
125 throw new \InvalidArgumentException(
'Invalid type');
129 foreach (
$params as $k => $v) {
134 $qs .=
'=' . $encoder($v);
138 foreach ($v as $vv) {
141 $qs .=
'=' . $encoder($vv);
147 return $qs ? (string) substr($qs, 0, -1) :
'';
__construct(string $basicAuth)
ilCmiXapiAbstractRequest constructor.
static buildQuery(array $params, $encoding=PHP_QUERY_RFC3986)
static checkResponse(array $response, &$body, array $allowedStatus=[200, 204])
if(! $DIC->user() ->getId()||!ilLTIConsumerAccess::hasCustomProviderCreationAccess()) $params