Skip to content

Commit 8eac295

Browse files
committed
Fix config, configuration, and documentation
1 parent 6b32949 commit 8eac295

File tree

5 files changed

+69
-52
lines changed

5 files changed

+69
-52
lines changed

DependencyInjection/BazingaGeocoderExtension.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,15 @@ public function load(array $configs, ContainerBuilder $container)
3636
$loader = new XmlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
3737
$loader->load('services.xml');
3838

39-
if (isset($config['fake_ip']) && !empty($config['fake_ip'])) {
39+
if (!empty($config['fake_ip']) && true === $config['fake_ip']['enabled']) {
4040
$definition = $container->getDefinition('bazinga_geocoder.event_listener.fake_request');
4141
$definition->replaceArgument(0, $config['fake_ip']['ip']);
4242

4343
$tag = current($definition->getTag('kernel.event_listener'));
4444
$tag['priority'] = $config['fake_ip']['priority'];
4545
$definition->setTags(array($tag));
46+
} else {
47+
$container->removeDefinition('bazinga_geocoder.event_listener.fake_request');
4648
}
4749

4850
if (isset($config['adapter']['class']) && !empty($config['adapter']['class'])) {

DependencyInjection/Configuration.php

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ class Configuration implements ConfigurationInterface
2121
/**
2222
* Generates the configuration tree builder.
2323
*
24-
* @return \Symfony\Component\Config\Definition\Builder\TreeBuilder The tree builder
24+
* @return TreeBuilder The tree builder
2525
*/
2626
public function getConfigTreeBuilder()
2727
{
@@ -35,7 +35,13 @@ public function getConfigTreeBuilder()
3535
->ifString()
3636
->then(function($value) { return array('ip' => $value); })
3737
->end()
38+
->treatFalseLike(array('enabled' => false))
39+
->treatTrueLike(array('enabled' => true))
40+
->treatNullLike(array('enabled' => true))
3841
->children()
42+
->booleanNode('enabled')
43+
->defaultTrue()
44+
->end()
3945
->scalarNode('ip')->defaultNull()->end()
4046
->scalarNode('priority')->defaultValue(0)->end()
4147
->end()
@@ -114,7 +120,6 @@ public function getConfigTreeBuilder()
114120
->arrayNode('host_ip')->end()
115121
->arrayNode('geoip')->end()
116122
->arrayNode('free_geo_ip')->end()
117-
118123
->arrayNode('mapquest')->end()
119124
->arrayNode('oiorest')->end()
120125
->arrayNode('geocoder_ca')->end()
@@ -166,7 +171,7 @@ public function getConfigTreeBuilder()
166171
->end()
167172

168173
->end()
169-
;
174+
;
170175

171176
return $treeBuilder;
172177
}

Resources/config/services.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
</parameters>
4646

4747
<services>
48+
<service id="geocoder" alias="bazinga_geocoder.geocoder" />
4849
<service id="bazinga_geocoder.geocoder" class="%bazinga_geocoder.geocoder.class%" />
4950

5051
<!-- Adapters -->

Resources/doc/index.md

Lines changed: 54 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,8 @@ Usage
4242
-----
4343

4444
This bundle registers a `bazinga_geocoder.geocoder` service which is an instance
45-
of `Geocoder`. You'll be able to do whatever you want with it.
45+
of `Geocoder`. You'll be able to do whatever you want with it but be sure to
46+
configure at least **one provider** first.
4647

4748
**NOTE:** When using `Request::getClientIp()` with Symfony 2.1+, ensure you have
4849
a trusted proxy set in your `config.yml`:
@@ -67,14 +68,15 @@ information in your development environment, for instance:
6768
/**
6869
* @Template()
6970
*/
70-
public function indexAction()
71+
public function indexAction(Request $request)
7172
{
7273
// Retrieve information from the current user (by its IP address)
73-
$result = $this->geocoder
74+
$result = $this->container
75+
->get('bazinga_geocoder.geocoder')
7476
->using('yahoo')
75-
->geocode($this->getRequest()->server->get('REMOTE_ADDR'));
77+
->geocode($request->server->get('REMOTE_ADDR'));
7678

77-
// Find the 5 nearest objects from the current user.
79+
// Find the 5 nearest objects (15km) from the current user.
7880
$objects = ObjectQuery::create()
7981
->filterByDistanceFrom($result->getLatitude(), $result->getLongitude(), 15)
8082
->limit(5)
@@ -129,12 +131,14 @@ Here is an example:
129131
```php
130132
<?php
131133
132-
public function geocodeAction()
134+
public function geocodeAction(Request $request)
133135
{
134-
$result = $this->container->get('bazinga_geocoder.geocoder')
135-
->geocode($this->container->get('request')->server->get('REMOTE_ADDR'));
136+
$result = $this->container
137+
->get('bazinga_geocoder.geocoder')
138+
->geocode($request->server->get('REMOTE_ADDR'));
136139
137-
$body = $this->container->get('bazinga_geocoder.dumper_manager')
140+
$body = $this->container
141+
->get('bazinga_geocoder.dumper_manager')
138142
->get('geojson')
139143
->dump($result);
140144
@@ -196,60 +200,66 @@ Toolbar](https://raw.github.com/willdurand/BazingaGeocoderBundle/master/Resource
196200
Reference Configuration
197201
-----------------------
198202

199-
You have to define the providers you want to use in your configuration.
200-
Some of them need information (API key for instance).
203+
You MUST define the providers you want to use in your configuration. Some of
204+
them need information (API key for instance).
201205

202206
You'll find the reference configuration below:
203207

204208
``` yaml
205209
# app/config/config*.yml
206210
207211
bazinga_geocoder:
208-
fake_ip: 999.999.999.999
212+
fake_ip:
213+
enabled: true
214+
ip: ~
215+
priority: 0
209216
adapter:
210-
class: \Your\CustomAdapter
217+
class: ~
211218
providers:
212219
bing_maps:
213-
api_key: XXXXXXXXX
214-
locale: xx_XX
215-
google_maps:
216-
locale: xx_XX
217-
region: xx_XX
220+
api_key: ~ # Required
221+
locale: ~
222+
cache:
223+
adapter: ~ # Required
224+
provider: ~ # Required
225+
locale: ~
226+
lifetime: 86400
218227
ip_info_db:
219-
api_key: XXXXXXXXX
228+
api_key: ~ # Required
220229
yahoo:
221-
api_key: XXXXXXXXX
222-
locale: xx_XX
230+
api_key: ~ # Required
231+
locale: ~
223232
cloudmade:
224-
api_key: XXXXXXXXX
225-
free_geo_ip: ~
233+
api_key: ~ # Required
234+
google_maps:
235+
locale: ~
236+
region: ~
237+
use_ssl: false
226238
openstreetmaps:
227-
locale: xx_XX
228-
host_ip: ~
229-
geoip: ~
230-
mapquest: ~
231-
oiorest: ~
232-
geocoder_ca: ~
233-
geocoder_us: ~
239+
locale: ~
240+
host_ip: []
241+
geoip: []
242+
free_geo_ip: []
243+
mapquest: []
244+
oiorest: []
245+
geocoder_ca: []
246+
geocoder_us: []
234247
ign_openls:
235-
api_key: XXXXXXXXX
236-
data_science_toolkit: ~
248+
api_key: ~ # Required
249+
data_science_toolkit: []
237250
yandex:
238-
locale: xx-XX
239-
toponym: XXXXXXXXX
251+
locale: ~
252+
toponym: ~
240253
geo_ips:
241-
api_key: XXXXXXXXX
242-
geo_plugin: ~
254+
api_key: ~
255+
geo_plugin: []
243256
maxmind:
244-
api_key: XXXXXXXXX
245-
# Caching Layer
246-
cache:
247-
provider: openstreetmaps
248-
adapter: some_service_id
249-
lifetime: 86400
250-
locale: %locale%
257+
api_key: ~ # Required
258+
maxmind_binary:
259+
binary_file: ~ # Required
260+
open_flag: ~
251261
chain:
252-
providers: [free_geo_ip, host_ip]
262+
providers: []
253263
```
254264

255265

Resources/views/Collector/geocoder.html.twig

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
{% endblock %}
3131

3232
{% block panel %}
33-
<h2>Gocoder requests</h2>
33+
<h2>Geocoder Requests</h2>
3434

3535
{% if not collector.requestsCount %}
3636
<p><em>No requests.</em></p>
@@ -67,13 +67,12 @@
6767
function geo_explain(link) {
6868
"use strict";
6969
70-
var imgs = link.children,
71-
target = link.getAttribute('data-target-id');
70+
var imgs = link.children,
71+
target = link.getAttribute('data-target-id');
7272
7373
Sfjs.toggle(target, imgs[0], imgs[1]);
7474
7575
return false;
7676
}
7777
//]]></script>
78-
7978
{% endblock %}

0 commit comments

Comments
 (0)