Passed
Pull Request — master (#2972)
by Rafael
33:58
created

getAvailablePluginNamespaces()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
eloc 3
dl 0
loc 6
ccs 0
cts 4
cp 0
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
crap 2
1
<?php
2
namespace ApacheSolrForTypo3\Solr\System\Configuration;
3
4
/*
5
 * This file is part of the TYPO3 CMS project.
6
 *
7
 * It is free software; you can redistribute it and/or modify it under
8
 * the terms of the GNU General Public License, either version 2
9
 * of the License, or any later version.
10
 *
11
 * For the full copyright and license information, please read the
12
 * LICENSE.txt file that was distributed with this source code.
13
 *
14
 * The TYPO3 project - inspiring people to share!
15
 */
16
17
use TYPO3\CMS\Core\Utility\GeneralUtility;
18
19
/**
20
 * This class encapsulates the access to the extension configuration.
21
 *
22
 * @author Timo Hund <[email protected]>
23
 */
24
class ExtensionConfiguration
25
{
26
    /**
27
     * Extension Configuration
28
     *
29
     * @var array
30
     */
31
    protected $configuration = [];
32
33
    /**
34
     * ExtensionConfiguration constructor.
35
     * @param array $configurationToUse
36
     */
37 245
    public function __construct($configurationToUse = [])
38
    {
39 245
        if (empty($configurationToUse)) {
40 245
            $this->configuration = GeneralUtility::makeInstance(\TYPO3\CMS\Core\Configuration\ExtensionConfiguration::class)->get('solr');
41
        } else {
42 6
            $this->configuration = $configurationToUse;
43
        }
44 245
    }
45
46
    /**
47
     * Get configuration for useConfigurationFromClosestTemplate
48
     *
49
     * @return bool
50
     */
51 140
    public function getIsUseConfigurationFromClosestTemplateEnabled()
52
    {
53 140
        return (bool)$this->getConfigurationOrDefaultValue('useConfigurationFromClosestTemplate', false);
54
    }
55
56
    /**
57
     * Get configuration for useConfigurationTrackRecordsOutsideSiteroot
58
     *
59
     * @return bool
60
     */
61 65
    public function getIsUseConfigurationTrackRecordsOutsideSiteroot()
62
    {
63 65
        return (bool)$this->getConfigurationOrDefaultValue('useConfigurationTrackRecordsOutsideSiteroot', true);
64
    }
65
66
    /**
67
     * Get configuration for allowSelfSignedCertificates
68
     *
69
     * @return bool
70
     */
71 1
    public function getIsSelfSignedCertificatesEnabled()
72
    {
73 1
        return (bool)$this->getConfigurationOrDefaultValue('allowSelfSignedCertificates', false);
74
    }
75
76
    /**
77
     * Get configuration for useConfigurationMonitorTables
78
     *
79
     * @return array of tableName
80
     */
81 44
    public function getIsUseConfigurationMonitorTables()
82
    {
83 44
        $monitorTables = [];
84 44
        $monitorTablesList = $this->getConfigurationOrDefaultValue('useConfigurationMonitorTables', '');
85
86 44
        if (empty($monitorTablesList)) {
87 42
            return $monitorTables;
88
        }
89
90 4
        return GeneralUtility::trimExplode(',', $monitorTablesList);
91
    }
92
93
    /**
94
     * Get configuration for allowLegacySiteMode
95
     *
96
     * @return bool
97
     */
98
    public function getIsAllowLegacySiteModeEnabled(): bool
99
    {
100
        trigger_error('solr:deprecation: Method getIsAllowLegacySiteModeEnabled is deprecated since EXT:solr 11 and will be removed in 12. Since EXT:solr 10 legacy site handling is deprecated and was removed in EXT:solr 11.', E_USER_DEPRECATED);
101
102
        //@todo throw exception if set to true and log deprecation
103
        $legacyModeIsActive = $this->getConfigurationOrDefaultValue('allowLegacySiteMode', false);
104
        if($legacyModeIsActive === true) {
105
            throw new \InvalidArgumentException("Legacy mode is not supported anymore, please migrate your system to use sitehandling now!");
106
        }
107
108
        return false;
109
    }
110
111
    /**
112
     * Returns a list of available/whitelisted EXT:solr plugin namespaces.
113
     * Builds from "pluginNamespaces" extension configuration setting.
114
     *
115
     * @return array
116
     */
117
    public function getAvailablePluginNamespaces(): array
118
    {
119
        $pluginNamespacesList = 'tx_solr,' . $this->getConfigurationOrDefaultValue(
120
                'pluginNamespaces'
121
            );
122
        return array_unique(GeneralUtility::trimExplode(',', $pluginNamespacesList));
123
    }
124
125
    /**
126
     * Returns a list of cacheHash-excludedParameters matching the EXT:solr plugin namespaces.
127
     * Builds from "pluginNamespaces" extension configuration setting.
128
     *
129
     * @return array
130
     */
131 224
    public function getCacheHashExcludedParameters(): array
132
    {
133 224
        $pluginNamespacesList = 'tx_solr,' . $this->getConfigurationOrDefaultValue(
134 224
            'pluginNamespaces'
135
        );
136 224
        $pluginNamespaces = array_map(
137
            function ($pluginNamespace) {
138 224
                return '^' . $pluginNamespace . '[';
139 224
            },
140 224
            array_unique(GeneralUtility::trimExplode(',', $pluginNamespacesList))
141
        );
142 224
        return array_combine($pluginNamespaces, $pluginNamespaces);
143
    }
144
145
    /**
146
     * @param string $key
147
     * @param mixed $defaultValue
148
     * @return mixed|null
149
     */
150 235
    protected function getConfigurationOrDefaultValue(string $key, $defaultValue = null)
151
    {
152 235
        return $this->configuration[$key] ?? $defaultValue;
153
    }
154
155
156
}
157