bootstrap.php 2.69 KB
Newer Older
Vassilis Kanellopoulos's avatar
Vassilis Kanellopoulos committed
1
<?php
2 3

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

21
return function (App $app) {
Vassilis Kanellopoulos's avatar
Vassilis Kanellopoulos committed
22 23

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

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

30
    $events('on', 'app.services', function ($container) {
31 32 33 34 35 36 37
        $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')
38 39
            );
        };
40 41 42 43 44 45 46 47 48 49 50
        $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')
51 52
            );
        };
53
        $container[CreateLabs::class] = function ($c) {
54 55 56 57
            $settings = $c->get('settings');
            $categoryMap = isset($settings['inventory']['category_map'])
                ? $settings['inventory']['category_map'] : [];

58 59 60 61 62 63
            return new CreateLabs(
                $c->get(LabServiceInterface::class),
                $c->get(AssetServiceInterface::class),
                $c->get('SchInventory\\Service'),
                $c->get(SchoolServiceInterface::class),
                $c->get('authentication_service'),
64 65
                $c->get('logger'),
                $categoryMap
66 67
            );
        };
68
    });
Vassilis Kanellopoulos's avatar
Vassilis Kanellopoulos committed
69

70
    $events('on', 'app.bootstrap', function ($app, $container) {
71 72 73 74
        $container['router']->getNamedRoute('user.login.sso')
            ->add(CreateUser::class)
            ->add(CreateSchool::class)
            ->add(CreateLabs::class);
Vassilis Kanellopoulos's avatar
Vassilis Kanellopoulos committed
75
    }, -10);
Vassilis Kanellopoulos's avatar
Vassilis Kanellopoulos committed
76
};