Skip to content

Commit 3c485ee

Browse files
committed
Add ChainProvider
1 parent c733f55 commit 3c485ee

File tree

5 files changed

+51
-18
lines changed

5 files changed

+51
-18
lines changed

DependencyInjection/BazingaGeocoderExtension.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,27 @@ public function load(array $configs, ContainerBuilder $container)
171171

172172
$container->setDefinition('bazinga_geocoder.provider.cache', $provider);
173173
}
174+
175+
if (isset($config['providers']['chain'])) {
176+
177+
$chainProvider = new Definition(
178+
'%bazinga_geocoder.geocoder.provider.chain.class%'
179+
);
180+
181+
$this->container->setDefinition('bazinga_geocoder.provider.chain', $chainProvider);
182+
183+
$chainProvider
184+
->setPublic(false)
185+
->addTag('bazinga_geocoder.provider');
186+
187+
if (isset($config['providers']['chain']['providers'])) {
188+
foreach ($config['providers']['chain']['providers'] as $name) {
189+
if ($this->container->hasDefinition('bazinga_geocoder.provider.'.$name)) {
190+
$chainProvider->addMethodCall('addProvider', array($this->container->getDefinition('bazinga_geocoder.provider.'.$name)));
191+
}
192+
}
193+
}
194+
}
174195
}
175196

176197
protected function addProvider($name, array $arguments = array())

DependencyInjection/Configuration.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,14 @@ public function getConfigTreeBuilder()
138138
->end()
139139
->end()
140140
->end()
141+
->arrayNode('chain')
142+
->fixXmlConfig('provider')
143+
->children()
144+
->arrayNode('providers')
145+
->prototype('scalar')->end()
146+
->end()
147+
->end()
148+
->end()
141149

142150
->end()
143151
;

Resources/config/services.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
<parameter key="bazinga_geocoder.geocoder.provider.geo_plugin.class">Geocoder\Provider\GeoPluginProvider</parameter>
2727
<parameter key="bazinga_geocoder.geocoder.provider.maxmind.class">Geocoder\Provider\MaxMindProvider</parameter>
2828
<parameter key="bazinga_geocoder.geocoder.provider.cache.class">Bazinga\Bundle\GeocoderBundle\Provider\CacheProvider</parameter>
29+
<parameter key="bazinga_geocoder.geocoder.provider.chain.class">Geocoder\Provider\ChainProvider</parameter>
2930

3031
<parameter key="bazinga_geocoder.event_listener.fake_request.class">Bazinga\Bundle\GeocoderBundle\EventListener\FakeRequestListener</parameter>
3132

Tests/DependencyInjection/BazingaGeocoderExtensionTest.php

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -41,25 +41,26 @@ public function testLoad()
4141
$geocoder = $container->get('bazinga_geocoder.geocoder');
4242
$providers = $geocoder->getProviders();
4343
foreach (array(
44-
'bing_maps' => 'Geocoder\\Provider\\BingMapsProvider',
45-
'cache' => 'Bazinga\\Bundle\\GeocoderBundle\\Provider\\CacheProvider',
46-
'ip_info_db' => 'Geocoder\\Provider\\IpInfoDbProvider',
47-
'yahoo' => 'Geocoder\\Provider\\YahooProvider',
48-
'cloudmade' => 'Geocoder\\Provider\\CloudMadeProvider',
49-
'google_maps' => 'Geocoder\\Provider\\GoogleMapsProvider',
50-
'openstreetmaps' => 'Geocoder\\Provider\\OpenStreetMapsProvider',
51-
'host_ip' => 'Geocoder\\Provider\\HostIpProvider',
52-
'free_geo_ip' => 'Geocoder\\Provider\\FreeGeoIpProvider',
53-
'map_quest' => 'Geocoder\\Provider\\MapQuestProvider',
54-
'oio_rest' => 'Geocoder\\Provider\\OIORestProvider',
55-
'geocoder_ca' => 'Geocoder\\Provider\\GeocoderCaProvider',
56-
'geocoder_us' => 'Geocoder\\Provider\\GeocoderUsProvider',
57-
'ign_openls' => 'Geocoder\\Provider\\IGNOpenLSProvider',
44+
'bing_maps' => 'Geocoder\\Provider\\BingMapsProvider',
45+
'cache' => 'Bazinga\\Bundle\\GeocoderBundle\\Provider\\CacheProvider',
46+
'ip_info_db' => 'Geocoder\\Provider\\IpInfoDbProvider',
47+
'yahoo' => 'Geocoder\\Provider\\YahooProvider',
48+
'cloudmade' => 'Geocoder\\Provider\\CloudMadeProvider',
49+
'google_maps' => 'Geocoder\\Provider\\GoogleMapsProvider',
50+
'openstreetmaps' => 'Geocoder\\Provider\\OpenStreetMapsProvider',
51+
'host_ip' => 'Geocoder\\Provider\\HostIpProvider',
52+
'free_geo_ip' => 'Geocoder\\Provider\\FreeGeoIpProvider',
53+
'map_quest' => 'Geocoder\\Provider\\MapQuestProvider',
54+
'oio_rest' => 'Geocoder\\Provider\\OIORestProvider',
55+
'geocoder_ca' => 'Geocoder\\Provider\\GeocoderCaProvider',
56+
'geocoder_us' => 'Geocoder\\Provider\\GeocoderUsProvider',
57+
'ign_openls' => 'Geocoder\\Provider\\IGNOpenLSProvider',
5858
'data_science_toolkit' => 'Geocoder\\Provider\\DataScienceToolkitProvider',
59-
'yandex' => 'Geocoder\\Provider\\YandexProvider',
60-
'geo_ips' => 'Geocoder\\Provider\\GeoIpsProvider',
61-
'geo_plugin' => 'Geocoder\\Provider\\GeoPluginProvider',
62-
'maxmind' => 'Geocoder\\Provider\\MaxmindProvider',
59+
'yandex' => 'Geocoder\\Provider\\YandexProvider',
60+
'geo_ips' => 'Geocoder\\Provider\\GeoIpsProvider',
61+
'geo_plugin' => 'Geocoder\\Provider\\GeoPluginProvider',
62+
'maxmind' => 'Geocoder\\Provider\\MaxmindProvider',
63+
'chain' => 'Geocoder\\Provider\\ChainProvider',
6364
) as $name => $class) {
6465
$this->assertInstanceOf($class, $providers[$name], sprintf('-> Assert that %s is instance of %s', $name, $class));
6566
}

Tests/DependencyInjection/Fixtures/config.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,3 +41,5 @@ bazinga_geocoder:
4141
geo_plugin: ~
4242
maxmind:
4343
api_key: 123
44+
chain:
45+
providers: [free_geo_ip, host_ip]

0 commit comments

Comments
 (0)