Passed
Push — develop ( ec71a0...627254 )
by Nikolay
12:54 queued 13s
created

ConfigClass::onNatsReload()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 2
Code Lines 0

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 0
dl 0
loc 2
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
/**
3
 * Copyright © MIKO LLC - All Rights Reserved
4
 * Unauthorized copying of this file, via any medium is strictly prohibited
5
 * Proprietary and confidential
6
 * Written by Alexey Portnov, 6 2020
7
 */
8
9
namespace MikoPBX\Modules\Config;
10
11
use MikoPBX\Core\System\MikoPBXConfig;
12
use Phalcon\Di;
13
use ReflectionClass as ReflectionClassAlias;
14
15
abstract class ConfigClass implements SystemConfigInterface, AsteriskConfigInterface, RestAPIConfigInterface
16
{
17
    /**
18
     * Dependency injections
19
     */
20
    protected $di;
21
22
    /**
23
     * @var \MikoPBX\Core\System\MikoPBXConfig
24
     */
25
    protected MikoPBXConfig $mikoPBXConfig;
26
27
    /**
28
     * @var \Phalcon\Config
29
     */
30
    protected \Phalcon\Config $config;
31
32
    /**
33
     * @var bool
34
     */
35
    protected bool $booting;
36
37
    /**
38
     * Error and Notice messages
39
     * @var array
40
     */
41
    protected array $messages;
42
43
    /**
44
     * Array of PbxSettings values
45
     */
46
    protected array $generalSettings;
47
48
    /**
49
     * Asterisk config file name
50
     */
51
    protected string $description;
52
53
    /**
54
     * Additional module UniqueID
55
     */
56
    protected string $moduleUniqueId;
57
58
    /**
59
     * Additional module directory
60
     */
61
    protected string $moduleDir;
62
63
64
    /**
65
     * ConfigClass constructor.
66
     *
67
     */
68
    public function __construct()
69
    {
70
        $this->di            = Di::getDefault();
71
        $this->config        = $this->di->getShared('config');
0 ignored issues
show
Bug introduced by
The method getShared() does not exist on null. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

71
        /** @scrutinizer ignore-call */ 
72
        $this->config        = $this->di->getShared('config');

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
72
        $this->booting       = $this->di->getRegistry()->booting;
73
        $this->mikoPBXConfig = new MikoPBXConfig();
74
        $this->generalSettings = $this->mikoPBXConfig->getGeneralSettings();
75
76
        // Get child class parameters and define module Dir and UniqueID
77
        $reflector = new ReflectionClassAlias(static::class);
78
        $partsOfNameSpace = explode('\\', $reflector->getNamespaceName());
79
        if (count($partsOfNameSpace)===3 && $partsOfNameSpace[0]==='Modules'){
80
            $modulesDir    = $this->config->path('core.modulesDir');
81
            $this->moduleUniqueId = $partsOfNameSpace[1];
82
            $this->moduleDir =  $modulesDir.'/'.$this->moduleUniqueId;
83
        }
84
85
        $this->messages = [];
86
    }
87
88
    public function getSettings(): void
89
    {
90
91
    }
92
93
    public function generateConfig(): void
94
    {
95
        // Генерация конфигурационных файлов.
96
        $this->echoGenerateConfig();
97
        $this->getSettings();
98
        $this->generateConfigProtected();
99
        $this->echoDone();
100
    }
101
102
103
    /**
104
     * Makes pretty module text block into config file
105
     * @param string $addition
106
     *
107
     * @return string
108
     */
109
    protected function confBlockWithComments(string $addition):string
110
    {
111
        $result = '';
112
        if (empty($addition)){
113
            return $result;
114
        }
115
        if (!empty($this->moduleUniqueId)){
116
            $result ='; ***** BEGIN BY '.$this->moduleUniqueId.PHP_EOL." *****\t";
117
            $result .= $addition;
118
            if (substr($addition, -1)!=="\t"){
119
                $result .="\t";
120
            }
121
            $result .='; ***** END BY '.$this->moduleUniqueId.PHP_EOL." *****\t";
122
        } else {
123
            $result .= $addition;
124
        }
125
        return $result;
126
    }
127
128
    /**
129
     * Вывод сообщения о генерации конфига.
130
     *
131
     */
132
    protected function echoGenerateConfig(): void
133
    {
134
        if ($this->booting === true && !empty($this->description)) {
135
            echo "   |- generate config {$this->description}... ";
136
        }
137
    }
138
139
    /**
140
     * Генерация конфигурационного файла asterisk.
141
     */
142
    protected function generateConfigProtected():void
143
    {
144
    }
145
146
    /**
147
     * Вывод сообщения об окончании генерации.
148
     */
149
    protected function echoDone(): void
150
    {
151
        if ($this->booting === true && !empty($this->description)) {
152
            echo "\033[32;1mdone\033[0m \n";
153
        }
154
    }
155
156
    // Получаем строки include для секции internal.
157
158
    public function getIncludeInternal(): string
159
    {
160
        // Генерация внутреннего номерного плана.
161
        return '';
162
    }
163
164
    // Получаем строки include для секции internal-transfer.
165
    public function getIncludeInternalTransfer() :string
166
    {
167
        // Генерация внутреннего номерного плана.
168
        return '';
169
    }
170
171
    // Генератор extension для контекста internal.
172
    public function extensionGenInternal(): string
173
    {
174
        // Генерация внутреннего номерного плана.
175
        return '';
176
    }
177
178
    // Генератор extension для контекста internal.
179
    public function extensionGenInternalTransfer(): string
180
    {
181
        // Генерация внутреннего номерного плана.
182
        return '';
183
    }
184
185
186
    // Генератор extension для контекста peers.
187
    public function extensionGenPeerContexts()
188
    {
189
        // Генерация внутреннего номерного плана.
190
        return '';
191
    }
192
193
    // Генератор extensions, дополнительные контексты.
194
    public function extensionGenContexts(): string
195
    {
196
        return '';
197
    }
198
199
    // Генератор хинтов для контекста internal-hints
200
    public function extensionGenHints(): string
201
    {
202
        // Генерация хинтов.
203
        return '';
204
    }
205
206
    // Секция global для extensions.conf.
207
    public function extensionGlobals(): string
208
    {
209
        // Генерация хинтов.
210
        return '';
211
    }
212
213
    // Секция featuremap для features.conf
214
    public function getFeatureMap(): string
215
    {
216
        // Возвращает старкоды.
217
        return '';
218
    }
219
220
    /**
221
     * Генерация контекста для публичных звонков.
222
     *
223
     * @param $conf
224
     *
225
     * @return void
226
     */
227
    public function generatePublicContext(&$conf) :void
228
    {
229
    }
230
231
232
    /**
233
     * Будет вызван после старта asterisk.
234
     */
235
    public function onAfterPbxStarted(): void
236
    {
237
    }
238
239
    /**
240
     * Добавление задач в crond.
241
     *
242
     * @param $tasks
243
     */
244
    public function createCronTasks(&$tasks): void
245
    {
246
    }
247
248
249
    /**
250
     * Генератор сеции пиров для sip.conf
251
     *
252
     * @return string
253
     */
254
    public function generatePeersPj(): string
255
    {
256
        return '';
257
    }
258
259
    /**
260
     * Генератор сеции пиров для manager.conf
261
     *
262
     */
263
    public function generateManagerConf(): string
264
    {
265
        return '';
266
    }
267
268
    /**
269
     * Дополнительные параметры для
270
     *
271
     * @param $peer
272
     *
273
     * @return string
274
     */
275
    public function generatePeerPjAdditionalOptions($peer): string
276
    {
277
        return '';
278
    }
279
280
    /**
281
     * Кастомизация исходящего контекста для конкретного маршрута.
282
     *
283
     * @param $rout
284
     *
285
     * @return string
286
     */
287
    public function generateOutRoutContext($rout): string
288
    {
289
        return '';
290
    }
291
292
    /**
293
     * Кастомизация исходящего контекста для конкретного маршрута.
294
     *
295
     * @param $rout
296
     *
297
     * @return string
298
     */
299
    public function generateOutRoutAfterDialContext($rout): string
300
    {
301
        return '';
302
    }
303
304
    /**
305
     * Кастомизация входящего контекста для конкретного маршрута.
306
     *
307
     * @param $id
308
     *
309
     * @return string
310
     */
311
    public function generateIncomingRoutAfterDialContext($id): string
312
    {
313
        return '';
314
    }
315
316
    /**
317
     * Кастомизация входящего контекста для конкретного маршрута.
318
     *
319
     * @param $rout_number
320
     *
321
     * @return string
322
     */
323
    public function generateIncomingRoutBeforeDial($rout_number): string
324
    {
325
        return '';
326
    }
327
328
    /**
329
     * Обработчик события изменения данных в базе настроек mikopbx.db.
330
     *
331
     * @param $data
332
     */
333
    public function modelsEventChangeData($data): void
334
    {
335
    }
336
337
    /**
338
     * Обработчик события изменения данных в базе настроек mikopbx.db.
339
     *
340
     * @param $modified_tables
341
     */
342
    public function modelsEventNeedReload($modified_tables): void
343
    {
344
    }
345
346
    /**
347
     * Returns array of workers classes for WorkerSafeScripts from module
348
     * @return array
349
     */
350
    public function getModuleWorkers(): array
351
    {
352
        return [];
353
    }
354
355
    /**
356
     * Returns array of additional firewall rules for module
357
     * @return array
358
     */
359
    public function getDefaultFirewallRules(): array
360
    {
361
        return [];
362
    }
363
364
    /**
365
     * Return messages after function or method execution
366
     * @return array
367
     */
368
    public function getMessages(): array
369
    {
370
        return  $this->messages;
371
    }
372
373
    /**
374
     * Process enable action in web interface
375
     * @return bool
376
     */
377
    public function onBeforeModuleEnable(): bool
378
    {
379
        return true;
380
    }
381
382
    /**
383
     * Process disable action in web interface
384
     * @return bool
385
     */
386
    public function onBeforeModuleDisable(): bool
387
    {
388
        return true;
389
    }
390
391
    /**
392
     * Генератор modules.conf
393
     *
394
     * @return string
395
     */
396
    public function generateModulesConf():string
397
    {
398
        return '';
399
    }
400
401
    /**
402
     *  Process CoreAPI requests under root rights
403
     *
404
     * @param array $request
405
     *
406
     * @return array
407
     */
408
    public function moduleRestAPICallback(array $request): array
409
    {
410
        $action = strtoupper($request['action']);
411
        switch ($action){
412
            case 'CHECK':
413
            case 'RELOAD':
414
                $result['result']   = 'Success';
0 ignored issues
show
Comprehensibility Best Practice introduced by
$result was never initialized. Although not strictly required by PHP, it is generally a good practice to add $result = array(); before regardless.
Loading history...
415
                break;
416
            default:
417
                $result['result']   = 'ERROR';
418
                $result['data'] = 'API action not found;';
419
        }
420
        return $result;
421
    }
422
423
    /**
424
     * Returns array of additional routes for PBXCoreREST interface from module
425
     *
426
     * @return array
427
     */
428
    public function getPBXCoreRESTAdditionalRoutes(): array
429
    {
430
        return [];
431
    }
432
}