|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* Copyright (C) MIKO LLC - All Rights Reserved |
|
4
|
|
|
* Unauthorized copying of this file, via any medium is strictly prohibited |
|
5
|
|
|
* Proprietary and confidential |
|
6
|
|
|
* Written by Nikolay Beketov, 4 2020 |
|
7
|
|
|
* |
|
8
|
|
|
*/ |
|
9
|
|
|
|
|
10
|
|
|
declare(strict_types=1); |
|
11
|
|
|
/** |
|
12
|
|
|
* Copyright (C) MIKO LLC - All Rights Reserved |
|
13
|
|
|
* Unauthorized copying of this file, via any medium is strictly prohibited |
|
14
|
|
|
* Proprietary and confidential |
|
15
|
|
|
* Written by Nikolay Beketov, 4 2020 |
|
16
|
|
|
* |
|
17
|
|
|
*/ |
|
18
|
|
|
|
|
19
|
|
|
namespace MikoPBX\Common\Providers; |
|
20
|
|
|
|
|
21
|
|
|
use MikoPBX\Common\Models\PbxExtensionModules; |
|
22
|
|
|
use MikoPBX\Modules\Config\ConfigClass; |
|
23
|
|
|
use Phalcon\Di; |
|
24
|
|
|
use Phalcon\Di\DiInterface; |
|
25
|
|
|
use Phalcon\Di\ServiceProviderInterface; |
|
26
|
|
|
|
|
27
|
|
|
use function MikoPBX\Common\Config\appPath; |
|
28
|
|
|
|
|
29
|
|
|
/** |
|
30
|
|
|
* Main database connection is created based in the parameters defined in the configuration file |
|
31
|
|
|
*/ |
|
32
|
|
|
class PBXConfModulesProvider implements ServiceProviderInterface |
|
33
|
|
|
{ |
|
34
|
|
|
/** |
|
35
|
|
|
* Register db service provider |
|
36
|
|
|
* |
|
37
|
|
|
* @param \Phalcon\Di\DiInterface $di |
|
38
|
|
|
*/ |
|
39
|
|
|
public function register(DiInterface $di): void |
|
40
|
|
|
{ |
|
41
|
|
|
$di->setShared( |
|
42
|
|
|
'pbxConfModules', |
|
43
|
|
|
function (){ |
|
44
|
|
|
return array_merge( |
|
45
|
|
|
self::getCoreConfModules(), |
|
46
|
|
|
self::getExtensionsConfModules() |
|
47
|
|
|
); |
|
48
|
|
|
} |
|
49
|
|
|
); |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
|
|
/** |
|
53
|
|
|
* Create array of AsteriskConfModules |
|
54
|
|
|
* @return array |
|
55
|
|
|
*/ |
|
56
|
|
|
public static function getCoreConfModules():array |
|
57
|
|
|
{ |
|
58
|
|
|
$arrObjects = []; |
|
59
|
|
|
$configsDir = appPath('src/Core/Asterisk/Configs'); |
|
60
|
|
|
$modulesFiles = glob("{$configsDir}/*.php", GLOB_NOSORT); |
|
61
|
|
|
foreach ($modulesFiles as $file) { |
|
62
|
|
|
$className = pathinfo($file)['filename']; |
|
63
|
|
|
$full_class_name = "\\MikoPBX\\Core\\Asterisk\\Configs\\{$className}"; |
|
64
|
|
|
if (class_exists($full_class_name)) { |
|
65
|
|
|
$object = new $full_class_name(); |
|
66
|
|
|
if ($object instanceof ConfigClass){ |
|
67
|
|
|
$arrObjects[] = $object; |
|
68
|
|
|
} |
|
69
|
|
|
} |
|
70
|
|
|
} |
|
71
|
|
|
return $arrObjects; |
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
|
|
/** |
|
75
|
|
|
* Create array of AsteriskConfModules |
|
76
|
|
|
* @return array |
|
77
|
|
|
*/ |
|
78
|
|
|
public static function getExtensionsConfModules():array |
|
79
|
|
|
{ |
|
80
|
|
|
$arrObjects = []; |
|
81
|
|
|
$modules = PbxExtensionModules::find('disabled=0')->toArray(); |
|
82
|
|
|
foreach ($modules as $value) { |
|
83
|
|
|
$class_name = str_replace('Module', '', $value['uniqid']); |
|
84
|
|
|
$full_class_name = "\\Modules\\{$value['uniqid']}\\Lib\\{$class_name}Conf"; |
|
85
|
|
|
if (class_exists($full_class_name)) { |
|
86
|
|
|
$object = new $full_class_name(); |
|
87
|
|
|
if ($object instanceof ConfigClass){ |
|
88
|
|
|
$arrObjects[] = $object; |
|
89
|
|
|
} |
|
90
|
|
|
} |
|
91
|
|
|
} |
|
92
|
|
|
return $arrObjects; |
|
93
|
|
|
} |
|
94
|
|
|
|
|
95
|
|
|
/** |
|
96
|
|
|
* Recreates modules service after enable or disable them |
|
97
|
|
|
*/ |
|
98
|
|
|
public static function recreateModulesProvider(): void |
|
99
|
|
|
{ |
|
100
|
|
|
$di = Di::getDefault(); |
|
101
|
|
|
$di->remove('pbxConfModules'); |
|
102
|
|
|
$di->register(new self()); |
|
103
|
|
|
} |
|
104
|
|
|
|
|
105
|
|
|
} |