ILIAS  release_7 Revision v7.30-3-g800a261c036
xapiproxy.php
Go to the documentation of this file.
1<?php
2 // hardcoded namespace
3 // attention: maybe a problem with composer v2 / psr4 autoload requires exact matching of namespace and parent folder name?
4 namespace XapiProxy;
5
6 // hardcoded context for better performance
7 // $plugin = file_exists(__DIR__."/plugin.php"); // for testing
8 $plugin = false;
9
13 if (strtoupper($_SERVER["REQUEST_METHOD"]) == "OPTIONS") {
14 header('HTTP/1.1 204 No Content');
15 header('Access-Control-Allow-Origin: ' . $_SERVER["HTTP_ORIGIN"]);
16 header('Access-Control-Allow-Credentials: true');
17 header('Access-Control-Allow-Methods: GET, POST, PUT, DELETE, OPTIONS');
18 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');
19 exit;
20 }
21
25 if (!empty($_SERVER['PHP_AUTH_USER']) && !empty($_SERVER['PHP_AUTH_PW'])) {
26 $client = $_SERVER['PHP_AUTH_USER'];
27 $token = $_SERVER['PHP_AUTH_PW'];
28 } elseif (!empty($_SERVER['HTTP_AUTHORIZATION'])) {
29 $basicAuth = explode(':', base64_decode(substr($_SERVER['HTTP_AUTHORIZATION'], 6)));
30 $client = $basicAuth[0];
31 $token = $basicAuth[1];
32 } else {
33 header('HTTP/1.1 401 Authorization Required');
35 }
36
41 if ($plugin) {
46 //require_once __DIR__.'/classes/XapiProxy/vendor/autoload.php';
47
48 chdir("../../../../../../../");
49 } else {
50 chdir("../../");
51 }
52
56 require_once __DIR__ . '/classes/XapiProxy/DataService.php';
58
62 require_once __DIR__ . '/classes/XapiProxy/XapiProxy.php';
63 $dic = $GLOBALS['DIC'];
64
65 $dic['xapiproxy'] = function ($c) use ($client, $token, $plugin) {
66 return new XapiProxy($client, $token, $plugin);
67 };
68
72 try {
73 $dic['xapiproxy']->initLrs();
74 } catch (\Exception $e) { // ?
75 $dic['xapiproxy']->log()->error($dic['xapiproxy']->getLogMessage($e->getMessage()));
76 }
77
78 require_once __DIR__ . '/classes/XapiProxy/XapiProxyRequest.php';
79 require_once __DIR__ . '/classes/XapiProxy/XapiProxyResponse.php';
82
83 $dic['xapiproxy']->setXapiProxyRequest($req);
84 $dic['xapiproxy']->setXapiProxyResponse($resp);
85
86 $req->handle();
if(!defined('PATH_SEPARATOR')) $GLOBALS['_PEAR_default_error_mode']
Definition: PEAR.php:64
An exception for terminatinating execution or to throw for unit testing.
static initIlias($client_id)
Definition: DataService.php:7
$c
Definition: cli.php:37
if($_SERVER['argc']< 4) $client
Definition: cron.php:12
$_SERVER['HTTP_HOST']
Definition: raiseError.php:10
$dic
Definition: result.php:13
$token
Definition: xapitoken.php:52