bootstrap.php 3.66 KB
Newer Older
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 71 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 98 99 100 101 102 103 104 105 106 107
<?php
/**
 * gredu_labs
 * 
 * @link https://github.com/eellak/gredu_labs for the canonical source repository
 * @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');

    $container['view'] = function($c) {
        $settings = $c['settings'];
        $view = new Slim\Views\Twig(
            $settings['view']['template_path'],
            $settings['view']['twig']
        );
        $view->addExtension(new Slim\Views\TwigExtension(
            $c['router'],
            $c['request']->getUri()
        ));

        $view->addExtension(new GrEduLabs\Application\Twig\Extension\Navigation(
            $settings['navigation'],
            $c->get('router'),
            $c->get('request')
        ));
        $view->addExtension(new Knlv\Slim\Views\TwigMessages(
            $c['flash']
        ));

        return $view;
    };

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

    $container['logger'] = function ($c) {
        $settings =  $c['settings'];
        $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;
    };

    $container['authenticate_redbean_listener'] = function ($c) {
        return new GrEduLabs\Application\Authentication\RedbeanListener();
    };

    $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']
        );
        
    }, 1000000);
    $events('on', 'authenticate', $container['authenticate_redbean_listener']);

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

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

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

    $container['GrEduLabs\\Application\\Action\\School\\Staff'] = function ($c) {
        return new GrEduLabs\Application\Action\School\Staff($c->get('view'));
    };

    $container['GrEduLabs\\Application\\Action\\School\\Labs'] = function ($c) {
        return new GrEduLabs\Application\Action\School\Labs($c->get('view'));
    };

    $container['GrEduLabs\\Application\\Action\\School\\Assets'] = function ($c) {
        return new GrEduLabs\Application\Action\School\Assets($c->get('view'));
    };

    $app->get('/', 'GrEduLabs\\Application\\Action\\Index')->setName('index');
    $app->group('/school', function () {
        $this->get('', 'GrEduLabs\\Application\\Action\\School\\Index')->setName('school');
        $this->get('/staff', 'GrEduLabs\\Application\\Action\\School\\Staff')->setName('school.staff');
        $this->get('/labs', 'GrEduLabs\\Application\\Action\\School\\Labs')->setName('school.labs');
        $this->get('/assets', 'GrEduLabs\\Application\\Action\\School\\Assets')->setName('school.assets');
    });
};