bootstrap.php 4.65 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 29
        $container[GrEduLabs\Schools\Action\Staff\ListAll::class] = function ($c) {
            return new GrEduLabs\Schools\Action\Staff\ListAll(
30
                $c->get('view'),
31
                $c->get(GrEduLabs\Schools\Service\StaffService::class)
32
            );
33
        };
34

35 36 37 38 39 40 41 42 43
        $container[GrEduLabs\Schools\Action\Staff\PersistTeacher::class] = function ($c) {
            return new GrEduLabs\Schools\Action\Staff\PersistTeacher(
                $c->get(GrEduLabs\Schools\Service\StaffService::class)
            );
        };

        $container[GrEduLabs\Schools\Action\Staff\DeleteTeacher::class] = function ($c) {
            return new GrEduLabs\Schools\Action\Staff\DeleteTeacher(
                $c->get(GrEduLabs\Schools\Service\StaffService::class)
44
            );
45
        };
46

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

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

59 60 61
        $container[GrEduLabs\Schools\Action\Assets::class] = function ($c) {
            return new GrEduLabs\Schools\Action\Assets($c->get('view'));
        };
62

kanellov's avatar
kanellov committed
63 64
        $container['schoolservice'] = function ($c) {
            return new GrEduLabs\Schools\Service\SchoolService();
65 66
        };

67 68 69 70 71 72 73 74 75 76 77
        $container[GrEduLabs\Schools\InputFilter\Teacher::class] = function ($c) {
            return new GrEduLabs\Schools\InputFilter\Teacher();
        };

        $container[GrEduLabs\Schools\Service\StaffService::class] = function ($c) {
            return new GrEduLabs\Schools\Service\StaffService();
        };

        $container[GrEduLabs\Schools\Middleware\InputFilterTeacher::class] = function ($c) {
            return new GrEduLabs\Schools\Middleware\InputFilterTeacher(
                $c->get(GrEduLabs\Schools\InputFilter\Teacher::class)
kanellov's avatar
kanellov committed
78
            );
79 80
        };

kanellov's avatar
kanellov committed
81 82 83 84 85
        $container['labservice'] = function ($c) {
            return new GrEduLabs\Schools\Service\LabService(
                $c->get('schoolservice'),
                $c->get('staffservice')
            );
86 87
        };

kanellov's avatar
kanellov committed
88 89 90 91 92 93 94 95 96
        $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']);
97
        };
98

99
    });
100

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

104 105
        $app->group('/school', function () {
            $this->get('', GrEduLabs\Schools\Action\Index::class)->setName('school');
106 107 108 109 110 111 112
            $this->get('/staff', GrEduLabs\Schools\Action\Staff\ListAll::class)->setName('school.staff');
            $this->post('/staff', GrEduLabs\Schools\Action\Staff\PersistTeacher::class)
                ->add(GrEduLabs\Schools\Middleware\InputFilterTeacher::class)
                ->setName('school.staffcreate');
            $this->delete('/staff/{id:[1-9][0-9]*}', GrEduLabs\Schools\Action\Staff\DeleteTeacher::class)
                ->setName('school.staffdelete');

113
            $this->get('/labs', GrEduLabs\Schools\Action\Labs::class)->setName('school.labs');
114
            $this->post('/labs', GrEduLabs\Schools\Action\LabCreate::class)->setName('school.labcreate');
115
            $this->get('/assets', GrEduLabs\Schools\Action\Assets::class)->setName('school.assets');
kanellov's avatar
kanellov committed
116 117
        })->add(GrEduLabs\Schools\Middleware\FetchSchoolFromIdentity::class);
    });
118
};