bootstrap.php 2.05 KB
Newer Older
Vassilis Kanellopoulos's avatar
Vassilis Kanellopoulos committed
1
<?php
2
3
4
5
6
7
8

use GrEduLabs\Schools\InputFilter\School as SchoolInputFilter;
use GrEduLabs\Schools\Service\SchoolServiceInterface;
use SchMM\FetchUnit;
use SchSync\Middleware\CreateSchool;
use SchSync\Middleware\CreateUser;
use Slim\App;
Vassilis Kanellopoulos's avatar
Vassilis Kanellopoulos committed
9
10
11
12
13
14
15
16
17
/**
 * 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
 */

18
return function (App $app) {
Vassilis Kanellopoulos's avatar
Vassilis Kanellopoulos committed
19
20

    $container = $app->getContainer();
21
    $events    = $container['events'];
Vassilis Kanellopoulos's avatar
Vassilis Kanellopoulos committed
22

23
24
25
    $events('on', 'app.autoload', function ($stop, $autoloader) {
        $autoloader->addPsr4('SchSync\\', __DIR__ . '/src');
    });
Vassilis Kanellopoulos's avatar
Vassilis Kanellopoulos committed
26

27
    $events('on', 'app.services', function ($stop, $container) {
28
29
30
31
32
33
34
        $container[CreateUser::class] = function ($c) {
            return new CreateUser(
                $c->get('authentication_service'),
                $c->get('router')->pathFor('user.login'),
                $c->get('router')->pathFor('user.logout.sso'),
                $c->get('flash'),
                $c->get('logger')
35
36
            );
        };
37
38
39
40
41
42
43
44
45
46
47
        $container[CreateSchool::class] = function ($c) {
            return new CreateSchool(
                $c->get('ldap'),
                $c->get(FetchUnit::class),
                $c->get('authentication_service'),
                $c->get(SchoolServiceInterface::class),
                $c->get(SchoolInputFilter::class),
                $c->get('router')->pathFor('user.login'),
                $c->get('router')->pathFor('user.logout.sso'),
                $c->get('flash'),
                $c->get('logger')
48
49
50
            );
        };
    });
Vassilis Kanellopoulos's avatar
Vassilis Kanellopoulos committed
51

52
    $events('on', 'app.bootstrap', function ($stop, $app, $container) {
53
        foreach ($container->get('router')->getRoutes() as $route) {
Vassilis Kanellopoulos's avatar
Vassilis Kanellopoulos committed
54
            if ('user.login.sso' === $route->getName()) {
55
56
                $route->add(CreateUser::class)
                    ->add(CreateSchool::class);
Vassilis Kanellopoulos's avatar
Vassilis Kanellopoulos committed
57
58
59
60
                break;
            }
        }
    }, -10);
Vassilis Kanellopoulos's avatar
Vassilis Kanellopoulos committed
61
};