[task] handle missing array path exceptions

This commit is contained in:
Daniel Maier 2018-10-17 17:17:06 +02:00
parent 01e2179b14
commit 5ea0f34632
3 changed files with 21 additions and 8 deletions

View file

@ -20,6 +20,7 @@ namespace Codappix\SearchCore\Configuration;
* 02110-1301, USA. * 02110-1301, USA.
*/ */
use TYPO3\CMS\Core\Utility\Exception\MissingArrayPathException;
use TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface; use TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface;
use TYPO3\CMS\Core\Utility\ArrayUtility; use TYPO3\CMS\Core\Utility\ArrayUtility;
@ -60,16 +61,17 @@ class ConfigurationContainer implements ConfigurationContainerInterface
*/ */
public function get(string $path) public function get(string $path)
{ {
$value = ArrayUtility::getValueByPath($this->settings, $path); try
{
if ($value === null) { return ArrayUtility::getValueByPath($this->settings, $path);
}
catch (MissingArrayPathException $exception)
{
throw new InvalidArgumentException( throw new InvalidArgumentException(
'The given configuration option "' . $path . '" does not exist.', 'The given configuration option "' . $path . '" does not exist.',
InvalidArgumentException::OPTION_DOES_NOT_EXIST InvalidArgumentException::OPTION_DOES_NOT_EXIST
); );
} }
return $value;
} }
/** /**
@ -78,6 +80,13 @@ class ConfigurationContainer implements ConfigurationContainerInterface
*/ */
public function getIfExists(string $path) public function getIfExists(string $path)
{ {
return ArrayUtility::getValueByPath($this->settings, $path); try
{
return ArrayUtility::getValueByPath($this->settings, $path);
}
catch (\Exception $exception)
{
return null;
}
} }
} }

View file

@ -22,6 +22,7 @@ namespace Codappix\SearchCore\Connection\Elasticsearch;
use Codappix\SearchCore\Configuration\ConfigurationContainerInterface; use Codappix\SearchCore\Configuration\ConfigurationContainerInterface;
use TYPO3\CMS\Core\SingletonInterface as Singleton; use TYPO3\CMS\Core\SingletonInterface as Singleton;
use TYPO3\CMS\Extbase\Utility\DebuggerUtility;
/** /**
* The current connection to elasticsearch. * The current connection to elasticsearch.
@ -54,8 +55,8 @@ class Connection implements Singleton
if ($elasticaClient === null) { if ($elasticaClient === null) {
$elasticaClient = new \Elastica\Client([ $elasticaClient = new \Elastica\Client([
'host' => $this->configuration->get('connections.elasticsearch.host'), 'host' => $this->configuration->getIfExists('connections.elasticsearch.host'),
'port' => $this->configuration->get('connections.elasticsearch.port'), 'port' => $this->configuration->getIfExists('connections.elasticsearch.port'),
// TODO: Make configurable // TODO: Make configurable
// 'log' => 'file', // 'log' => 'file',
]); ]);

View file

@ -25,6 +25,7 @@ use Codappix\SearchCore\Configuration\InvalidArgumentException;
use Codappix\SearchCore\Domain\Index\IndexerInterface; use Codappix\SearchCore\Domain\Index\IndexerInterface;
use Codappix\SearchCore\Domain\Index\TcaIndexer\TcaTableServiceInterface; use Codappix\SearchCore\Domain\Index\TcaIndexer\TcaTableServiceInterface;
use TYPO3\CMS\Core\SingletonInterface as Singleton; use TYPO3\CMS\Core\SingletonInterface as Singleton;
use TYPO3\CMS\Core\Utility\Exception\MissingArrayPathException;
use TYPO3\CMS\Extbase\Object\ObjectManagerInterface; use TYPO3\CMS\Extbase\Object\ObjectManagerInterface;
/** /**
@ -65,6 +66,8 @@ class IndexerFactory implements Singleton
// Nothing to do, we throw exception below // Nothing to do, we throw exception below
} catch (InvalidArgumentException $e) { } catch (InvalidArgumentException $e) {
// Nothing to do, we throw exception below // Nothing to do, we throw exception below
} catch (MissingArrayPathException $e) {
// Nothing to do, we throw exception below
} }
throw new NoMatchingIndexerException('Could not find an indexer for ' . $identifier, 1497341442); throw new NoMatchingIndexerException('Could not find an indexer for ' . $identifier, 1497341442);