bootstrap.php 2.78 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
 * @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();

Vassilis Kanellopoulos's avatar
Vassilis Kanellopoulos committed
15 16 17 18 19 20 21 22
    // setup RedbeanPHP
    define('REDBEAN_MODEL_PREFIX', '');
    RedBeanPHP\R::setup(
        $container['settings']['db']['dsn'],
        $container['settings']['db']['user'],
        $container['settings']['db']['pass']
    );

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

25
    $container['view'] = function ($c) {
26
        $settings = $c['settings'];
27
        $view     = new Slim\Views\Twig(
28 29 30 31 32 33 34 35
            $settings['view']['template_path'],
            $settings['view']['twig']
        );
        $view->addExtension(new Slim\Views\TwigExtension(
            $c['router'],
            $c['request']->getUri()
        ));

36
        $view->addExtension($c[GrEduLabs\Application\Twig\Extension\Navigation::class]);
37 38 39 40 41 42 43
        $view->addExtension(new Knlv\Slim\Views\TwigMessages(
            $c['flash']
        ));

        return $view;
    };

44 45 46 47 48 49 50 51
    $container[GrEduLabs\Application\Twig\Extension\Navigation::class] = function ($c) {
        return new GrEduLabs\Application\Twig\Extension\Navigation(
            $c['settings']['navigation'],
            $c['router'],
            $c['request']
        );
    };

52 53 54 55 56
    $container['flash'] = function ($c) {
        return new \Slim\Flash\Messages();
    };

    $container['logger'] = function ($c) {
57
        $settings = $c['settings'];
58 59 60 61 62 63 64 65 66 67 68
        $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;
    };

69 70 71 72
    $container['csrf'] = function ($c) {
        return new \Slim\Csrf\Guard();
    };

73 74 75 76 77 78

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


79
    $events = $container['events'];
Vassilis Kanellopoulos's avatar
Vassilis Kanellopoulos committed
80

81 82 83
    $events('on', 'bootstrap', function () use ($container) {
        session_name('GrEduLabs');
        session_start();
Vassilis Kanellopoulos's avatar
Vassilis Kanellopoulos committed
84
    }, 100000000000);
85 86

    $events('on', 'bootstrap', function () use ($container) {
Vassilis Kanellopoulos's avatar
Vassilis Kanellopoulos committed
87 88 89 90 91
        foreach ($container['router']->getRoutes() as $route) {
            if ('user.login' === $route->getName()) {
                $route->add('csrf');
                break;
            }
92 93 94 95
        }
    });


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

98
};