ILIAS  release_8 Revision v8.23
xapiproxy.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
21 // hardcoded namespace
22 // attention: maybe a problem with composer v2 / psr4 autoload requires exact matching of namespace and parent folder name?
23 
24 namespace XapiProxy;
25 
26 // hardcoded context for better performance
27 // $plugin = file_exists(__DIR__."/plugin.php"); // for testing
28 $plugin = false;
29 
33 if (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 
45 if (!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 
65 if ($plugin) {
70  //require_once __DIR__.'/classes/XapiProxy/vendor/autoload.php';
71 
72  chdir("../../../../../../../");
73 } else {
74  chdir("../../");
75 }
76 require_once("Services/Init/classes/class.ilInitialisation.php");
77 //instead of DataService
80 // DataService::initIlias($client);
81 $dic = $GLOBALS['DIC'];
82 
84 
88 try {
89  $xapiproxy->initLrs();
90 } catch (\Exception $e) {
91  $xapiproxy->log()->error($e->getMessage());
92 }
95 
96 $xapiproxy->setXapiProxyRequest($req);
97 $xapiproxy->setXapiProxyResponse($resp);
98 
99 $req->handle();
const CONTEXT_SCORM
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Definition: DataService.php:21
catch(\Exception $e) $req
Definition: xapiproxy.php:93
$client
static initILIAS()
ilias initialisation
$token
Definition: xapitoken.php:70
$_SERVER['HTTP_HOST']
Definition: raiseError.php:10
if(!defined('PATH_SEPARATOR')) $GLOBALS['_PEAR_default_error_mode']
Definition: PEAR.php:64
static init(string $a_type)
Init context by type.
$dic
Definition: result.php:32