Skip to content

Commit f7f2d18

Browse files
committed
Merge remote-tracking branch 'upstream/master'
2 parents eda7759 + 2850133 commit f7f2d18

File tree

3 files changed

+47
-43
lines changed

3 files changed

+47
-43
lines changed

DependencyInjection/BazingaGeocoderExtension.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
use Bazinga\GeocoderBundle\ProviderFactory\PluginProviderFactory;
2020
use Bazinga\GeocoderBundle\ProviderFactory\ProviderFactoryInterface;
2121
use Faker\Generator;
22+
use Geocoder\Dumper\Dumper;
2223
use Geocoder\Plugin\Plugin\CachePlugin;
2324
use Geocoder\Plugin\Plugin\LimitPlugin;
2425
use Geocoder\Plugin\Plugin\LocalePlugin;
@@ -65,6 +66,9 @@ public function load(array $configs, ContainerBuilder $container)
6566
}
6667

6768
$this->loadProviders($container, $config);
69+
70+
$container->registerForAutoconfiguration(Dumper::class)
71+
->addTag('bazinga_geocoder.dumper');
6872
}
6973

7074
private function loadProviders(ContainerBuilder $container, array $config)

Resources/config/services.yml

Lines changed: 11 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,15 @@
11
services:
2-
Geocoder\Dumper\GeoArray:
3-
public: true
4-
tags: ['bazinga_geocoder.dumper']
5-
6-
Geocoder\Dumper\GeoJson:
7-
public: true
8-
tags: ['bazinga_geocoder.dumper']
9-
10-
Geocoder\Dumper\Gpx:
11-
public: true
12-
tags: ['bazinga_geocoder.dumper']
13-
14-
Geocoder\Dumper\Kml:
15-
public: true
16-
tags: ['bazinga_geocoder.dumper']
17-
18-
Geocoder\Dumper\Wkb:
19-
public: true
20-
tags: ['bazinga_geocoder.dumper']
21-
22-
Geocoder\Dumper\Wkt:
23-
public: true
24-
tags: ['bazinga_geocoder.dumper']
2+
_instanceof:
3+
Geocoder\Dumper\Dumper:
4+
tags: ['bazinga_geocoder.dumper']
5+
public: true
6+
7+
Geocoder\Dumper\GeoArray: ~
8+
Geocoder\Dumper\GeoJson: ~
9+
Geocoder\Dumper\Gpx: ~
10+
Geocoder\Dumper\Kml: ~
11+
Geocoder\Dumper\Wkb: ~
12+
Geocoder\Dumper\Wkt: ~
2513

2614
Bazinga\GeocoderBundle\ProviderFactory\:
2715
resource: '../../ProviderFactory'

Resources/doc/index.md

Lines changed: 32 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -237,41 +237,53 @@ Read more about cache [here](cache.md).
237237
If you need to dump your geocoded data to a specific format, you can use the
238238
__Dumper__ component. The following dumper's are supported:
239239

240-
* Geojson
240+
* GeoArray
241+
* GeoJson
241242
* GPX
242-
* KMP
243+
* KML
243244
* WKB
244245
* WKT
245246

246-
Here is an example:
247+
Here is an example if you are using autowiring:
247248

248249
```php
249250
<?php
250251
251-
public function geocodeAction(Request $request)
252+
namespace App\Controller;
253+
254+
use Geocoder\Dumper\GeoJson;
255+
use Geocoder\Provider\Provider;
256+
use Geocoder\Query\GeocodeQuery;
257+
use Symfony\Component\HttpFoundation\JsonResponse;
258+
use Symfony\Component\HttpFoundation\Request;
259+
260+
class AcmeController
252261
{
253-
$result = $this->container
254-
->get('bazinga_geocoder.provider.acme')
255-
->geocodeQuery(GeocodeQuery::create($request->server->get('REMOTE_ADDR')));
262+
private $acmeGeocoder;
263+
private $geoJsonDumper;
256264
257-
$body = $this->container
258-
->get('Geocoder\Dumper\GeoJson')
259-
->dump($result);
265+
public function __construct(Provider $acmeGeocoder, GeoJson $dumper)
266+
{
267+
$this->acmeGeocoder = $acmeGeocoder;
268+
$this->geoJsonDumper = $dumper;
269+
}
270+
271+
public function geocodeAction(Request $request)
272+
{
273+
$result = $this->acmeGeocoder->geocodeQuery(GeocodeQuery::create($request->server->get('REMOTE_ADDR')));
260274
261-
$response = new Response();
262-
$response->setContent($body);
275+
$body = $this->geoJsonDumper->dump($result);
263276
264-
return $response;
277+
return new JsonResponse($body);
278+
}
265279
}
266280
```
267281

268-
To register a new dumper, you must tag it with `bazinga_geocoder.dumper`.
269-
270-
```xml
271-
<service id="some.dumper" class="%some.dumper.class">
272-
<tag name="bazinga_geocoder.dumper" alias="custom" />
273-
</service>
274-
```
282+
Each dumper service if it implements `Geocoder\Dumper\Dumper` interface will be
283+
tagged with `bazinga_geocoder.dumper` tag. Each dumper can be used with autowiring
284+
providing the dumper class name as the argument.
285+
Also If you want to inject all the tagged dumpers to your service you can provide
286+
your service argument as: `!tagged bazinga_geocoder.dumper`.
275287

276288
### Custom HTTP Client
277289

0 commit comments

Comments
 (0)