Completed
Push — master ( 045e4a...eefd63 )
by
unknown
38:09 queued 24:29
created

TcaDisplayConditions::isIPLockEnabled()   A

Complexity

Conditions 5
Paths 5

Size

Total Lines 10
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 5
eloc 6
c 1
b 0
f 0
nc 5
nop 1
dl 0
loc 10
rs 9.6111
1
<?php
2
declare(strict_types = 1);
3
4
namespace TYPO3\CMS\Core\Hooks;
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 TYPO3\CMS\Core\Utility\ExtensionManagementUtility;
20
21
/**
22
 * Various display conditions to check for e.g. installed extensions or configuration settings used.
23
 *
24
 * @internal This class is a hook implementation and is not part of the TYPO3 Core API.
25
 */
26
class TcaDisplayConditions
27
{
28
    /**
29
     * Check if an extension is loaded.
30
     *
31
     * @param array $parameters
32
     * @return bool
33
     */
34
    public function isExtensionInstalled(array $parameters): bool
35
    {
36
        $extension = $parameters['conditionParameters'][0] ?? '';
37
        if (!empty($extension)) {
38
            return ExtensionManagementUtility::isLoaded($extension);
39
        }
40
        return false;
41
    }
42
43
    /**
44
     * Check if $GLOBALS['TYPO3_CONF_VARS']['BE']['ipLock'] is active
45
     *
46
     * @param array $parameters
47
     * @return bool
48
     */
49
    public function isIPLockEnabled(array $parameters): bool
50
    {
51
        $type = $parameters['conditionParameters'][0] ?? 'backend';
52
        if ($type === 'backend') {
53
            return (int)$GLOBALS['TYPO3_CONF_VARS']['BE']['ipLock'] > 0 || (int)$GLOBALS['TYPO3_CONF_VARS']['BE']['lockIPv6'] > 0;
54
        }
55
        if ($type === 'frontend') {
56
            return (int)$GLOBALS['TYPO3_CONF_VARS']['FE']['ipLock'] > 0 || (int)$GLOBALS['TYPO3_CONF_VARS']['FE']['lockIPv6'] > 0;
57
        }
58
        return false;
59
    }
60
}
61