Passed
Push — master ( 12556a...721793 )
by Timo
17:02
created

getIsSelfSignedCertificatesEnabled()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
crap 1
1
<?php
2
namespace ApacheSolrForTypo3\Solr\System\Configuration;
3
4
/***************************************************************
5
 *  Copyright notice
6
 *
7
 *  (c) 2017- Timo Schmidt <[email protected]
8
 *  All rights reserved
9
 *
10
 *  This script is part of the TYPO3 project. The TYPO3 project is
11
 *  free software; you can redistribute it and/or modify
12
 *  it under the terms of the GNU General Public License as published by
13
 *  the Free Software Foundation; either version 2 of the License, or
14
 *  (at your option) any later version.
15
 *
16
 *  The GNU General Public License can be found at
17
 *  http://www.gnu.org/copyleft/gpl.html.
18
 *
19
 *  This script is distributed in the hope that it will be useful,
20
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
21
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
22
 *  GNU General Public License for more details.
23
 *
24
 *  This copyright notice MUST APPEAR in all copies of the script!
25
 ***************************************************************/
26
27
use TYPO3\CMS\Core\Utility\GeneralUtility;
28
29
/**
30
 * This class encapsulates the access to the extension configuration.
31
 *
32
 * @package ApacheSolrForTypo3\Solr\System\Configuration
33
 * @author Timo Hund <[email protected]>
34
 */
35
class ExtensionConfiguration
36
{
37
    /**
38
     * Extension Configuration
39
     *
40
     * @var array
41
     */
42
    protected $configuration = [];
43
44
    /**
45
     * ExtensionConfiguration constructor.
46
     * @param array $configurationToUse
47
     */
48 148
    public function __construct($configurationToUse = [])
49
    {
50 148
        if (empty($configurationToUse)) {
51 148
            $this->configuration =  unserialize($GLOBALS['TYPO3_CONF_VARS']['EXT']['extConf']['solr']);
52
        } else {
53 4
            $this->configuration = $configurationToUse;
54
        }
55 148
    }
56
57
    /**
58
     * Get configuration for useConfigurationFromClosestTemplate
59
     *
60
     * @return bool
61
     */
62 65
    public function getIsUseConfigurationFromClosestTemplateEnabled()
63
    {
64 65
        return (bool)$this->getConfigurationOrDefaultValue('useConfigurationFromClosestTemplate', false);
65
    }
66
67
    /**
68
     * Get configuration for useConfigurationTrackRecordsOutsideSiteroot
69
     *
70
     * @return bool
71
     */
72 51
    public function getIsUseConfigurationTrackRecordsOutsideSiteroot()
73
    {
74 51
        return (bool)$this->getConfigurationOrDefaultValue('useConfigurationTrackRecordsOutsideSiteroot', true);
75
    }
76
77
    /**
78
     * Get configuration for allowSelfSignedCertificates
79
     *
80
     * @return bool
81
     */
82 2
    public function getIsSelfSignedCertificatesEnabled()
83
    {
84 2
        return (bool)$this->getConfigurationOrDefaultValue('allowSelfSignedCertificates', false);
85
    }
86
87
    /**
88
     * Get configuration for useConfigurationMonitorTables
89
     *
90
     * @return array of tableName => true
91
     */
92 34
    public function getIsUseConfigurationMonitorTables()
93
    {
94 34
        $monitorTables = [];
95 34
        $monitorTablesList = $this->getConfigurationOrDefaultValue('useConfigurationMonitorTables', '');
96
97 34
        if (empty($monitorTablesList)) {
98 32
            return $monitorTables;
99
        }
100
101 3
        $monitorTablesTemp = GeneralUtility::trimExplode(',', $monitorTablesList);
102 3
        foreach ($monitorTablesTemp as $value) {
103 3
            $monitorTables[$value] = true;
104
        }
105
106 3
        return $monitorTables;
107
    }
108
109
    /**
110
     * @param string $key
111
     * @param mixed $defaultValue
112
     * @return mixed
113
     */
114 72
    protected function getConfigurationOrDefaultValue($key, $defaultValue)
115
    {
116 72
        return isset($this->configuration[$key]) ? $this->configuration[$key] : $defaultValue;
117
    }
118
}
119