ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
xapiproxy.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
21// hardcoded namespace
22// attention: maybe a problem with composer v2 / psr4 autoload requires exact matching of namespace and parent folder name?
23namespace XapiProxy;
24
25// hardcoded context for better performance
26// $plugin = file_exists(__DIR__."/plugin.php"); // for testing
27$plugin = false;
28
32if (strtoupper($_SERVER["REQUEST_METHOD"]) == "OPTIONS") {
33 header('HTTP/1.1 204 No Content');
34 header('Access-Control-Allow-Origin: ' . $_SERVER["HTTP_ORIGIN"]);
35 header('Access-Control-Allow-Credentials: true');
36 header('Access-Control-Allow-Methods: GET, POST, PUT, DELETE, OPTIONS');
37 header('Access-Control-Allow-Headers: X-Experience-API-Version,Accept,Authorization,Etag,Cache-Control,Content-Type,DNT,If-Modified-Since,Keep-Alive,Origin,User-Agent,X-Mx-ReqToken,X-Requested-With');
38 exit;
39}
40
44if (!empty($_SERVER['PHP_AUTH_USER']) && !empty($_SERVER['PHP_AUTH_PW'])) {
45 $client = $_SERVER['PHP_AUTH_USER'];
46 $token = $_SERVER['PHP_AUTH_PW'];
47} elseif (!empty($_SERVER['HTTP_AUTHORIZATION'])) {
48 $basicAuth = explode(':', base64_decode(substr($_SERVER['HTTP_AUTHORIZATION'], 6)));
49 $client = $basicAuth[0];
50 $token = $basicAuth[1];
51} else {
52 header('HTTP/1.1 401 Authorization Required');
53 header('Access-Control-Allow-Origin: ' . $_SERVER["HTTP_ORIGIN"]);
54 header('Access-Control-Allow-Credentials: true');
55 header('Access-Control-Allow-Methods: GET, POST, PUT, DELETE, OPTIONS');
56 header('Access-Control-Allow-Headers: X-Experience-API-Version,Accept,Authorization,Etag,Cache-Control,Content-Type,DNT,If-Modified-Since,Keep-Alive,Origin,User-Agent,X-Mx-ReqToken,X-Requested-With');
58}
59
64if ($plugin) {
69 //require_once __DIR__.'/classes/XapiProxy/vendor/autoload.php';
70
71 chdir("../../../../../../../../");
72} else {
73 chdir("../../../");
74}
75//instead of DataService
78// DataService::initIlias($client);
79$dic = $GLOBALS['DIC'];
80
82
86try {
87 $xapiproxy->initLrs();
88} catch (\Exception $e) {
89 $xapiproxy->log()->error($e->getMessage());
90}
93
94$xapiproxy->setXapiProxyRequest($req);
95$xapiproxy->setXapiProxyResponse($resp);
96
97$req->handle();
const CONTEXT_SCORM
static init(string $a_type)
Init context by type.
static initILIAS()
ilias initialisation
$client
$dic
Definition: ltiresult.php:33
catch(\Exception $e) $req
Definition: xapiproxy.php:91
$_SERVER['HTTP_HOST']
Definition: raiseError.php:26
$GLOBALS["DIC"]
Definition: wac.php:54
$token
Definition: xapitoken.php:70