ILIAS
release_8 Revision v8.19
◀ ilDoc Overview
Main Page
Related Pages
Modules
+
Namespaces
Namespace List
+
Namespace Members
+
All
$
_
a
b
c
d
e
f
g
h
i
j
l
m
n
o
p
r
s
t
u
v
w
x
+
Functions
_
a
b
c
d
e
f
g
h
i
l
m
n
o
p
r
s
t
u
v
w
x
+
Variables
$
a
b
c
d
e
f
g
h
j
l
m
p
s
t
u
+
Data Structures
Data Structures
Data Structure Index
Class Hierarchy
+
Data Fields
+
All
$
_
a
b
c
d
e
f
g
h
i
j
k
l
m
n
o
p
q
r
s
t
u
v
w
x
y
z
Ö
+
Functions
_
a
b
c
d
e
f
g
h
i
j
k
l
m
n
o
p
q
r
s
t
u
v
w
x
y
z
+
Variables
$
a
b
c
d
e
f
g
h
i
j
k
l
m
n
o
p
q
r
s
t
u
v
w
x
y
z
Ö
+
Files
File List
+
Globals
+
All
$
_
a
b
c
d
e
f
g
h
i
j
k
l
m
n
o
p
r
s
t
u
v
w
x
z
+
Functions
_
a
b
c
d
e
g
h
i
m
n
p
r
s
t
u
v
x
+
Variables
$
a
c
d
e
f
g
h
i
j
k
l
m
n
o
p
r
s
t
u
v
w
z
Examples
•
All
Data Structures
Namespaces
Files
Functions
Variables
Modules
Pages
ltiservices.php
Go to the documentation of this file.
1
<?php
2
3
declare(strict_types=1);
4
23
chdir(
"../../"
);
24
25
require_once(
"Services/Init/classes/class.ilInitialisation.php"
);
26
27
ilContext::init
(
ilContext::CONTEXT_SCORM
);
28
ilInitialisation::initILIAS
();
29
30
global
$DIC
;
31
32
$path
=
$_SERVER
[
'PATH_INFO'
] ??
''
;
33
34
if
(empty(
$path
)) {
35
ilObjLTIConsumer::sendResponseError
(500, json_encode(array(
'error'
=>
"ERROR_NO_PATH_INFO"
)));
36
}
37
38
$serviceName
=
getService
(
$path
);
39
40
ilObjLTIConsumer::getLogger
()->debug(
"lti service call $serviceName"
);
41
ilObjLTIConsumer::getLogger
()->debug(
"lti service path $path"
);
42
43
$service
= null;
44
switch
(
$serviceName
) {
45
case
"gradeservice"
:
46
$service
=
new
ilLTIConsumerGradeService
();
47
$service
->setResourcePath(
$path
);
48
break
;
49
default
:
50
ilObjLTIConsumer::sendResponseError
(400, json_encode(array(
'error'
=>
'invalid_request'
)));
51
}
52
53
$response
=
new
ilLTIConsumerServiceResponse
();
54
55
$isGet
=
$response
->getRequestMethod() ===
ilLTIConsumerResourceBase::HTTP_GET
;
56
$isDelete
=
$response
->getRequestMethod() ===
ilLTIConsumerResourceBase::HTTP_DELETE
;
57
58
if
(
$isGet
) {
59
$response
->setAccept(
$_SERVER
[
'HTTP_ACCEPT'
] ??
''
);
60
}
else
{
61
$response
->setContentType(isset(
$_SERVER
[
'CONTENT_TYPE'
]) ? explode(
';'
,
$_SERVER
[
'CONTENT_TYPE'
], 2)[0] :
''
);
62
}
63
64
$validRequest
=
false
;
65
66
$accept
=
$response
->getAccept();
67
$contenttype
=
$response
->getContentType();
68
$resources
=
$service
->getResources();
69
$res
= null;
70
71
foreach
(
$resources
as $resource) {
72
if
((
$isGet
&& !empty(
$accept
) && (!str_contains(
$accept
,
'*/*'
)) &&
73
!in_array(
$accept
, $resource->getFormats())) ||
74
((!
$isGet
&& !
$isDelete
) && !in_array(
$contenttype
, $resource->getFormats()))) {
75
continue
;
76
}
77
78
$template = $resource->getTemplate();
79
$template = preg_replace(
'/\{[a-zA-Z_]+\}/'
,
'[^/]+'
, $template);
80
$template = preg_replace(
'/\(([0-9a-zA-Z_\-,\/]+)\)/'
,
'(\\1|)'
, $template);
81
$template = str_replace(
'/'
,
'\/'
, $template);
82
if
(preg_match(
"/^$template$/"
,
$path
) === 1) {
83
$validRequest
=
true
;
84
$res
= $resource;
85
break
;
86
}
87
}
88
89
if
(!
$validRequest
||
$res
== null) {
90
$response
->setCode(400);
91
$response
->setReason(
"No handler found for $serviceName/$path $accept $contenttype"
);
92
}
else
{
93
$body = file_get_contents(
'php://input'
);
94
$response
->setRequestData($body);
95
if
(in_array(
$response
->getRequestMethod(),
$res
->getMethods())) {
96
$res
->execute(
$response
);
97
}
else
{
98
$response
->setCode(405);
99
}
100
}
101
$response
->send();
102
103
function
getService
(
string
&
$path
): string
104
{
105
$route = explode(
"/"
, $path);
106
array_shift($route);
// first slash
107
$ret = array_shift($route);
// service name
108
$path =
"/"
. implode(
"/"
, $route);
109
return
$ret;
110
}
$res
$res
Definition:
ltiservices.php:69
$isDelete
$isDelete
Definition:
ltiservices.php:56
$resources
$resources
Definition:
ltiservices.php:68
$serviceName
if(empty($path)) $serviceName
Definition:
ltiservices.php:38
ilObjLTIConsumer\sendResponseError
static sendResponseError(int $code, string $message, $log=true)
Definition:
class.ilObjLTIConsumer.php:1309
ilContext\CONTEXT_SCORM
const CONTEXT_SCORM
Definition:
class.ilContext.php:42
ilLTIConsumerServiceResponse
Definition:
class.ilLTIConsumerServiceResponse.php:30
$validRequest
$validRequest
Definition:
ltiservices.php:64
$accept
$accept
Definition:
ltiservices.php:66
$path
$path
Definition:
ltiservices.php:32
$DIC
global $DIC
Definition:
ltiservices.php:30
ilObjLTIConsumer\getLogger
static getLogger()
Definition:
class.ilObjLTIConsumer.php:1386
ilInitialisation\initILIAS
static initILIAS()
ilias initialisation
Definition:
class.ilInitialisation.php:1225
$response
switch($serviceName) $response
Definition:
ltiservices.php:53
$_SERVER
$_SERVER['HTTP_HOST']
Definition:
raiseError.php:10
ilLTIConsumerResourceBase\HTTP_DELETE
const HTTP_DELETE
HTTP Delete method.
Definition:
class.ilLTIConsumerResourceBase.php:42
$contenttype
$contenttype
Definition:
ltiservices.php:67
$isGet
$isGet
Definition:
ltiservices.php:55
ilContext\init
static init(string $a_type)
Init context by type.
Definition:
class.ilContext.php:52
ilLTIConsumerResourceBase\HTTP_GET
const HTTP_GET
HTTP Get method.
Definition:
class.ilLTIConsumerResourceBase.php:36
getService
getService(string &$path)
Definition:
ltiservices.php:103
$service
$service
Definition:
ltiservices.php:43
ilLTIConsumerGradeService
Definition:
class.ilLTIConsumerGradeService.php:30
Modules
LTIConsumer
ltiservices.php
Generated on Sun Apr 6 2025 22:01:41 for ILIAS by
1.8.13 (using
Doxyfile
)