bootstrap.php 7.17 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
    $events('on', 'app.services', function ($stop, $container) {
21 22 23

        // actions

24
        $container[GrEduLabs\Schools\Action\Index::class] = function ($c) {
25 26 27
            return new GrEduLabs\Schools\Action\Index(
                 $c->get('view'),
                 $c->get('schoolservice')
28
            );
29
        };
30

31 32
        $container[GrEduLabs\Schools\Action\Staff\ListAll::class] = function ($c) {
            return new GrEduLabs\Schools\Action\Staff\ListAll(
33
                $c->get('view'),
34
                $c->get(GrEduLabs\Schools\Service\StaffServiceInterface::class)
35
            );
36
        };
37

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

        $container[GrEduLabs\Schools\Action\Staff\DeleteTeacher::class] = function ($c) {
            return new GrEduLabs\Schools\Action\Staff\DeleteTeacher(
46
                $c->get(GrEduLabs\Schools\Service\StaffServiceInterface::class)
47
            );
48
        };
49

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

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

62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80
        $container[GrEduLabs\Schools\Action\Assets\ListAssets::class] = function ($c) {
            return new GrEduLabs\Schools\Action\Assets\ListAssets(
                $c->get('view'),
                $c->get(GrEduLabs\Schools\Service\AssetServiceInterface::class),
                $c->get(GrEduLabs\Schools\Service\SchoolAssetsInterface::class),
                $c->get(GrEduLabs\Schools\Service\LabServiceInterface::class)
            );
        };

        $container[GrEduLabs\Schools\Action\Assets\PersistAsset::class] = function ($c) {
            return new GrEduLabs\Schools\Action\Assets\PersistAsset(
                $c->get(GrEduLabs\Schools\Service\SchoolAssetsInterface::class)
            );
        };

        $container[GrEduLabs\Schools\Action\Assets\DeleteAsset::class] = function ($c) {
            return new GrEduLabs\Schools\Action\Assets\DeleteAsset(
                $c->get(GrEduLabs\Schools\Service\SchoolAssetsInterface::class)
            );
81
        };
82

83 84
        // services

kanellov's avatar
kanellov committed
85
        $container['schoolservice'] = function ($c) {
86
            return $c->get(GrEduLabs\Schools\Service\SchoolServiceInterface::class);
87 88
        };

89 90 91 92 93 94
        $container['staffservice'] = function ($c) {
            return $c->get(GrEduLabs\Schools\Service\StaffServiceInterface::class);
        };

        $container['labservice'] = function ($c) {
            return $c->get(GrEduLabs\Schools\Service\LabServiceInterface::class);
95 96
        };

97 98 99 100 101
        $container[GrEduLabs\Schools\Service\SchoolServiceInterface::class] = function ($c) {
            return new GrEduLabs\Schools\Service\SchoolService();
        };

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

105 106 107 108
        $container[GrEduLabs\Schools\Service\LabServiceInterface::class] = function ($c) {
            return new GrEduLabs\Schools\Service\LabService(
                $c->get(GrEduLabs\Schools\Service\SchoolServiceInterface::class),
                $c->get(GrEduLabs\Schools\Service\StaffServiceInterface::class)
kanellov's avatar
kanellov committed
109
            );
110 111
        };

112 113 114 115 116 117 118 119 120 121 122 123 124
        $container[GrEduLabs\Schools\Service\AssetServiceInterface::class] = function ($c) {
            return new GrEduLabs\Schools\Service\AssetService();
        };

        $container[GrEduLabs\Schools\Service\SchoolAssetsInterface::class] = function ($c) {
            return $c->get(GrEduLabs\Schools\Service\AssetServiceInterface::class);
        };

        // middleware 

        $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
125
            );
126 127
        };

128 129 130
        $container[GrEduLabs\Schools\Middleware\InputFilterSchoolAsset::class] = function ($c) {
            return new GrEduLabs\Schools\Middleware\InputFilterSchoolAsset(
                $c->get(GrEduLabs\Schools\InputFilter\SchoolAsset::class)
kanellov's avatar
kanellov committed
131 132 133 134 135
            );
        };

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

138 139 140 141 142 143 144 145 146 147 148 149 150
        // inputfilters

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

        $container[GrEduLabs\Schools\InputFilter\SchoolAsset::class] = function ($c) {
            return new GrEduLabs\Schools\InputFilter\SchoolAsset(
                $c->get(GrEduLabs\Schools\Service\LabServiceInterface::class),
                $c->get(GrEduLabs\Schools\Service\AssetServiceInterface::class)
            );
        };

151
    });
152

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

156
        $app->group('/school', function () {
157

158
            $this->get('', GrEduLabs\Schools\Action\Index::class)->setName('school');
159

160 161 162 163 164 165 166
            $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');

167
            $this->get('/labs', GrEduLabs\Schools\Action\Labs::class)->setName('school.labs');
168
            $this->post('/labs', GrEduLabs\Schools\Action\LabCreate::class)->setName('school.labcreate');
169 170 171 172 173 174

            $this->get('/assets', GrEduLabs\Schools\Action\Assets\ListAssets::class)->setName('school.assets');
            $this->post('/assets', GrEduLabs\Schools\Action\Assets\PersistAsset::class)
                ->add(GrEduLabs\Schools\Middleware\InputFilterSchoolAsset::class);
            $this->delete('/assets', GrEduLabs\Schools\Action\Assets\DeleteAsset::class);

kanellov's avatar
kanellov committed
175 176
        })->add(GrEduLabs\Schools\Middleware\FetchSchoolFromIdentity::class);
    });
177
};