bootstrap.php 2.8 KB
Newer Older
1
2
<?php
/**
3
 * gredu_labs.
4
5
 * 
 * @link https://github.com/eellak/gredu_labs for the canonical source repository
6
 *
7
8
9
10
11
12
13
14
15
16
 * @copyright Copyright (c) 2008-2015 Greek Free/Open Source Software Society (https://gfoss.ellak.gr/)
 * @license GNU GPLv3 http://www.gnu.org/licenses/gpl-3.0-standalone.html
 */

return function (Slim\App $app) {

    $container = $app->getContainer();

    $container['autoloader']->addPsr4('GrEduLabs\\Application\\', __DIR__ . '/src');

17
    $container['view'] = function ($c) {
18
        $settings = $c['settings'];
19
        $view     = new Slim\Views\Twig(
20
21
22
23
24
25
26
27
            $settings['view']['template_path'],
            $settings['view']['twig']
        );
        $view->addExtension(new Slim\Views\TwigExtension(
            $c['router'],
            $c['request']->getUri()
        ));

28
        $view->addExtension($c[GrEduLabs\Application\Twig\Extension\Navigation::class]);
29
30
31
32
33
34
35
        $view->addExtension(new Knlv\Slim\Views\TwigMessages(
            $c['flash']
        ));

        return $view;
    };

36
37
38
39
40
41
42
43
    $container[GrEduLabs\Application\Twig\Extension\Navigation::class] = function ($c) {
        return new GrEduLabs\Application\Twig\Extension\Navigation(
            $c['settings']['navigation'],
            $c['router'],
            $c['request']
        );
    };

44
45
46
47
48
    $container['flash'] = function ($c) {
        return new \Slim\Flash\Messages();
    };

    $container['logger'] = function ($c) {
49
        $settings = $c['settings'];
50
51
52
53
54
55
56
57
58
59
60
        $logger   = new Monolog\Logger($settings['logger']['name']);
        $logger->pushProcessor(new Monolog\Processor\UidProcessor());
        $logger->pushHandler(new Monolog\Handler\RotatingFileHandler(
            $settings['logger']['path'],
            $settings['logger']['max_files'],
            Monolog\Logger::INFO
        ));

        return $logger;
    };

61
62
63
64
    $container['csrf'] = function ($c) {
        return new \Slim\Csrf\Guard();
    };

65
66
67
68
69
70
71

    $container['GrEduLabs\\Application\\Action\\Index'] = function ($c) {
        return new GrEduLabs\Application\Action\Index($c['view']);
    };



72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
    $events = $container['events'];
    $events('on', 'bootstrap', function () use ($container) {
        session_name('GrEduLabs');
        session_start();

        // setup RedbeanPHP

        RedBeanPHP\R::setup(
            $container['settings']['db']['dsn'],
            $container['settings']['db']['user'],
            $container['settings']['db']['pass']
        );

        define('REDBEAN_MODEL_PREFIX', 'GrEduLabs\\Application\\Model\\');

    }, 10000000);

    $events('on', 'bootstrap', function () use ($container) {
        try {
            $container['router']->getNamedRoute('user.login')->add('csrf');
        } catch (\RuntimeException $e) {
            // eat it
        }
    });


98
    $app->get('/', 'GrEduLabs\\Application\\Action\\Index')->setName('index');
99

100
};