Completed
Branch master (d17104)
by Christian
21:20
created

PhpInformation::getContent()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 6
nc 1
nop 1
dl 0
loc 10
rs 10
c 0
b 0
f 0
1
<?php
2
declare(strict_types = 1);
3
4
namespace TYPO3\CMS\Adminpanel\Modules\Info;
5
6
/*
7
 * This file is part of the TYPO3 CMS project.
8
 *
9
 * It is free software; you can redistribute it and/or modify it under
10
 * the terms of the GNU General Public License, either version 2
11
 * of the License, or any later version.
12
 *
13
 * For the full copyright and license information, please read the
14
 * LICENSE.txt file that was distributed with this source code.
15
 *
16
 * The TYPO3 project - inspiring people to share!
17
 */
18
19
use Psr\Http\Message\ServerRequestInterface;
20
use TYPO3\CMS\Adminpanel\ModuleApi\AbstractSubModule;
21
use TYPO3\CMS\Adminpanel\ModuleApi\ContentProviderInterface;
22
use TYPO3\CMS\Adminpanel\ModuleApi\DataProviderInterface;
23
use TYPO3\CMS\Adminpanel\ModuleApi\ModuleData;
24
use TYPO3\CMS\Core\Utility\GeneralUtility;
25
use TYPO3\CMS\Fluid\View\StandaloneView;
26
27
/**
28
 * PhpInformation admin panel sub module
29
 *
30
 * @internal
31
 */
32
class PhpInformation extends AbstractSubModule implements DataProviderInterface, ContentProviderInterface
33
{
34
    /**
35
     * @inheritdoc
36
     */
37
    public function getIdentifier(): string
38
    {
39
        return 'info_php';
40
    }
41
42
    /**
43
     * @inheritdoc
44
     */
45
    public function getLabel(): string
46
    {
47
        return $this->getLanguageService()->sL(
48
            'LLL:EXT:adminpanel/Resources/Private/Language/locallang_info.xlf:sub.php.label'
49
        );
50
    }
51
52
    /**
53
     * @inheritdoc
54
     */
55
    public function getDataToStore(ServerRequestInterface $request): ModuleData
56
    {
57
        return new ModuleData(
58
            [
59
                'general' => [
60
                    'PHP_VERSION' => PHP_VERSION,
61
                    'PHP_OS' => PHP_OS,
62
                    'PHP_SAPI' => PHP_SAPI,
63
                    'Peak Memory Usage' => memory_get_peak_usage(),
64
                ],
65
                'loadedExtensions' => implode(', ', get_loaded_extensions()),
66
                'constants' => get_defined_constants(true),
67
            ]
68
        );
69
    }
70
71
    /**
72
     * @inheritdoc
73
     */
74
    public function getContent(ModuleData $data): string
75
    {
76
        $view = GeneralUtility::makeInstance(StandaloneView::class);
77
        $templateNameAndPath = 'EXT:adminpanel/Resources/Private/Templates/Modules/Info/PhpInfo.html';
78
        $view->setTemplatePathAndFilename(GeneralUtility::getFileAbsFileName($templateNameAndPath));
79
        $view->setPartialRootPaths(['EXT:adminpanel/Resources/Private/Partials']);
80
81
        $view->assignMultiple($data->getArrayCopy());
82
83
        return $view->render();
84
    }
85
}
86