77 *
88 * @license MIT License
99 */
10-
1110namespace Bazinga \Bundle \GeocoderBundle \DependencyInjection ;
1211
1312use Symfony \Component \HttpKernel \DependencyInjection \Extension ;
1918use Symfony \Component \Config \Definition \Processor ;
2019
2120/**
22- * William Durand <william.durand1@gmail.com>
21+ * William Durand <william.durand1@gmail.com>.
2322 */
2423class BazingaGeocoderExtension extends Extension
2524{
@@ -29,9 +28,9 @@ public function load(array $configs, ContainerBuilder $container)
2928 {
3029 $ this ->container = $ container ;
3130
32- $ processor = new Processor ();
33- $ configuration = new Configuration ();
34- $ config = $ processor ->processConfiguration ($ configuration , $ configs );
31+ $ processor = new Processor ();
32+ $ configuration = new Configuration ();
33+ $ config = $ processor ->processConfiguration ($ configuration , $ configs );
3534
3635 $ loader = new XmlFileLoader ($ container , new FileLocator (__DIR__ .'/../Resources/config ' ));
3736 $ loader ->load ('services.xml ' );
@@ -52,9 +51,7 @@ public function load(array $configs, ContainerBuilder $container)
5251 $ container ->removeDefinition ('bazinga_geocoder.event_listener.fake_request ' );
5352 }
5453
55- if (isset ($ config ['adapter ' ]['class ' ]) && !empty ($ config ['adapter ' ]['class ' ])) {
56- $ container ->setParameter ('bazinga_geocoder.geocoder.adapter.class ' , $ config ['adapter ' ]['class ' ]);
57- }
54+ $ container ->setAlias ('bazinga_geocoder.geocoder.adapter ' , $ config ['adapter ' ]);
5855
5956 if (isset ($ config ['providers ' ]['free_geo_ip ' ])) {
6057 $ this ->addProvider ('free_geo_ip ' );
@@ -77,7 +74,7 @@ public function load(array $configs, ContainerBuilder $container)
7774 $ ipInfoDbParams = $ config ['providers ' ]['ip_info_db ' ];
7875
7976 $ this ->addProvider ('ip_info_db ' , array (
80- $ ipInfoDbParams ['api_key ' ]
77+ $ ipInfoDbParams ['api_key ' ],
8178 ));
8279 }
8380
@@ -108,7 +105,7 @@ public function load(array $configs, ContainerBuilder $container)
108105 $ openstreetMapsParams = $ config ['providers ' ]['openstreetmap ' ];
109106
110107 $ this ->addProvider ('openstreetmap ' , array (
111- $ openstreetMapsParams ['locale ' ]
108+ $ openstreetMapsParams ['locale ' ],
112109 ));
113110 }
114111
@@ -120,48 +117,24 @@ public function load(array $configs, ContainerBuilder $container)
120117 $ mapQuestParams = $ config ['providers ' ]['mapquest ' ];
121118
122119 $ this ->addProvider ('mapquest ' , array (
123- $ mapQuestParams ['api_key ' ]
124- ));
125- }
126-
127- if (isset ($ config ['providers ' ]['oiorest ' ])) {
128- $ this ->addProvider ('oiorest ' );
129- }
130-
131- if (isset ($ config ['providers ' ]['geocoder_ca ' ])) {
132- $ this ->addProvider ('geocoder_ca ' );
133- }
134-
135- if (isset ($ config ['providers ' ]['geocoder_us ' ])) {
136- $ this ->addProvider ('geocoder_us ' );
137- }
138-
139- if (isset ($ config ['providers ' ]['ign_openls ' ])) {
140- $ ignOpenlsParams = $ config ['providers ' ]['ign_openls ' ];
141-
142- $ this ->addProvider ('ign_openls ' , array (
143- $ ignOpenlsParams ['api_key ' ]
120+ $ mapQuestParams ['api_key ' ],
144121 ));
145122 }
146123
147- if (isset ($ config ['providers ' ]['data_science_toolkit ' ])) {
148- $ this ->addProvider ('data_science_toolkit ' );
149- }
150-
151124 if (isset ($ config ['providers ' ]['yandex ' ])) {
152125 $ yandexParams = $ config ['providers ' ]['yandex ' ];
153126
154127 $ this ->addProvider ('yandex ' , array (
155128 $ yandexParams ['locale ' ],
156- $ yandexParams ['toponym ' ]
129+ $ yandexParams ['toponym ' ],
157130 ));
158131 }
159132
160133 if (isset ($ config ['providers ' ]['geo_ips ' ])) {
161134 $ geoIpsParams = $ config ['providers ' ]['geo_ips ' ];
162135
163136 $ this ->addProvider ('geo_ips ' , array (
164- $ geoIpsParams ['api_key ' ]
137+ $ geoIpsParams ['api_key ' ],
165138 ));
166139 }
167140
@@ -173,7 +146,7 @@ public function load(array $configs, ContainerBuilder $container)
173146 $ maxmindParams = $ config ['providers ' ]['maxmind ' ];
174147
175148 $ this ->addProvider ('maxmind ' , array (
176- $ maxmindParams ['api_key ' ]
149+ $ maxmindParams ['api_key ' ],
177150 ));
178151 }
179152
@@ -195,9 +168,19 @@ public function load(array $configs, ContainerBuilder $container)
195168 $ container ->setDefinition ('bazinga_geocoder.provider.maxmind_binary ' , $ provider );
196169 }
197170
171+ if (isset ($ config ['providers ' ]['opencage ' ])) {
172+ $ openCageParams = $ config ['providers ' ]['opencage ' ];
173+
174+ $ this ->addProvider ('opencage ' , array (
175+ $ openCageParams ['api_key ' ],
176+ $ openCageParams ['use_ssl ' ],
177+ $ openCageParams ['locale ' ],
178+ ));
179+ }
180+
198181 if (isset ($ config ['providers ' ]['cache ' ])) {
199- $ params = $ config ['providers ' ]['cache ' ];
200- $ cache = new Reference ($ params ['adapter ' ]);
182+ $ params = $ config ['providers ' ]['cache ' ];
183+ $ cache = new Reference ($ params ['adapter ' ]);
201184 $ fallback = new Reference ('bazinga_geocoder.provider. ' .$ params ['provider ' ]);
202185
203186 $ provider = new Definition (
@@ -230,11 +213,11 @@ public function load(array $configs, ContainerBuilder $container)
230213 if (isset ($ config ['providers ' ]['chain ' ]['providers ' ])) {
231214 foreach ($ config ['providers ' ]['chain ' ]['providers ' ] as $ name ) {
232215 if ($ this ->container ->hasDefinition ('bazinga_geocoder.provider. ' .$ name )) {
233- $ chainProvider ->addMethodCall ('addProvider ' , array (
234- $ this ->container ->getDefinition ('bazinga_geocoder.provider. ' .$ name )
216+ $ chainProvider ->addMethodCall ('add ' , array (
217+ $ this ->container ->getDefinition ('bazinga_geocoder.provider. ' .$ name ),
235218 ));
236219 } else {
237- $ chainProvider ->addMethodCall ('addProvider ' , array (new Reference ($ name )));
220+ $ chainProvider ->addMethodCall ('add ' , array (new Reference ($ name )));
238221 }
239222 }
240223 }
0 commit comments