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