bootstrap.php 3.67 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13
<?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();
14
    $events    = $container['events'];
15

16 17 18
    $events('on', 'app.autoload', function ($stop, $autoloader) {
        $autoloader->addPsr4('GrEduLabs\\Schools\\', __DIR__ . '/src/');
    });
19

20 21
    $events('on', 'app.services', function ($stop, $container) {
        $container[GrEduLabs\Schools\Action\Index::class] = function ($c) {
22 23 24
            return new GrEduLabs\Schools\Action\Index(
                 $c->get('view'),
                 $c->get('schoolservice')
25
            );
26
        };
27

28
        $container[GrEduLabs\Schools\Action\Staff::class] = function ($c) {
29 30 31
            return new GrEduLabs\Schools\Action\Staff(
                $c->get('view'),
                $c->get('staffservice')
32
            );
33
        };
34

35 36 37
        $container[GrEduLabs\Schools\Action\StaffCreate::class] = function ($c) {
            return new GrEduLabs\Schools\Action\StaffCreate(
                $c->get('staffservice')
38
            );
39
        };
40

41
        $container[GrEduLabs\Schools\Action\Labs::class] = function ($c) {
42 43
            return new GrEduLabs\Schools\Action\Labs(
                $c->get('view')
44
            );
45
        };
46

47 48 49 50
        $container[GrEduLabs\Schools\Action\LabCreate::class] = function ($c) {
            return new GrEduLabs\Schools\Action\LabCreate(
                 $c->get('labservice')
            );
51
        };
52

53 54 55
        $container[GrEduLabs\Schools\Action\Assets::class] = function ($c) {
            return new GrEduLabs\Schools\Action\Assets($c->get('view'));
        };
56

kanellov's avatar
kanellov committed
57 58
        $container['schoolservice'] = function ($c) {
            return new GrEduLabs\Schools\Service\SchoolService();
59 60
        };

kanellov's avatar
kanellov committed
61 62
        $container['staffservice'] = function ($c) {
            return new GrEduLabs\Schools\Service\StaffService(
kanellov's avatar
kanellov committed
63
                new GrEduLabs\Schools\Filter\Teacher()
kanellov's avatar
kanellov committed
64
            );
65 66
        };

kanellov's avatar
kanellov committed
67 68 69 70 71
        $container['labservice'] = function ($c) {
            return new GrEduLabs\Schools\Service\LabService(
                $c->get('schoolservice'),
                $c->get('staffservice')
            );
72 73
        };

kanellov's avatar
kanellov committed
74 75 76 77 78 79 80 81 82
        $container['assetservice'] = function ($c) {
            return new GrEduLabs\Schools\Service\AssetService(
                $c->get('schoolservice'),
                $c->get('labservice')
            );
        };

        $container[GrEduLabs\Schools\Middleware\FetchSchoolFromIdentity::class] = function ($c) {
            return new GrEduLabs\Schools\Middleware\FetchSchoolFromIdentity($c['authentication_service']);
83
        };
84

85
    });
86

87
    $events('on', 'app.bootstrap', function ($stop, $app, $container) {
88 89
        $container['view']->getEnvironment()->getLoader()->prependPath(__DIR__ . '/templates');

90 91 92
        $app->group('/school', function () {
            $this->get('', GrEduLabs\Schools\Action\Index::class)->setName('school');
            $this->get('/staff', GrEduLabs\Schools\Action\Staff::class)->setName('school.staff');
93
            $this->post('/staff', GrEduLabs\Schools\Action\StaffCreate::class)->setName('school.staffcreate');
94
            $this->get('/labs', GrEduLabs\Schools\Action\Labs::class)->setName('school.labs');
95
            $this->post('/labs', GrEduLabs\Schools\Action\LabCreate::class)->setName('school.labcreate');
96
            $this->get('/assets', GrEduLabs\Schools\Action\Assets::class)->setName('school.assets');
kanellov's avatar
kanellov committed
97 98
        })->add(GrEduLabs\Schools\Middleware\FetchSchoolFromIdentity::class);
    });
99
};