Completed
Push — master ( 9d02b0...47261c )
by Timo
11s
created

getTypoScriptConfigurationInstance()   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 2
crap 1
1
<?php
2
3
namespace ApacheSolrForTypo3\Solr\System\Configuration;
4
5
/***************************************************************
6
 *  Copyright notice
7
 *
8
 *  (c) 2010-2016 Timo Schmidt <[email protected]
9
 *  All rights reserved
10
 *
11
 *  This script is part of the TYPO3 project. The TYPO3 project is
12
 *  free software; you can redistribute it and/or modify
13
 *  it under the terms of the GNU General Public License as published by
14
 *  the Free Software Foundation; either version 2 of the License, or
15
 *  (at your option) any later version.
16
 *
17
 *  The GNU General Public License can be found at
18
 *  http://www.gnu.org/copyleft/gpl.html.
19
 *
20
 *  This script is distributed in the hope that it will be useful,
21
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
22
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
23
 *  GNU General Public License for more details.
24
 *
25
 *  This copyright notice MUST APPEAR in all copies of the script!
26
 ***************************************************************/
27
28
use ApacheSolrForTypo3\Solr\System\Configuration\TypoScriptConfiguration;
29
use TYPO3\CMS\Core\SingletonInterface;
30
use TYPO3\CMS\Core\Utility\GeneralUtility;
31
32
/**
33
 * Configuration manager old the configuration instance.
34
 * Singleton
35
 *
36
 * @author Timo Schmidt <[email protected]>
37
 */
38
class ConfigurationManager implements SingletonInterface
39
{
40
    /**
41
     * @var TypoScriptConfiguration
42
     */
43
    protected $typoScriptConfigurations = array();
44
45
    /**
46
     * Resets the state of the configuration manager.
47
     *
48
     * @return void
49
     */
50 11
    public function reset()
51
    {
52 11
        $this->typoScriptConfigurations = array();
0 ignored issues
show
Documentation Bug introduced by
It seems like array() of type array is incompatible with the declared type object<ApacheSolrForTypo...ypoScriptConfiguration> of property $typoScriptConfigurations.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
53 11
    }
54
55
    /**
56
     * Retrieves the TypoScriptConfiguration object from an configuration array, pageId, languageId and TypoScript
57
     * path that is used in in the current context.
58
     *
59
     * @param array $configurationArray
60
     * @param int $contextPageId
61
     * @param int $contextLanguageId
62
     * @param string $contextTypoScriptPath
63
     * @return TypoScriptConfiguration
64
     */
65 156
    public function getTypoScriptConfiguration(array $configurationArray = null, $contextPageId = null, $contextLanguageId = 0, $contextTypoScriptPath = '')
66
    {
67 156
        if ($configurationArray == null) {
68 134
            if (isset($this->typoScriptConfigurations['default'])) {
69 88
                $configurationArray = $this->typoScriptConfigurations['default'];
70
            } else {
71 90
                if (!empty($GLOBALS['TSFE']->tmpl->setup) && is_array($GLOBALS['TSFE']->tmpl->setup)) {
72 73
                    $configurationArray = $GLOBALS['TSFE']->tmpl->setup;
73 73
                    $this->typoScriptConfigurations['default'] = $configurationArray;
74
                }
75
            }
76
        }
77
78 156
        if (!is_array($configurationArray)) {
79 17
            $configurationArray = array();
80
        }
81
82 156
        if (!isset($configurationArray['plugin.']['tx_solr.'])) {
83 18
            $configurationArray['plugin.']['tx_solr.'] = array();
84
        }
85
86 156
        if ($contextPageId === null && !empty($GLOBALS['TSFE']->id)) {
87 48
            $contextPageId = $GLOBALS['TSFE']->id;
88
        }
89
90 156
        $hash = md5(serialize($configurationArray)) . '-' . $contextPageId . '-' . $contextLanguageId . '-' . $contextTypoScriptPath;
91 156
        if (isset($this->typoScriptConfigurations[$hash])) {
92 100
            return $this->typoScriptConfigurations[$hash];
93
        }
94
95 113
        $this->typoScriptConfigurations[$hash] = $this->getTypoScriptConfigurationInstance($configurationArray, $contextPageId);
96 113
        return $this->typoScriptConfigurations[$hash];
97
    }
98
99
    /**
100
     * This method is used to build the TypoScriptConfiguration.
101
     *
102
     * @param array $configurationArray
103
     * @param null $contextPageId
104
     * @return object
105
     */
106 113
    protected function getTypoScriptConfigurationInstance(array $configurationArray = null, $contextPageId = null)
107
    {
108 113
        return GeneralUtility::makeInstance(TypoScriptConfiguration::class, $configurationArray, $contextPageId);
109
    }
110
}
111