Passed
Push — develop ( 368e3d...115c7b )
by Nikolay
12:16
created

SysLogsManagementProcessor::scanDirRecursively()   A

Complexity

Conditions 6
Paths 5

Size

Total Lines 20
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 9
dl 0
loc 20
rs 9.2222
c 0
b 0
f 0
cc 6
nc 5
nop 1
1
<?php
2
/*
3
 * MikoPBX - free phone system for small business
4
 * Copyright © 2017-2023 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
namespace MikoPBX\PBXCoreREST\Lib;
21
22
use MikoPBX\PBXCoreREST\Lib\SysLogs\DownloadLogFileAction;
23
use MikoPBX\PBXCoreREST\Lib\SysLogs\DownloadLogsArchiveAction;
24
use MikoPBX\PBXCoreREST\Lib\SysLogs\EraseFileAction;
25
use MikoPBX\PBXCoreREST\Lib\SysLogs\GetLogFromFileAction;
26
use MikoPBX\PBXCoreREST\Lib\SysLogs\GetLogsListAction;
27
use MikoPBX\PBXCoreREST\Lib\SysLogs\PrepareLogAction;
28
use MikoPBX\PBXCoreREST\Lib\SysLogs\StartLogAction;
29
use Phalcon\Di\Injectable;
30
31
/**
32
 * Class SysLogsManagementProcessor
33
 *
34
 * @package MikoPBX\PBXCoreREST\Lib
35
 *
36
 */
37
class SysLogsManagementProcessor extends Injectable
38
{
39
    /**
40
     * Processes syslog requests
41
     *
42
     * @param array $request
43
     *
44
     * @return PBXApiResult An object containing the result of the API call.
45
     *
46
     */
47
    public static function callBack(array $request): PBXApiResult
48
    {
49
        $action         = $request['action'];
50
        $data           = $request['data'];
51
        $res            = new PBXApiResult();
52
        $res->processor = __METHOD__;
53
        switch ($action) {
54
            case 'getLogFromFile':
55
                $res = GetLogFromFileAction::main($data);
56
                break;
57
            case 'prepareLog':
58
                $res = PrepareLogAction::main(false);
59
                $res->processor = $action;
60
                break;
61
            case 'startLog':
62
                $res = StartLogAction::main();
63
                break;
64
            case 'stopLog':
65
                $res = PrepareLogAction::main(true);
66
                $res->processor = $action;
67
                break;
68
            case 'downloadLogsArchive':
69
                $res = DownloadLogsArchiveAction::main($data['filename']);
70
                break;
71
            case 'downloadLogFile':
72
                $res = DownloadLogFileAction::main($data['filename']);
73
                break;
74
            case 'getLogsList':
75
                $res = GetLogsListAction::main();
76
                break;
77
            case 'eraseFile':
78
                $res = EraseFileAction::main($data['filename']);
79
                break;
80
            default:
81
                $res->messages['error'][] = "Unknown action - $action in ".__CLASS__;
82
        }
83
84
        $res->function = $action;
85
86
        return $res;
87
    }
88
89
}