|
1
|
|
|
<?php |
|
2
|
|
|
/* |
|
3
|
|
|
* MikoPBX - free phone system for small business |
|
4
|
|
|
* Copyright (C) 2017-2020 Alexey Portnov and Nikolay Beketov |
|
5
|
|
|
* |
|
6
|
|
|
* This program is free software: you can redistribute it and/or modify |
|
7
|
|
|
* it under the terms of the GNU General Public License as published by |
|
8
|
|
|
* the Free Software Foundation; either version 3 of the License, or |
|
9
|
|
|
* (at your option) any later version. |
|
10
|
|
|
* |
|
11
|
|
|
* This program is distributed in the hope that it will be useful, |
|
12
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
13
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
14
|
|
|
* GNU General Public License for more details. |
|
15
|
|
|
* |
|
16
|
|
|
* You should have received a copy of the GNU General Public License along with this program. |
|
17
|
|
|
* If not, see <https://www.gnu.org/licenses/>. |
|
18
|
|
|
*/ |
|
19
|
|
|
|
|
20
|
|
|
declare(strict_types=1); |
|
21
|
|
|
|
|
22
|
|
|
namespace MikoPBX\Common\Providers; |
|
23
|
|
|
|
|
24
|
|
|
use MikoPBX\Common\Models\PbxSettings; |
|
25
|
|
|
use MikoPBX\PBXCoreREST\Workers\WorkerApiCommands; |
|
26
|
|
|
use Phalcon\Di\DiInterface; |
|
27
|
|
|
use Phalcon\Di\ServiceProviderInterface; |
|
28
|
|
|
|
|
29
|
|
|
/** |
|
30
|
|
|
* The URL component is used to generate all kind of urls in the application |
|
31
|
|
|
*/ |
|
32
|
|
|
class LanguageProvider implements ServiceProviderInterface |
|
33
|
|
|
{ |
|
34
|
|
|
public const SERVICE_NAME = 'language'; |
|
35
|
|
|
|
|
36
|
|
|
/** |
|
37
|
|
|
* Register language service provider |
|
38
|
|
|
* |
|
39
|
|
|
* @param \Phalcon\Di\DiInterface $di |
|
40
|
|
|
*/ |
|
41
|
|
|
public function register(DiInterface $di): void |
|
42
|
|
|
{ |
|
43
|
|
|
$di->setShared( |
|
44
|
|
|
self::SERVICE_NAME, |
|
45
|
|
|
function () use ($di){ |
|
46
|
|
|
if (php_sapi_name() === 'cli') { |
|
47
|
|
|
if (cli_get_process_title() === WorkerApiCommands::class) { |
|
48
|
|
|
$language = PbxSettings::getValueByKey('WebAdminLanguage'); |
|
49
|
|
|
} else { |
|
50
|
|
|
$language = PbxSettings::getValueByKey('SSHLanguage'); |
|
51
|
|
|
} |
|
52
|
|
|
} else { |
|
53
|
|
|
$roSession = $di->getShared(SessionReadOnlyProvider::SERVICE_NAME); |
|
54
|
|
|
if ($roSession !== null && array_key_exists( |
|
55
|
|
|
'WebAdminLanguage', |
|
56
|
|
|
$roSession |
|
57
|
|
|
) && ! empty($roSession['WebAdminLanguage'])) { |
|
58
|
|
|
$language = $roSession['WebAdminLanguage']; |
|
59
|
|
|
} else { |
|
60
|
|
|
$language = PbxSettings::getValueByKey('WebAdminLanguage'); |
|
61
|
|
|
} |
|
62
|
|
|
} |
|
63
|
|
|
return $language; |
|
64
|
|
|
} |
|
65
|
|
|
); |
|
66
|
|
|
} |
|
67
|
|
|
} |