|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Codappix\SearchCore\Configuration; |
|
4
|
|
|
|
|
5
|
|
|
/* |
|
6
|
|
|
* Copyright (C) 2016 Daniel Siepmann <[email protected]> |
|
7
|
|
|
* |
|
8
|
|
|
* This program is free software; you can redistribute it and/or |
|
9
|
|
|
* modify it under the terms of the GNU General Public License |
|
10
|
|
|
* as published by the Free Software Foundation; either version 2 |
|
11
|
|
|
* of the License, or (at your option) any later version. |
|
12
|
|
|
* |
|
13
|
|
|
* This program is distributed in the hope that it will be useful, |
|
14
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
15
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
16
|
|
|
* GNU General Public License for more details. |
|
17
|
|
|
* |
|
18
|
|
|
* You should have received a copy of the GNU General Public License |
|
19
|
|
|
* along with this program; if not, write to the Free Software |
|
20
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA |
|
21
|
|
|
* 02110-1301, USA. |
|
22
|
|
|
*/ |
|
23
|
|
|
|
|
24
|
|
|
use TYPO3\CMS\Core\Utility\ArrayUtility; |
|
25
|
|
|
use TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface; |
|
26
|
|
|
|
|
27
|
|
|
/** |
|
28
|
|
|
* Container of all configurations for extension. |
|
29
|
|
|
* Always inject this to have a single place for configuration. |
|
30
|
|
|
*/ |
|
31
|
|
|
class ConfigurationContainer implements ConfigurationContainerInterface |
|
32
|
|
|
{ |
|
33
|
|
|
/** |
|
34
|
|
|
* Plain TypoScript array from extbase for extension / plugin. |
|
35
|
|
|
* |
|
36
|
|
|
* @var array |
|
37
|
|
|
*/ |
|
38
|
|
|
protected $settings = []; |
|
39
|
|
|
|
|
40
|
|
|
/** |
|
41
|
|
|
* Inject settings via ConfigurationManager. |
|
42
|
|
|
* |
|
43
|
|
|
* @throws NoConfigurationException |
|
44
|
62 |
|
*/ |
|
45
|
|
|
public function injectConfigurationManager(ConfigurationManagerInterface $configurationManager) |
|
46
|
62 |
|
{ |
|
47
|
62 |
|
$this->settings = $configurationManager->getConfiguration( |
|
48
|
62 |
|
ConfigurationManagerInterface::CONFIGURATION_TYPE_SETTINGS, |
|
49
|
|
|
'SearchCore' |
|
50
|
62 |
|
); |
|
51
|
|
|
if ($this->settings === null) { |
|
52
|
|
|
throw new NoConfigurationException('Could not fetch configuration.', 1484226842); |
|
53
|
62 |
|
} |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
|
/** |
|
57
|
|
|
* @param string $path In dot notation. |
|
58
|
|
|
* @return mixed |
|
59
|
|
|
* @throws InvalidArgumentException |
|
60
|
54 |
|
*/ |
|
61
|
|
|
public function get(string $path) |
|
62
|
54 |
|
{ |
|
63
|
|
|
$value = $this->getValueByPath($path); |
|
64
|
54 |
|
|
|
65
|
32 |
|
if ($value === null) { |
|
66
|
32 |
|
throw new InvalidArgumentException( |
|
67
|
32 |
|
'The given configuration option "' . $path . '" does not exist.', |
|
68
|
|
|
InvalidArgumentException::OPTION_DOES_NOT_EXIST |
|
69
|
|
|
); |
|
70
|
|
|
} |
|
71
|
50 |
|
|
|
72
|
|
|
return $value; |
|
73
|
|
|
} |
|
74
|
|
|
|
|
75
|
|
|
/** |
|
76
|
|
|
* @param string $path In dot notation. |
|
77
|
|
|
* @return mixed |
|
78
|
26 |
|
*/ |
|
79
|
|
|
public function getIfExists(string $path) |
|
80
|
26 |
|
{ |
|
81
|
|
|
return $this->getValueByPath($path); |
|
82
|
|
|
} |
|
83
|
|
|
|
|
84
|
|
|
/** |
|
85
|
|
|
* @param string $path In dot notation. |
|
86
|
|
|
* @return mixed|null Null if no entry was found. |
|
87
|
|
|
*/ |
|
88
|
|
|
protected function getValueByPath(string $path) |
|
89
|
|
|
{ |
|
90
|
|
|
try { |
|
91
|
|
|
return ArrayUtility::getValueByPath($this->settings, $path, '.'); |
|
92
|
|
|
} catch (\Exception $e) { |
|
93
|
|
|
// Catch all exceptions to safely handle path retrieval |
|
94
|
|
|
} |
|
95
|
|
|
return null; |
|
96
|
|
|
} |
|
97
|
|
|
} |
|
98
|
|
|
|