Skip to content

Commit 721d0a5

Browse files
authored
Updating the documentation for 5.0 (#158)
* Putting the documentation to sections * Added docs about custom provider * Added info about plugins * Updated links * fixed typo
1 parent c5a4d37 commit 721d0a5

File tree

4 files changed

+173
-34
lines changed

4 files changed

+173
-34
lines changed

Resources/doc/cache.md

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
# Caching the geocoder response
2+
3+
*[<< Back to documentation index](Resources/doc/index.md)*
4+
5+
It is quite rare that a location response gets updated. That is why it is a good idea to cache the responses. The second
6+
request will be both quicker and free of charge. To get started with caching you may use the `CachePlugin` which is supported
7+
by default in our configuration.
8+
9+
```yaml
10+
# config.yml
11+
bazinga_geocoder:
12+
providers:
13+
acme:
14+
factory: Bazinga\GeocoderBundle\ProviderFactory\GoogleMapsFactory
15+
cache: 'any.psr16.service'
16+
cache_lifetime: 3600
17+
```
18+
19+
You may use any [PSR16](http://www.php-fig.org/psr/psr-16/) cache [implementation](https://packagist.org/providers/psr/simple-cache-implementation).
20+
The `CachePlugin` helps you to cache all responses.
21+
22+
## Decorator pattern
23+
24+
If you do not like using the `CachePlugin` for some reason you may use the [`CacheProvider`](https://github.com/geocoder-php/cache-provider).
25+
The `CacheProvider` is using the [Decorator pattern](https://en.wikipedia.org/wiki/Decorator_pattern) to do caching. Which
26+
means that you wrap the `CacheProvider` around your existing provider.
27+
28+
```bash
29+
composer require geocoder-php/cache-provider
30+
```
31+
32+
```yaml
33+
# config.yml
34+
bazinga_geocoder:
35+
providers:
36+
acme:
37+
factory: Bazinga\GeocoderBundle\ProviderFactory\GoogleMapsFactory
38+
```
39+
40+
```yaml
41+
# services.yml
42+
servies:
43+
my_cached_geocoder:
44+
class: Geocoder\Provider\Cache\ProviderCache
45+
arguments: ['@bazinga_geocoder.provider.acme', '@any.psr16.service', 3600]
46+
```
47+
48+
## Installing a PSR16 cache
49+
50+
You may use any adapter from [PHP-cache.com](http://www.php-cache.com/en/latest/) or `symfony/cache`.

Resources/doc/custom-provider.md

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
# Registering Your Own Providers
2+
3+
*[<< Back to documentation index](Resources/doc/index.md)*
4+
5+
If you want to use your own provider in your application, create a service, and tag it as `bazinga_geocoder.provider`:
6+
7+
```xml
8+
<service id="acme_demo.geocoder.my_provider" class="Acme\Demo\Geocoder\Provider\MyProvider">
9+
<argument type="service" id="foo_service" />
10+
<tag name="bazinga_geocoder.provider" />
11+
</service>
12+
```
13+
14+
The bundle will automatically register your provider into the`Geocoder\ProviderAggregator` service. However, it will not
15+
show up the the web profiler because it is not registered with the [PluginProvider](Resources/doc/plguins.md).
16+
17+
If you want your provider to show up the web profiler you have to create a custom factory for your provider.
18+
19+
```php
20+
namespace Acme\Demo\Geocoder\Factory;
21+
22+
use Bazinga\GeocoderBundle\ProviderFactory\AbstractFactory;
23+
use Acme\Demo\Geocoder\Provider\MyProvider;
24+
use Acme\Demo\Service\Foo;
25+
26+
final class MyFactory extends AbstractFactory
27+
{
28+
private $fooService;
29+
30+
public function __construct(Foo $service) {
31+
$this->someService = $service;
32+
}
33+
34+
protected function getProvider(array $config)
35+
{
36+
return new MyProvider($this->fooService);
37+
}
38+
}
39+
```
40+
41+
```yaml
42+
bazinga_geocoder:
43+
providers:
44+
acme:
45+
factory: Acme\Demo\Geocoder\Factory\MyFactory
46+
aliases: ['acme_demo.geocoder.my_provider']
47+
```

Resources/doc/index.md

Lines changed: 29 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,28 @@
11
BazingaGeocoderBundle
22
=====================
33

4-
Integration of the [**Geocoder**](http://github.com/geocoder-php/Geocoder)
5-
library into Symfony.
4+
Integration of the [**Geocoder**](http://github.com/geocoder-php/Geocoder) library into Symfony.
5+
6+
Our documentation has the following sections:
7+
8+
* [Index](index.md) (This page)
9+
* [Public services](services.md)
10+
* [Registering Your Own Provider](custom-provider.md)
11+
* [All about Cache](cache.md)
12+
* [Plugins](plugins.md)
13+
* [Doctrine support](doctrine.md)
14+
15+
Table of contents
16+
-----------------
617

718
* [Installation](#installation)
819
* [Usage](#usage)
920
* [Fake local ip](#fake-local-ip)
10-
* [Registering Your Own Provider](#registering-your-own-provider)
11-
* [Dumpers](#dumper)
1221
* [Cache](#cache-results)
22+
* [Dumpers](#dumper)
1323
* [Custom HTTP clients](#custom-http-clients)
14-
* [Doctrine support](Resources/doc/doctrine.md)
15-
* [Public services](Resources/doc/services.md)
1624
* [Reference Configuration](#reference-configuration)
25+
* [Backwards compatibility](#backwards-compatibility)
1726
* [Testing](#testing)
1827

1928

@@ -132,22 +141,22 @@ bazinga_geocoder:
132141
If set, the parameter will replace all instances of "127.0.0.1" in your queries and replace them with the given one.
133142

134143

135-
### Registering Your Own Providers
144+
### Cache Results
136145

137-
If you want to use your own provider in your application, create a service,
138-
and tag it as `bazinga_geocoder.provider`:
146+
Sometimes you have to cache the results from a provider. For this case the bundle provides
147+
simple configuration. You only need to provide a service name for you SimpleCache (PSR-16)
148+
service and you are good to go.
139149

140-
```xml
141-
<service id="acme_demo.geocoder.my_provider" class="Acme\Demo\Geocoder\Provider\MyProvider">
142-
<tag name="bazinga_geocoder.provider" />
143-
</service>
150+
```yaml
151+
bazinga_geocoder:
152+
providers:
153+
acme:
154+
factory: Bazinga\GeocoderBundle\ProviderFactory\GoogleMapsFactory
155+
cache: 'any.psr16.service'
156+
cache_lifetime: 3600
144157
```
145158

146-
The bundle will automatically register your provider into the
147-
`Geocoder\ProviderAggregator` service.
148-
149-
If you want your provider to show up the web profiler you have to create a custom factory
150-
for your provider.
159+
Read more about cache [here](cache.md).
151160

152161
### Dumpers
153162

@@ -190,22 +199,6 @@ To register a new dumper, you must tag it with `bazinga_geocoder.dumper`.
190199
</service>
191200
```
192201

193-
### Cache Results
194-
195-
Sometimes you have to cache the results from a provider. For this case the bundle provides
196-
simple configuration. You only need to provide a service name for you SimpleCache (PSR-16)
197-
service and you are good to go.
198-
199-
```yaml
200-
bazinga_geocoder:
201-
providers:
202-
acme:
203-
factory: Bazinga\GeocoderBundle\ProviderFactory\GoogleMapsFactory
204-
cache: 'any.psr16.service'
205-
cache_lifetime: 3600
206-
207-
```
208-
209202
### Custom HTTP Client
210203

211204
The HTTP geocoder providers integrates with [HTTPlug](http://httplug.io/). It will give you all
@@ -243,6 +236,8 @@ bazinga_geocoder:
243236
limit: 5
244237
locale: 'sv'
245238
logger: 'logger'
239+
plugins:
240+
- my_custom_plugin
246241
aliases:
247242
- acme
248243
- acme_geocoder

Resources/doc/plugins.md

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
# Plugins
2+
3+
*[<< Back to documentation index](Resources/doc/index.md)*
4+
5+
Plugins lets you modify or take actions the `Query` or the result. There are a few plugins from the `geocoder-php/plugin`
6+
package like `LimitPlugin`, `LoggerPlugin` and `CachePlugin`. Some of them are supported in the configuration.
7+
8+
```yaml
9+
# config.yml
10+
bazinga_geocoder:
11+
fake_ip:
12+
ip: '123.123.123.123' # Uses the FakeIpPlugin
13+
providers:
14+
acme:
15+
factory: Bazinga\GeocoderBundle\ProviderFactory\GoogleMapsFactory
16+
cache: 'app.cache' # Uses the CachePlugin
17+
limit: 5 # Uses the LimitPlugin
18+
locale: 'sv' # Uses the LocalePlugin
19+
logger: 'logger' # Uses the LoggerPlugin
20+
```
21+
22+
To use a any other plugins you must first register them as a service. Say you want to add some data to each query. You
23+
may then use the `QueryDataPlugin`.
24+
25+
```yaml
26+
# services.yml
27+
sevices:
28+
app.query_data_plugin:
29+
class: Geocoder\Plugin\Plugin\QueryDataPlugin
30+
arguments:
31+
- ['foo': 'bar']
32+
- true
33+
```
34+
35+
```yaml
36+
# config.yml
37+
bazinga_geocoder:
38+
providers:
39+
acme:
40+
factory: Bazinga\GeocoderBundle\ProviderFactory\GoogleMapsFactory
41+
plugins:
42+
- "app.query_data_plugin"
43+
```
44+
45+
This will execute `$query = $query->withData('foo', 'bar');` on all queries executed by the acme provider.
46+
47+
Read more about plugins at the [Geocoder's documentation](https://github.com/geocoder-php/Geocoder).

0 commit comments

Comments
 (0)