8000 Merge branch 'master' of github.com:geocoder-php/GeocoderLaravel into… · geocoder-php/GeocoderLaravel@92ecd82 · GitHub
[go: up one dir, main page]

Skip to content

Commit 92ecd82

Browse files
committed
Merge branch 'master' of github.com:geocoder-php/GeocoderLaravel into develop
2 parents 60f0724 + fd0c837 commit 92ecd82

File tree

3 files changed

+53
-11
lines changed

3 files changed

+53
-11
lines changed

CHANGELOG.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,15 @@
22
All notable changes to this project will be documented in this file.
33
This project adheres to [Semantic Versioning](http://semver.org/).
44

5+
## [4.0.9] - 28 May 2018
6+
### Added
7+
- class-name resolution from Service container, allowing for dependency
8+
injection.
9+
10+
## [4.0.8] - 25 Mar 2018
11+
### Added
12+
- work-around for missing `config_path()` function in Lumen.
13+
514
## [4.0.7] - 25 Mar 2018
615
### Added
716
- optional dedicated cache store.

README.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,19 @@ app('geocoder')->reverse(43.882587,-103.454067)->get();
234234
app('geocoder')->geocode('Los Angeles, CA')->dump('kml');
235235
```
236236

237+
#### Dependency Injection
238+
```php
239+
use Geocoder\Laravel\ProviderAndDumperAggregator as Geocoder;
240+
241+
class GeocoderController extends Controller
242+
{
243+
public function getGeocode(Geocoder $geocoder)
244+
{
245+
$geocoder->geocode('Los Angeles, CA')->get()
246+
}
247+
}
248+
```
249+
237250
## Upgrading
238251
Anytime you upgrade this package, please remember to clear your cache, to prevent incompatible cached responses when breaking changes are introduced (this should hopefully only be necessary in major versions):
239252
```sh

src/Providers/GeocoderService.php

Lines changed: 31 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,32 +11,52 @@
1111

1212
use Geocoder\Laravel\Facades\Geocoder;
1313
use Geocoder\Laravel\ProviderAndDumperAggregator;
14-
use Illuminate\Support\Collection;
1514
use Illuminate\Support\ServiceProvider;
16-
use ReflectionClass;
1715

1816
class GeocoderService extends ServiceProvider
1917
{
2018
protected $defer = false;
2119

2220
public function boot()
2321
{
24-
$configPath = __DIR__ . '/../../config/geocoder.php';
25-
$this->publishes([$configPath => config_path('geocoder.php')], 'config');
26-
$this->mergeConfigFrom($configPath, 'geocoder');
27-
$this->app->singleton('geocoder', function () {
28-
return (new ProviderAndDumperAggregator)
29-
->registerProvidersFromConfig(collect(config('geocoder.providers')));
30-
});
22+
$configPath = __DIR__ . "/../../config/geocoder.php";
23+
$this->publishes(
24+
[$configPath => $this->configPath("geocoder.php")],
25+
"config"
26+
);
27+
$this->mergeConfigFrom($configPath, "geocoder");
28+
$geocoder = (new ProviderAndDumperAggregator)
29+
->registerProvidersFromConfig(collect(config("geocoder.providers")));
30+
$this->app
31+
->singleton("geocoder", function () use ($geocoder) {
32+
return $geocoder;
33+
});
34+
$this->app
35+
->instance(ProviderAndDumperAggregator::class, $geocoder);
3136
}
3237

3338
public function register()
3439
{
35-
$this->app->alias('Geocoder', Geocoder::class);
40+
$this->app->alias("Geocoder", Geocoder::class);
3641
}
3742

3843
public function provides() : array
3944
{
40-
return ['geocoder'];
45+
return ["geocoder", ProviderAndDumperAggregator::class];
46+
}
47+
48+
protected function configPath(string $path = "") : string
49+
{
50+
if (function_exists("config_path")) {
51+
return config_path($path);
52+
}
53+
54+
$pathParts = [
55+
app()->basePath(),
56+
"config",
57+
trim($path, "/"),
58+
];
59+
60+
return implode("/", $pathParts);
4161
}
4262
}

0 commit comments

Comments
 (0)
0