bootstrap.php 6.41 KB
Newer Older
1 2 3 4 5 6 7 8 9 10
<?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
 */

11 12 13 14 15
use GrEduLabs\Schools\Action;
use GrEduLabs\Schools\InputFilter;
use GrEduLabs\Schools\Middleware;
use GrEduLabs\Schools\Service;

16 17 18
return function (Slim\App $app) {

    $container = $app->getContainer();
19
    $events    = $container['events'];
20

21 22 23
    $events('on', 'app.autoload', function ($stop, $autoloader) {
        $autoloader->addPsr4('GrEduLabs\\Schools\\', __DIR__ . '/src/');
    });
24

25
    $events('on', 'app.services', function ($stop, $container) {
26 27 28

        // actions

29 30
        $container[Action\Index::class] = function ($c) {
            return new Action\Index(
31
                 $c->get('view'),
32
                 $c->get(Service\SchoolServiceInterface::class)
33
            );
34
        };
35

36 37
        $container[Action\Staff\ListAll::class] = function ($c) {
            return new Action\Staff\ListAll(
38
                $c->get('view'),
39
                $c->get(Service\StaffServiceInterface::class)
40
            );
41
        };
42

43 44 45
        $container[Action\Staff\PersistTeacher::class] = function ($c) {
            return new Action\Staff\PersistTeacher(
                $c->get(Service\StaffServiceInterface::class)
46 47 48
            );
        };

49 50 51
        $container[Action\Staff\DeleteTeacher::class] = function ($c) {
            return new Action\Staff\DeleteTeacher(
                $c->get(Service\StaffServiceInterface::class)
52
            );
53
        };
54

55
        $container[Action\Lab\ListAll::class] = function ($c) {
56 57
            return new GrEduLabs\Schools\Action\Lab\ListAll(
                $c->get('view'),
58 59
                $c->get(Service\LabServiceInterface::class),
                $c->get(Service\StaffServiceInterface::class)
60
            );
61
        };
62

63 64 65
        $container[Action\Lab\PersistLab::class] = function ($c) {
            return new PersistLab(
                 $c->get(Service\LabServiceInterface::class)
66
            );
67
        };
68

69 70
        $container[Action\Assets\ListAssets::class] = function ($c) {
            return new Action\Assets\ListAssets(
71
                $c->get('view'),
72 73 74
                $c->get(Service\AssetServiceInterface::class),
                $c->get(Service\SchoolAssetsInterface::class),
                $c->get(Service\LabServiceInterface::class)
75 76 77
            );
        };

78 79 80
        $container[Action\Assets\PersistAsset::class] = function ($c) {
            return new Action\Assets\PersistAsset(
                $c->get(Service\SchoolAssetsInterface::class)
81 82 83
            );
        };

84 85 86
        $container[Action\Assets\DeleteAsset::class] = function ($c) {
            return new Action\Assets\DeleteAsset(
                $c->get(Service\SchoolAssetsInterface::class)
87
            );
88
        };
89

90 91
        // services

kanellov's avatar
kanellov committed
92
        $container['schoolservice'] = function ($c) {
93
            return $c->get(Service\SchoolServiceInterface::class);
94 95
        };

96
        $container['staffservice'] = function ($c) {
97
            return $c->get(Service\StaffServiceInterface::class);
98 99 100
        };

        $container['labservice'] = function ($c) {
101
            return $c->get(Service\LabServiceInterface::class);
102 103
        };

104 105
        $container[Service\SchoolServiceInterface::class] = function ($c) {
            return new Service\SchoolService();
106 107
        };

108 109
        $container[Service\StaffServiceInterface::class] = function ($c) {
            return new Service\StaffService();
110 111
        };

112 113 114 115
        $container[Service\LabServiceInterface::class] = function ($c) {
            return new Service\LabService(
                $c->get(Service\SchoolServiceInterface::class),
                $c->get(Service\StaffServiceInterface::class)
kanellov's avatar
kanellov committed
116
            );
117 118
        };

119 120
        $container[Service\AssetServiceInterface::class] = function ($c) {
            return new Service\AssetService();
121 122
        };

123 124
        $container[Service\SchoolAssetsInterface::class] = function ($c) {
            return $c->get(Service\AssetServiceInterface::class);
125 126 127 128
        };

        // middleware 

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

135 136 137
        $container[Middleware\InputFilterSchoolAsset::class] = function ($c) {
            return new Middleware\InputFilterSchoolAsset(
                $c->get(InputFilter\SchoolAsset::class)
kanellov's avatar
kanellov committed
138 139 140
            );
        };

141 142
        $container[Middleware\FetchSchoolFromIdentity::class] = function ($c) {
            return new Middleware\FetchSchoolFromIdentity($c['authentication_service']);
143
        };
144

145 146
        // inputfilters

147 148 149 150 151 152 153 154 155
        $container[InputFilter\Teacher::class] = function ($c) {
            return new InputFilter\Teacher();
        };

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

158 159 160
        $container[InputFilter\School::class] = function ($c) {
            return new InputFilter\School(
                $c->get(Service\SchoolServiceInterface::class)
161 162 163
            );
        };

164
    });
165

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

169
        $app->group('/school', function () {
170

171
            $this->get('', Action\Index::class)->setName('school');
172

173 174 175 176
            $this->get('/staff', Action\Staff\ListAll::class)->setName('school.staff');
            $this->post('/staff', Action\Staff\PersistTeacher::class)
                ->add(Middleware\InputFilterTeacher::class);
            $this->delete('/staff', Action\Staff\DeleteTeacher::class);
177

178 179
            $this->get('/labs', Action\Lab\ListAll::class)->setName('school.labs');
            $this->post('/labs', Action\Lab\PersistLab::class)->setName('school.labcreate');
180

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

186
        })->add(Middleware\FetchSchoolFromIdentity::class);
kanellov's avatar
kanellov committed
187
    });
188
};