SystemInfoController::getApiInfo()   A
last analyzed

Complexity

Conditions 2
Paths 5

Size

Total Lines 20
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 13
nc 5
nop 0
dl 0
loc 20
rs 9.8333
c 0
b 0
f 0
1
<?php
2
/**
3
 * BEdita, API-first content management framework
4
 * Copyright 2023 Atlas Srl, Chialab Srl
5
 *
6
 * This file is part of BEdita: you can redistribute it and/or modify
7
 * it under the terms of the GNU Lesser General Public License as published
8
 * by the Free Software Foundation, either version 3 of the License, or
9
 * (at your option) any later version.
10
 *
11
 * See LICENSE.LGPL or <http://gnu.org/licenses/lgpl-3.0.html> for more details.
12
 */
13
namespace App\Controller\Admin;
14
15
use App\Utility\SchemaTrait;
16
use BEdita\SDK\BEditaClientException;
17
use Cake\Core\Configure;
18
use Cake\Http\Response;
19
use Cake\Utility\Hash;
20
use Twig\Environment;
21
22
/**
23
 * System info Controller
24
 */
25
class SystemInfoController extends AdministrationBaseController
26
{
27
    use SchemaTrait;
28
29
    /**
30
     * @inheritDoc
31
     */
32
    public function index(): ?Response
33
    {
34
        $this->set('system_info', $this->getSystemInfo());
35
        $this->set('api_info', $this->getApiInfo());
36
37
        return null;
38
    }
39
40
    /**
41
     * Get system info.
42
     *
43
     * @return array
44
     */
45
    public function getSystemInfo(): array
46
    {
47
        return [
48
            'Version' => Configure::read('Manager.version'),
49
            'CakePHP' => Configure::version(),
50
            'PHP' => phpversion(),
51
            'Twig' => Environment::VERSION,
52
            'Vuejs' => '',
53
            'Operating System' => php_uname(),
54
            'PHP Server API' => php_sapi_name(),
55
            'Extensions' => get_loaded_extensions(),
56
            'Extensions info' => get_loaded_extensions(true),
57
            'Memory limit' => ini_get('memory_limit'),
58
            'Post max size' => sprintf('%dM', intVal(substr(ini_get('post_max_size'), 0, -1))),
59
            'Upload max size' => sprintf('%dM', intVal(substr(ini_get('upload_max_filesize'), 0, -1))),
60
        ];
61
    }
62
63
    /**
64
     * Get api info from API server.
65
     *
66
     * @return array
67
     */
68
    public function getApiInfo(): array
69
    {
70
        $info = [
71
            'Url' => Configure::read('API.apiBaseUrl'),
72
            'Version' => Hash::get((array)$this->viewBuilder()->getVar('project'), 'version'),
73
        ];
74
        try {
75
            $info = (array)Hash::get(
76
                $this->apiClient->get('/admin/sysinfo'),
77
                'meta.info'
78
            );
79
            /** @var \Authentication\Identity $user */
80
            $user = $this->Authentication->getIdentity();
81
            $meta = $this->getMeta($user);
82
            $info = array_merge($info, ['GET /home' => $meta]);
83
        } catch (BEditaClientException $e) {
84
            $this->log($e->getMessage(), 'error');
85
        }
86
87
        return $info;
88
    }
89
}
90