aboutsummaryrefslogtreecommitdiff
path: root/lib/bootstrap-api.php
blob: 58756a8f570e53c47c93cbbfaf30e0b39938117a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
<?php
namespace {
    StudipAutoloader::addAutoloadPath($GLOBALS['STUDIP_BASE_PATH'] . '/vendor/oauth-php/library');

    // Set base url for URLHelper class
    URLHelper::setBaseUrl($GLOBALS['CANONICAL_RELATIVE_PATH_STUDIP']);
}

namespace RESTAPI {
    use Studip, OAuthStore;

    // Define api version
    const VERSION = '2';

    $router = Router::getInstance();

    // Register JSON content renderer
    $router->registerRenderer(new Renderer\JSONRenderer, true);

    // If in development mode, register debug content renderer
    if (defined('Studip\\ENV') && Studip\ENV === 'development') {
        $router->registerRenderer(new Renderer\DebugRenderer);
    }

    OAuthStore::instance('PDO', [
        'dsn' => 'mysql:host=' . $GLOBALS['DB_STUDIP_HOST']
                   . ';dbname=' . $GLOBALS['DB_STUDIP_DATABASE'],
        'username' => $GLOBALS['DB_STUDIP_USER'],
        'password' => $GLOBALS['DB_STUDIP_PASSWORD']
    ]);

    // Register default consumers
    Consumer\Base::addType('http', 'RESTAPI\\Consumer\\HTTP');
    Consumer\Base::addType('studip', 'RESTAPI\\Consumer\\Studip');
    Consumer\Base::addType('oauth', 'RESTAPI\\Consumer\\OAuth');
}