dependencies.php 5.61 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
<?php

/*
 * This file is part of Anis Server.
 *
 * (c) Laboratoire d'Astrophysique de Marseille / CNRS
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */
declare(strict_types=1);

use Psr\Container\ContainerInterface;

// Load settings
$container->set(SETTINGS, function () {
    return include __DIR__ . '/../app/settings.php';
});

// Doctrine factory
$container->set('em', function (ContainerInterface $c) {
    $settings = $c->get(SETTINGS)['database'];
François Agneray's avatar
François Agneray committed
23
24
25
26
27
28
    $devMode = boolval($settings['dev_mode']);
    $proxyDir = getcwd() . '/../doctrine-proxy';
    $cache = null;
    if ($devMode == false) {
        $cache = new \Doctrine\Common\Cache\ApcuCache();
    }
29
30
    $dc = \Doctrine\ORM\Tools\Setup::createAnnotationMetadataConfiguration(
        array('src/Entity'),
François Agneray's avatar
François Agneray committed
31
32
33
        $devMode,
        $proxyDir,
        $cache
34
    );
François Agneray's avatar
François Agneray committed
35
36
37
38
    $dc->setAutogenerateProxyClasses(false);
    
    if ($devMode) {
        $dc->setSQLLogger(new \Doctrine\DBAL\Logging\DebugStack());
39
    } else {
François Agneray's avatar
François Agneray committed
40
        $dc->setQueryCacheImpl($cache);
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
    }
    return \Doctrine\ORM\EntityManager::create($settings['connection_options'], $dc);
});

// Monolog factory
$container->set('logger', function (ContainerInterface $c) {
    $loggerSettings = $c->get('settings')['logger'];
    $logger = new \Monolog\Logger($loggerSettings['name']);
    $logger->pushProcessor(new \Monolog\Processor\UidProcessor());
    $logger->pushHandler(new \Monolog\Handler\StreamHandler($loggerSettings['path'], $loggerSettings['level']));
    return $logger;
});

// Actions
$container->set('App\Action\RootAction', function () {
    return new App\Action\RootAction();
});

$container->set('App\Action\DatabaseListAction', function (ContainerInterface $c) {
    return new App\Action\DatabaseListAction($c->get('em'));
});

$container->set('App\Action\DatabaseAction', function (ContainerInterface $c) {
    return new App\Action\DatabaseAction($c->get('em'));
});

$container->set('App\Action\TableListAction', function (ContainerInterface $c) {
    return new App\Action\TableListAction($c->get('em'), new App\Utils\DBALConnectionFactory());
});

$container->set('App\Action\ProjectListAction', function (ContainerInterface $c) {
    return new App\Action\ProjectListAction($c->get('em'));
});

$container->set('App\Action\ProjectAction', function (ContainerInterface $c) {
    return new App\Action\ProjectAction($c->get('em'));
});

$container->set('App\Action\FamilyListAction', function (ContainerInterface $c) {
    return new App\Action\FamilyListAction($c->get('em'));
});

$container->set('App\Action\FamilyAction', function (ContainerInterface $c) {
    return new App\Action\FamilyAction($c->get('em'));
});

87
88
89
90
91
92
93
94
$container->set('App\Action\InstanceListAction', function (ContainerInterface $c) {
    return new App\Action\InstanceListAction($c->get('em'));
});

$container->set('App\Action\InstanceAction', function (ContainerInterface $c) {
    return new App\Action\InstanceAction($c->get('em'));
});

95
96
97
98
$container->set('App\Action\DatasetFamilyListAction', function (ContainerInterface $c) {
    return new App\Action\DatasetFamilyListAction($c->get('em'));
});

99
100
101
102
$container->set('App\Action\DatasetListByInstanceAction', function (ContainerInterface $c) {
    return new App\Action\DatasetListByInstanceAction($c->get('em'));
});

103
104
105
106
$container->set('App\Action\DatasetFamilyAction', function (ContainerInterface $c) {
    return new App\Action\DatasetFamilyAction($c->get('em'));
});

107
108
109
110
111
$container->set('App\Action\DatasetListAction', function (ContainerInterface $c) {
    return new App\Action\DatasetListAction($c->get('em'), new App\Utils\DBALConnectionFactory());
});

$container->set('App\Action\DatasetAction', function (ContainerInterface $c) {
112
    return new App\Action\DatasetAction($c->get('em'));
113
114
});

115
$container->set('App\Action\CriteriaFamilyListAction', function (ContainerInterface $c) {
116
    return new App\Action\CriteriaFamilyListAction($c->get('em'));
117
118
119
});

$container->set('App\Action\CriteriaFamilyAction', function (ContainerInterface $c) {
120
    return new App\Action\CriteriaFamilyAction($c->get('em'));
121
122
});

123
$container->set('App\Action\OutputFamilyListAction', function (ContainerInterface $c) {
124
    return new App\Action\OutputFamilyListAction($c->get('em'));
125
126
});

François Agneray's avatar
François Agneray committed
127
$container->set('App\Action\OutputFamilyAction', function (ContainerInterface $c) {
128
129
130
131
132
    return new App\Action\OutputFamilyAction($c->get('em'));
});

$container->set('App\Action\OutputCategoryListByDatasetAction', function (ContainerInterface $c) {
    return new App\Action\OutputCategoryListByDatasetAction($c->get('em'));
François Agneray's avatar
François Agneray committed
133
134
135
136
137
138
139
140
141
142
});

$container->set('App\Action\OutputCategoryListAction', function (ContainerInterface $c) {
    return new App\Action\OutputCategoryListAction($c->get('em'));
});

$container->set('App\Action\OutputCategoryAction', function (ContainerInterface $c) {
    return new App\Action\OutputCategoryAction($c->get('em'));
});

143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
$container->set('App\Action\AttributeListAction', function (ContainerInterface $c) {
    return new App\Action\AttributeListAction($c->get('em'));
});

$container->set('App\Action\AttributeAction', function (ContainerInterface $c) {
    return new App\Action\AttributeAction($c->get('em'));
});

$container->set('App\Action\SearchAction', function (ContainerInterface $c) {
    return new App\Action\SearchAction(
        $c->get('em'),
        new App\Utils\DBALConnectionFactory(),
        new App\Utils\Operator\OperatorFactory()
    );
});

// Middlewares
$container->set('App\Middleware\AuthorizationMiddleware', function (ContainerInterface $c) {
    return new App\Middleware\AuthorizationMiddleware($c->get('em'), $c->get(SETTINGS)['token_options']);
});