bootstrap.php 9.74 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
    $events('on', 'app.autoload', function ($autoloader) {
22
23
        $autoloader->addPsr4('GrEduLabs\\Schools\\', __DIR__ . '/src/');
    });
24

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

        // actions

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

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

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

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

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

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

Vassilis Kanellopoulos's avatar
Vassilis Kanellopoulos committed
71
72
73
74
75
76
        $container[Action\Lab\DeleteLab::class] = function ($c) {
            return new Action\Lab\DeleteLab(
                $c->get(Service\LabServiceInterface::class)
            );
        };

kanellov's avatar
kanellov committed
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
        $container[Action\Lab\DownloadAttachment::class] = function ($c) {
            $settings = $c->get('settings');
            $uploadTargetPath = $settings['schools']['file_upload']['target_path'];

            return new Action\Lab\DownloadAttachment(
                $c->get(Service\LabServiceInterface::class),
                $uploadTargetPath
            );
        };

        $container[Action\Lab\RemoveAttachment::class] = function ($c) {
            return new Action\Lab\RemoveAttachment(
                $c->get(Service\LabServiceInterface::class)
            );
        };

93
94
        $container[Action\Assets\ListAssets::class] = function ($c) {
            return new Action\Assets\ListAssets(
95
                $c->get('view'),
96
97
98
                $c->get(Service\AssetServiceInterface::class),
                $c->get(Service\SchoolAssetsInterface::class),
                $c->get(Service\LabServiceInterface::class)
99
100
101
            );
        };

102
103
104
        $container[Action\Assets\PersistAsset::class] = function ($c) {
            return new Action\Assets\PersistAsset(
                $c->get(Service\SchoolAssetsInterface::class)
105
106
107
            );
        };

108
109
110
        $container[Action\Assets\DeleteAsset::class] = function ($c) {
            return new Action\Assets\DeleteAsset(
                $c->get(Service\SchoolAssetsInterface::class)
111
            );
112
        };
113

Georgios Tsakalos's avatar
Georgios Tsakalos committed
114
115
116
        $container[Action\Software\ListAll::class] = function ($c) {
            return new Action\Software\ListAll(
                $c->get('view'),
117
118
                $c->get(Service\SoftwareServiceInterface::class),
                $c->get(Service\LabServiceInterface::class)
Georgios Tsakalos's avatar
Georgios Tsakalos committed
119
120
121
            );
        };

Georgios Tsakalos's avatar
Georgios Tsakalos committed
122
123
124
125
126
127
        $container[Action\Software\PersistSoftware::class] = function ($c) {
            return new Action\Software\PersistSoftware(
                $c->get(Service\SoftwareServiceInterface::class)
            );
        };

Georgios Tsakalos's avatar
Georgios Tsakalos committed
128
        $container[Action\Software\DeleteSoftware::class] = function ($c) {
Georgios Tsakalos's avatar
Georgios Tsakalos committed
129
130
131
132
133
            return new Action\Software\DeleteSoftware(
                $c->get(Service\SoftwareServiceInterface::class)
            );
        };

134
135
        // services

kanellov's avatar
kanellov committed
136
        $container['schoolservice'] = function ($c) {
137
            return $c->get(Service\SchoolServiceInterface::class);
138
139
        };

140
        $container['staffservice'] = function ($c) {
141
            return $c->get(Service\StaffServiceInterface::class);
142
143
144
        };

        $container['labservice'] = function ($c) {
145
            return $c->get(Service\LabServiceInterface::class);
146
147
        };

148
149
        $container[Service\SchoolServiceInterface::class] = function ($c) {
            return new Service\SchoolService();
150
151
        };

152
153
        $container[Service\StaffServiceInterface::class] = function ($c) {
            return new Service\StaffService();
154
155
        };

156
        $container[Service\LabServiceInterface::class] = function ($c) {
kanellov's avatar
kanellov committed
157
158
159
160
            $settings = $c->get('settings');
            $uploadTargetPath = $settings['schools']['file_upload']['target_path'];

            return new Service\LabService($uploadTargetPath);
161
162
        };

Georgios Tsakalos's avatar
Georgios Tsakalos committed
163
164
165
166
        $container[Service\SoftwareServiceInterface::class] = function ($c) {
            return new Service\SoftwareService();
        };

167
168
        $container[Service\AssetServiceInterface::class] = function ($c) {
            return new Service\AssetService();
169
170
        };

171
172
        $container[Service\SchoolAssetsInterface::class] = function ($c) {
            return $c->get(Service\AssetServiceInterface::class);
173
174
175
176
        };

        // middleware 

177
178
179
        $container[Middleware\InputFilterTeacher::class] = function ($c) {
            return new Middleware\InputFilterTeacher(
                $c->get(InputFilter\Teacher::class)
kanellov's avatar
kanellov committed
180
            );
181
182
        };

183
184
185
186
187
188
        $container[Middleware\InputFilterLab::class] = function ($c) {
            return new Middleware\InputFilterLab(
                $c->get(InputFilter\Lab::class)
            );
        };

189
190
191
        $container[Middleware\InputFilterSchoolAsset::class] = function ($c) {
            return new Middleware\InputFilterSchoolAsset(
                $c->get(InputFilter\SchoolAsset::class)
kanellov's avatar
kanellov committed
192
193
194
            );
        };

195
196
197
198
199
200
        $container[Middleware\InputFilterSoftware::class] = function ($c) {
            return new Middleware\InputFilterSoftware(
                $c->get(InputFilter\Software::class)
            );
        };

201
202
        $container[Middleware\FetchSchoolFromIdentity::class] = function ($c) {
            return new Middleware\FetchSchoolFromIdentity($c['authentication_service']);
203
        };
204

205
206
        // inputfilters

207
208
209
210
211
212
213
214
215
        $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)
            );
216
217
        };

218
219
220
        $container[InputFilter\School::class] = function ($c) {
            return new InputFilter\School(
                $c->get(Service\SchoolServiceInterface::class)
221
222
223
            );
        };

224
        $container[InputFilter\Lab::class] = function ($c) {
225
            $settings = $c->get('settings');
kanellov's avatar
kanellov committed
226
            $uploadTmpPath = $settings['schools']['file_upload']['tmp_path'];
227
            $attachmentSize = $settings['schools']['file_upload']['max_size'];
kanellov's avatar
kanellov committed
228

229
            return new InputFilter\Lab(
kanellov's avatar
kanellov committed
230
                $uploadTmpPath,
231
232
                $c->get(Service\LabServiceInterface::class),
                $attachmentSize
233
            );
234
235
        };

236
237
238
239
        $container[InputFilter\Software::class] = function ($c) {
            return new InputFilter\Software();
        };

240
    });
241

242
    $events('on', 'app.bootstrap', function ($app, $container) {
243
244
        $container['view']->getEnvironment()->getLoader()->prependPath(__DIR__ . '/templates');

245
        $app->group('/school', function () {
246

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

249
250
251
252
            $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);
253

254
            $this->get('/labs', Action\Lab\ListAll::class)->setName('school.labs');
kanellov's avatar
kanellov committed
255
            $this->post('/labs', Action\Lab\PersistLab::class)
256
                ->add(Middleware\InputFilterLab::class);
Vassilis Kanellopoulos's avatar
Vassilis Kanellopoulos committed
257
            $this->delete('/labs', Action\Lab\DeleteLab::class);
kanellov's avatar
kanellov committed
258
259
260
            $this->get('/labs/attachment', Action\Lab\DownloadAttachment::class)
                ->setName('school.labs.attachment');
            $this->delete('/labs/attachment', Action\Lab\RemoveAttachment::class);
261

262
263
264
265
            $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);
266

Georgios Tsakalos's avatar
Georgios Tsakalos committed
267
            $this->get('/software', Action\Software\ListAll::class)->setName('school.software');
268
269
            $this->post('/software', Action\Software\PersistSoftware::class)
                ->add(Middleware\InputFilterSoftware::class);
270
            $this->delete('/software', Action\Software\DeleteSoftware::class);
Georgios Tsakalos's avatar
Georgios Tsakalos committed
271

272
        })->add(Middleware\FetchSchoolFromIdentity::class);
kanellov's avatar
kanellov committed
273
    });
274
};