|
13 | 13 | namespace Bazinga\GeocoderBundle\DependencyInjection;
|
14 | 14 |
|
15 | 15 | use Bazinga\GeocoderBundle\DataCollector\GeocoderDataCollector;
|
| 16 | +use Bazinga\GeocoderBundle\DependencyInjection\Compiler\FactoryValidatorPass; |
16 | 17 | use Bazinga\GeocoderBundle\Plugin\FakeIpPlugin;
|
17 | 18 | use Bazinga\GeocoderBundle\Plugin\ProfilingPlugin;
|
18 | 19 | use Bazinga\GeocoderBundle\ProviderFactory\PluginProviderFactory;
|
|
25 | 26 | use Symfony\Component\Config\Definition\Processor;
|
26 | 27 | use Symfony\Component\Config\FileLocator;
|
27 | 28 | use Symfony\Component\DependencyInjection\ContainerBuilder;
|
| 29 | +use Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException; |
28 | 30 | use Symfony\Component\DependencyInjection\Loader\YamlFileLoader;
|
29 | 31 | use Symfony\Component\DependencyInjection\Reference;
|
30 | 32 | use Symfony\Component\HttpKernel\DependencyInjection\Extension;
|
@@ -60,14 +62,20 @@ public function load(array $configs, ContainerBuilder $container)
|
60 | 62 | private function loadProviders(ContainerBuilder $container, array $config)
|
61 | 63 | {
|
62 | 64 | foreach ($config['providers'] as $providerName => $providerConfig) {
|
63 |
| - $factoryService = $container->getDefinition($providerConfig['factory']); |
64 |
| - $factoryClass = $factoryService->getClass() ?: $providerConfig['factory']; |
65 |
| - if (!$this->implementsPoviderFactory($factoryClass)) { |
66 |
| - throw new \LogicException(sprintf('Provider factory "%s" must implement ProviderFactoryInterface', $providerConfig['factory'])); |
| 65 | + try { |
| 66 | + $factoryService = $container->getDefinition($providerConfig['factory']); |
| 67 | + $factoryClass = $factoryService->getClass() ?: $providerConfig['factory']; |
| 68 | + if (!$this->implementsPoviderFactory($factoryClass)) { |
| 69 | + throw new \LogicException(sprintf('Provider factory "%s" must implement ProviderFactoryInterface', $providerConfig['factory'])); |
| 70 | + } |
| 71 | + // See if any option has a service reference |
| 72 | + $providerConfig['options'] = $this->findReferences($providerConfig['options']); |
| 73 | + $factoryClass::validate($providerConfig['options'], $providerName); |
| 74 | + } catch (ServiceNotFoundException $e) { |
| 75 | + // Assert: We are using a custom factory. If invalid config, it will be caught in FactoryValidatorPass |
| 76 | + $providerConfig['options'] = $this->findReferences($providerConfig['options']); |
| 77 | + FactoryValidatorPass::addFactoryServiceId($providerConfig['factory']); |
67 | 78 | }
|
68 |
| - // See if any option has a service reference |
69 |
| - $providerConfig['options'] = $this->findReferences($providerConfig['options']); |
70 |
| - $factoryClass::validate($providerConfig['options'], $providerName); |
71 | 79 |
|
72 | 80 | $serviceId = 'bazinga_geocoder.provider.'.$providerName;
|
73 | 81 | $plugins = $this->configureProviderPlugins($container, $providerConfig, $serviceId);
|
|
0 commit comments