Completed
Pull Request — master (#1113)
by
unknown
18:44
created

getConfigurationOrDefaultValue()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 0
loc 4
ccs 0
cts 0
cp 0
rs 10
c 1
b 0
f 0
cc 2
eloc 2
nc 2
nop 2
crap 6
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
/**
28
 * This class encapsulates the access to the extension configuration.
29
 *
30
 * @package ApacheSolrForTypo3\Solr\System\Configuration
31
 * @author Timo Hund <[email protected]>
32
 */
33
class ExtensionConfiguration
34
{
35
    /**
36
     * Extension Configuration
37
     *
38
     * @var array
39
     */
40
    protected $configuration = [];
41
42
    /**
43
     * ExtensionConfiguration constructor.
44
     * @param array $configurationToUse
45
     */
46 63
    public function __construct($configurationToUse = [])
47
    {
48 63
        if (empty($configurationToUse)) {
49 63
            $this->configuration =  unserialize($GLOBALS['TYPO3_CONF_VARS']['EXT']['extConf']['solr']);
50
        } else {
51 1
            $this->configuration = $configurationToUse;
52
        }
53 63
    }
54
55
    /**
56
     * Get configuration for useConfigurationFromClosestTemplate
57
     *
58 63
     * @return bool
59
     */
60 63
    public function getIsUseConfigurationFromClosestTemplateEnabled()
61
    {
62
        return (bool)$this->getConfigurationOrDefaultValue('useConfigurationFromClosestTemplate', false);
63
    }
64
65
    /**
66
     * Get configuration for useConfigurationTrackRecordsOutsideSiteroot
67
     *
68 63
     * @return bool
69
     */
70 63
    public function getIsUseConfigurationTrackRecordsOutsideSiteroot()
71
    {
72
        return (bool)$this->getConfigurationOrDefaultValue('useConfigurationTrackRecordsOutsideSiteroot', true);
73
    }
74
75
    /**
76
     * @param string $key
77
     * @param mixed $defaultValue
78
     * @return mixed
79
     */
80
    protected function getConfigurationOrDefaultValue($key, $defaultValue)
81
    {
82
        return isset($this->configuration[$key]) ? $this->configuration[$key] : $defaultValue;
83
    }
84
}
85