2016-12-13 12:33:54 +01:00
|
|
|
<?php
|
2017-07-06 23:48:47 +02:00
|
|
|
namespace Codappix\SearchCore\Configuration;
|
2016-12-13 12:33:54 +01:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Copyright (C) 2016 Daniel Siepmann <coding@daniel-siepmann.de>
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
|
|
|
* 02110-1301, USA.
|
|
|
|
*/
|
|
|
|
|
|
|
|
use TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface;
|
2016-12-20 10:04:44 +01:00
|
|
|
use TYPO3\CMS\Extbase\Utility\ArrayUtility;
|
2016-12-13 12:33:54 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Container of all configurations for extension.
|
|
|
|
* Always inject this to have a single place for configuration and parsing only once.
|
|
|
|
*/
|
|
|
|
class ConfigurationContainer implements ConfigurationContainerInterface
|
|
|
|
{
|
|
|
|
/**
|
2016-12-20 10:04:44 +01:00
|
|
|
* Plain TypoScript array from extbase for extension / plugin.
|
2016-12-13 12:33:54 +01:00
|
|
|
*
|
|
|
|
* @var array
|
|
|
|
*/
|
2017-05-30 10:42:35 +02:00
|
|
|
protected $settings = [];
|
2016-12-13 12:33:54 +01:00
|
|
|
|
|
|
|
/**
|
2016-12-20 10:04:44 +01:00
|
|
|
* Inject settings via ConfigurationManager.
|
2016-12-13 12:33:54 +01:00
|
|
|
*
|
2017-01-12 14:21:41 +01:00
|
|
|
* @throws NoConfigurationException
|
2016-12-13 12:33:54 +01:00
|
|
|
*/
|
|
|
|
public function injectConfigurationManager(ConfigurationManagerInterface $configurationManager)
|
|
|
|
{
|
|
|
|
$this->settings = $configurationManager->getConfiguration(
|
|
|
|
ConfigurationManagerInterface::CONFIGURATION_TYPE_SETTINGS,
|
2018-11-06 17:34:56 +01:00
|
|
|
'SearchCore'
|
2016-12-13 12:33:54 +01:00
|
|
|
);
|
2017-01-12 14:07:23 +01:00
|
|
|
if ($this->settings === null) {
|
2017-01-12 14:21:41 +01:00
|
|
|
throw new NoConfigurationException('Could not fetch configuration.', 1484226842);
|
2017-01-12 14:07:23 +01:00
|
|
|
}
|
2016-12-13 12:33:54 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2016-12-20 10:04:44 +01:00
|
|
|
* @param string $path In dot notation.
|
2016-12-13 12:33:54 +01:00
|
|
|
* @return mixed
|
|
|
|
* @throws InvalidArgumentException
|
|
|
|
*/
|
2018-03-06 17:40:49 +01:00
|
|
|
public function get(string $path)
|
2016-12-13 12:33:54 +01:00
|
|
|
{
|
2016-12-20 10:04:44 +01:00
|
|
|
$value = ArrayUtility::getValueByPath($this->settings, $path);
|
|
|
|
|
|
|
|
if ($value === null) {
|
2016-12-13 12:33:54 +01:00
|
|
|
throw new InvalidArgumentException(
|
2016-12-20 10:04:44 +01:00
|
|
|
'The given configuration option "' . $path . '" does not exist.',
|
2016-12-13 12:33:54 +01:00
|
|
|
InvalidArgumentException::OPTION_DOES_NOT_EXIST
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2016-12-20 10:04:44 +01:00
|
|
|
return $value;
|
2016-12-13 12:33:54 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2016-12-20 10:04:44 +01:00
|
|
|
* @param string $path In dot notation.
|
|
|
|
* @return mixed
|
2016-12-13 12:33:54 +01:00
|
|
|
*/
|
2018-03-06 17:40:49 +01:00
|
|
|
public function getIfExists(string $path)
|
2016-12-13 12:33:54 +01:00
|
|
|
{
|
2016-12-20 10:04:44 +01:00
|
|
|
return ArrayUtility::getValueByPath($this->settings, $path);
|
2016-12-13 12:33:54 +01:00
|
|
|
}
|
|
|
|
}
|