aboutsummaryrefslogtreecommitdiff
path: root/lib/bootstrap-definitions.php
blob: 2f59dc9bffc897f6a7632a4ab047e04f419d7305 (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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
<?php

use DebugBar\DataCollector\ExceptionsCollector;
use DebugBar\DataCollector\MemoryCollector;
use DebugBar\DataCollector\MessagesCollector;
use DebugBar\DataCollector\PhpInfoCollector;
use DebugBar\DataCollector\RequestDataCollector;
use DebugBar\DataCollector\TimeDataCollector;
use Monolog\Handler\StreamHandler;
use Monolog\Logger;
use Psr\Container\ContainerInterface;
use Psr\Log\LoggerInterface;

use function DI\create;

return [
    LoggerInterface::class => DI\factory(function () {
        return new Logger('studip', [
            new StreamHandler(
                $GLOBALS['TMP_PATH'] . '/studip.log',
                \Studip\ENV === 'development' ? Logger::DEBUG : Logger::ERROR
            ),
        ]);
    }),
    \Studip\Cache\Cache::class => DI\factory(function () {
        return \Studip\Cache\Factory::getCache();
    }),
    PDO::class => DI\factory(function () {
        return DBManager::get();
    }),
    Trails\Dispatcher::class => DI\factory(function (ContainerInterface $container) {
        return new \StudipDispatcher($container);
    }),
    DebugBar\DebugBar::class => DI\factory(function (ContainerInterface $container) {
        $debugBar = new DebugBar\DebugBar();
        $debugBar->addCollector(new PhpInfoCollector());
        $debugBar->addCollector(new RequestDataCollector());
        $debugBar->addCollector(new MemoryCollector());
        $debugBar->addCollector(new ExceptionsCollector());

        // Future Improvements, not used/activated right now
        # $debugBar->addCollector(new MessagesCollector());
        # $debugBar->addCollector(new TimeDataCollector());

        $config = iterator_to_array(Config::getInstance()->getIterator());
        ksort($config);
        $debugBar->addCollector(new DebugBar\DataCollector\ConfigCollector($config));

        $pdo = $container->get(PDO::class);
        if ($pdo instanceof DebugBar\DataCollector\PDO\TraceablePDO) {
            $collector = new DebugBar\DataCollector\PDO\PDOCollector($pdo);
            $debugBar->addCollector($collector);
        }

        return $debugBar;
    }),
    StudipPDO::class => DI\factory(function () {
        $pdo = new StudipPDO(
            "mysql:host={$GLOBALS['DB_STUDIP_HOST']};dbname={$GLOBALS['DB_STUDIP_DATABASE']};charset=utf8mb4",
            $GLOBALS['DB_STUDIP_USER'],
            $GLOBALS['DB_STUDIP_PASSWORD']
        );

        if (Studip\Debug\DebugBar::isActivated()) {
            $pdo = new DebugBar\DataCollector\PDO\TraceablePDO($pdo);
        }

        return $pdo;
    }),
];