Return empty array when configuration cannot be loaded

This commit is contained in:
Thibaud Fabre
2016-10-06 11:36:49 +02:00
parent d915c0d6e3
commit c48b490e18

View File

@@ -3,6 +3,7 @@
namespace Alchemy\Phrasea\Core\Provider; namespace Alchemy\Phrasea\Core\Provider;
use Alchemy\Phrasea\Core\Configuration\PropertyAccess; use Alchemy\Phrasea\Core\Configuration\PropertyAccess;
use Alchemy\Phrasea\Exception\RuntimeException;
use Silex\Application; use Silex\Application;
use Silex\ServiceProviderInterface; use Silex\ServiceProviderInterface;
@@ -37,25 +38,30 @@ class WorkerConfigurationServiceProvider implements ServiceProviderInterface
] ]
]; ];
/** @var PropertyAccess $configuration */ try {
$configuration = $app['conf']; /** @var PropertyAccess $configuration */
$configuration = $app['conf'];
$queueConfigurations = $configuration->get(['workers', 'queue'], $defaultConfiguration); $queueConfigurations = $configuration->get(['workers', 'queue'], $defaultConfiguration);
$queueConfiguration = reset($queueConfigurations); $queueConfiguration = reset($queueConfigurations);
$queueKey = key($queueConfigurations); $queueKey = key($queueConfigurations);
if (! isset($queueConfiguration['name'])) { if (! isset($queueConfiguration['name'])) {
if (! is_string($queueKey)) { if (! is_string($queueKey)) {
throw new \RuntimeException('Invalid queue configuration: configuration has no key or name.'); 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) public function boot(Application $app)
{ {
// TODO: Implement boot() method. // No-op
} }
} }