aboutsummaryrefslogtreecommitdiff
path: root/lib/classes/JsonApi/settings.php
blob: dfb8185089c18c4b57407e078df5fd7ccc103284 (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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
<?php

namespace JsonApi;

use DI\ContainerBuilder;
use Neomerx\JsonApi\Contracts\Factories\FactoryInterface;
use Neomerx\JsonApi\Contracts\Schema\SchemaContainerInterface;
use Psr\Container\ContainerInterface;

return function (ContainerBuilder $containerBuilder) {
    // Global Settings Object
    $containerBuilder->addDefinitions([
        'studip-current-user' => function () {
            if ($user = $GLOBALS['user']) {
                return $user->getAuthenticatedUser();
            }

            return null;
        },
        'studip-authenticator' => function () {
            return function ($username, $password) {
                $check = \StudipAuthAbstract::CheckAuthentication($username, $password);

                if ($check['uid'] && 'nobody' != $check['uid']) {
                    return \User::find($check['uid']);
                }

                return null;
            };
        },

        'json-api-integration-schemas' => function () {
            $schemaMap = new SchemaMap();
            $coreSchemas = $schemaMap();

            $allSchemas = $coreSchemas;
            $pluginSchemas = \PluginEngine::sendMessage(Contracts\JsonApiPlugin::class, 'registerSchemas');
            if (is_array($pluginSchemas) && count($pluginSchemas)) {
                foreach ($pluginSchemas as $arrayOfSchemas) {
                    $allSchemas = array_merge($allSchemas, $arrayOfSchemas);
                }
            }

            return $allSchemas;
        },

        'json-api-integration-urlPrefix' => function () {
            return rtrim(\URLHelper::getUrl('jsonapi.php/v1'), '/');
        },

        'json-api-error-encoder' => function (FactoryInterface $factory) {
            return $factory->createEncoder($factory->createSchemaContainer([]));
        },
    ]);
};