8000 Merge pull request #164 from tooblue/patch-1 · laravel-shift/GeocoderLaravel@f576885 · GitHub
[go: up one dir, main page]

Skip to content

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit f576885

Browse files
authored
Merge pull request geocoder-php#164 from tooblue/patch-1
Allow passing reader class and arguments as array
2 parents 67f027b + dde4def commit f576885

File tree

3 files changed

+21
-5
lines changed

3 files changed

+21
-5
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,8 @@ return [
182182
|
183183
| You can specify a reader for specific providers, like GeoIp2, which
184184
| connect to a local file-database. The reader should be set to an
185-
| instance of the required reader class.
185+
| instance of the required reader class or an array containing the reader
186+
| class and arguments.
186187
|
187188
| Please consult the official Geocoder documentation for more info.
188189
| https://github.com/geocoder-php/geoip2-provider

config/geocoder.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,8 @@
8888
|
8989
| You can specify a reader for specific providers, like GeoIp2, which
9090
| connect to a local file-database. The reader should be set to an
91-
| instance of the required reader class.
91+
| instance of the required reader class or an array containing the reader
92+
| class and arguments.
9293
|
9394
| Please consult the official Geocoder documentation for more info.
9495
| https://github.com/geocoder-php/geoip2-provider

src/ProviderAndDumperAggregator.php

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,18 @@ protected function getAdapterClass(string $provider) : string
221221
return config('geocoder.adapter');
222222
}
223223

224+
protected function getReader()
225+
{
226+
if (is_array(config('geocoder.reader'))) {
227+
$reflection = new ReflectionClass(config('geocoder.reader.class'));
228+
$reader = $reflection->newInstanceArgs(config('geocoder.reader.arguments'));
229+
} else {
230+
$reader = config('geocoder.reader');
231+
}
232+
233+
return $reader;
234+
}
235+
224236
protected function getArguments(array $arguments, string $provider) : array
225237
{
226238
if ($provider === 'Geocoder\Provider\Chain\Chain') {
@@ -232,9 +244,11 @@ protected function getArguments(array $arguments, string $provider) : array
232244
$adapter = $this->getAdapterClass($provider);
233245

234246
if ($adapter) {
235-
$adapter = $this->requiresReader($provider)
236-
? new $adapter(config('geocoder.reader'))
237-
: new $adapter;
247+
if ($this->requiresReader($provider)) {
248+
$adapter = new $adapter($this->getReader());
249+
} else {
250+
$adapter = new $adapter;
251+
}
238252

239253
array_unshift($arguments, $adapter);
240254
}

0 commit comments

Comments
 (0)
0