ILIAS  trunk Revision v12.0_alpha-377-g3641b37b9db
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?
23
24namespace XapiProxy;
25
26// hardcoded context for better performance
27// $plugin = file_exists(__DIR__."/plugin.php"); // for testing
28$plugin = false;
29
33if (strtoupper($_SERVER["REQUEST_METHOD"]) == "OPTIONS") {
34 header('HTTP/1.1 204 No Content');
35 header('Access-Control-Allow-Origin: ' . $_SERVER["HTTP_ORIGIN"]);
36 header('Access-Control-Allow-Credentials: true');
37 header('Access-Control-Allow-Methods: GET, POST, PUT, DELETE, OPTIONS');
38 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');
39 exit;
40}
41
45if (!empty($_SERVER['PHP_AUTH_USER']) && !empty($_SERVER['PHP_AUTH_PW'])) {
46 $client = $_SERVER['PHP_AUTH_USER'];
47 $token = $_SERVER['PHP_AUTH_PW'];
48} elseif (!empty($_SERVER['HTTP_AUTHORIZATION'])) {
49 $basicAuth = explode(':', base64_decode(substr($_SERVER['HTTP_AUTHORIZATION'], 6)));
50 $client = $basicAuth[0];
51 $token = $basicAuth[1];
52} else {
53 header('HTTP/1.1 401 Authorization Required');
54 header('Access-Control-Allow-Origin: ' . $_SERVER["HTTP_ORIGIN"]);
55 header('Access-Control-Allow-Credentials: true');
56 header('Access-Control-Allow-Methods: GET, POST, PUT, DELETE, OPTIONS');
57 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');
59}
60
61require_once '../vendor/composer/vendor/autoload.php';
62//instead of DataService
65// DataService::initIlias($client);
66$dic = $GLOBALS['DIC'];
67
69
73try {
74 $xapiproxy->initLrs();
75} catch (\Exception $e) {
76 $xapiproxy->log()->error($e->getMessage());
77}
80
81$xapiproxy->setXapiProxyRequest($req);
82$xapiproxy->setXapiProxyResponse($resp);
83
84$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:78
$_SERVER['HTTP_HOST']
Definition: raiseError.php:26
$GLOBALS["DIC"]
Definition: wac.php:54
$token
Definition: xapitoken.php:67