From c48b490e18c5b7cd94c81ed4b3a700fe90b78267 Mon Sep 17 00:00:00 2001 From: Thibaud Fabre Date: Thu, 6 Oct 2016 11:36:49 +0200 Subject: [PATCH] Return empty array when configuration cannot be loaded --- .../WorkerConfigurationServiceProvider.php | 34 +++++++++++-------- 1 file changed, 20 insertions(+), 14 deletions(-) diff --git a/lib/Alchemy/Phrasea/Core/Provider/WorkerConfigurationServiceProvider.php b/lib/Alchemy/Phrasea/Core/Provider/WorkerConfigurationServiceProvider.php index 639d4e0fbb..cc0ac0a2a3 100644 --- a/lib/Alchemy/Phrasea/Core/Provider/WorkerConfigurationServiceProvider.php +++ b/lib/Alchemy/Phrasea/Core/Provider/WorkerConfigurationServiceProvider.php @@ -3,6 +3,7 @@ namespace Alchemy\Phrasea\Core\Provider; use Alchemy\Phrasea\Core\Configuration\PropertyAccess; +use Alchemy\Phrasea\Exception\RuntimeException; use Silex\Application; use Silex\ServiceProviderInterface; @@ -37,25 +38,30 @@ class WorkerConfigurationServiceProvider implements ServiceProviderInterface ] ]; - /** @var PropertyAccess $configuration */ - $configuration = $app['conf']; + try { + /** @var PropertyAccess $configuration */ + $configuration = $app['conf']; - $queueConfigurations = $configuration->get(['workers', 'queue'], $defaultConfiguration); + $queueConfigurations = $configuration->get(['workers', 'queue'], $defaultConfiguration); - $queueConfiguration = reset($queueConfigurations); - $queueKey = key($queueConfigurations); + $queueConfiguration = reset($queueConfigurations); + $queueKey = key($queueConfigurations); - if (! isset($queueConfiguration['name'])) { - if (! is_string($queueKey)) { - throw new \RuntimeException('Invalid queue configuration: configuration has no key or name.'); + if (! isset($queueConfiguration['name'])) { + if (! is_string($queueKey)) { + throw new \RuntimeException('Invalid queue configuration: configuration has no key or name.'); + } + + $queueConfiguration['name'] = $queueKey; } - $queueConfiguration['name'] = $queueKey; + $config = [ $queueConfiguration['name'] => $queueConfiguration ]; + + return $config; + } + catch (RuntimeException $exception) { + return []; } - - $config = [ $queueConfiguration['name'] => $queueConfiguration ]; - - return $config; }); } @@ -68,6 +74,6 @@ class WorkerConfigurationServiceProvider implements ServiceProviderInterface */ public function boot(Application $app) { - // TODO: Implement boot() method. + // No-op } }