forked from centreon/centreon-archived
-
Notifications
You must be signed in to change notification settings - Fork 0
/
container.php
97 lines (84 loc) · 3.13 KB
/
container.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
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
87
88
89
90
91
92
93
94
95
96
97
<?php
/*
* Copyright 2005 - 2019 Centreon (https://www.centreon.com/)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* For more information : [email protected]
*
*/
// Creating container
use Pimple\Container;
$dependencyInjector = \Centreon\LegacyContainer::getInstance();
// Define Centreon Configuration Database Connection
$dependencyInjector['configuration_db'] = function ($c) {
return new \CentreonDB('centreon');
};
// Define Centreon Realtime Database Connection
$dependencyInjector['realtime_db'] = function ($c) {
return new \CentreonDB('centstorage');
};
// Define Centreon Rest Http Client
$dependencyInjector['rest_http'] = function ($c) {
return new \CentreonRestHttp();
};
// Define filesystem
$dependencyInjector['filesystem'] = function ($c) {
return new \Symfony\Component\Filesystem\Filesystem();
};
// Utils
$dependencyInjector['utils'] = function ($c) use ($dependencyInjector) {
return $dependencyInjector[CentreonLegacy\ServiceProvider::CENTREON_LEGACY_UTILS];
};
// Define finder
$dependencyInjector['finder'] = $dependencyInjector->factory(function ($c) {
return new \Symfony\Component\Finder\Finder();
});
// Define Language translator
$dependencyInjector['translator'] = $dependencyInjector->factory(function ($c) {
global $centreon;
$translator = new CentreonLang(_CENTREON_PATH_, $centreon);
$translator->bindLang();
$translator->bindLang('help');
return $translator;
});
$dependencyInjector['path.files_generation'] = _CENTREON_PATH_ . '/filesGeneration/';
// Defines the web service that will transform the translation files into one json file
$dependencyInjector[CentreonI18n::class] = function ($container) {
require_once _CENTREON_PATH_ . '/www/api/class/centreon_i18n.class.php';
$lang = getenv('LANG');
if ($lang === false) {
// Initialize the language translator
$container['translator'];
$lang = getenv('LANG');
}
if (strstr($lang, '.UTF-8') === false) {
$lang .= '.UTF-8';
}
$translationFile = _CENTREON_PATH_ . "www/locale/{$lang}/LC_MESSAGES/messages.ser";
$translation = new CentreonI18n();
$translation->setFilesGenerationPath($translationFile);
return $translation;
};
// Dynamically register service provider
Centreon\Infrastructure\Provider\AutoloadServiceProvider::register($dependencyInjector);
// Centreon configuration files
$configFiles = $dependencyInjector['finder']
->files()
->name('*.config.php')
->depth('== 0')
->in(__DIR__ . '/config');
foreach ($configFiles as $configFile) {
$configFileName = $configFile->getBasename();
require __DIR__ . '/config/' . $configFileName;
}