Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,8 @@ return [
|
| You can specify a reader for specific providers, like GeoIp2, which
| connect to a local file-database. The reader should be set to an
| instance of the required reader class.
| instance of the required reader class or an array containing the reader
| class and arguments.
|
| Please consult the official Geocoder documentation for more info.
| https://github.com/geocoder-php/geoip2-provider
Expand Down
3 changes: 2 additions & 1 deletion config/geocoder.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,8 @@
|
| You can specify a reader for specific providers, like GeoIp2, which
| connect to a local file-database. The reader should be set to an
| instance of the required reader class.
| instance of the required reader class or an array containing the reader
| class and arguments.
|
| Please consult the official Geocoder documentation for more info.
| https://github.com/geocoder-php/geoip2-provider
Expand Down
20 changes: 17 additions & 3 deletions src/ProviderAndDumperAggregator.php
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,18 @@ protected function getAdapterClass(string $provider) : string
return config('geocoder.adapter');
}

protected function getReader()
{
if (is_array(config('geocoder.reader'))) {
$reflection = new ReflectionClass(config('geocoder.reader.class'));
$reader = $reflection->newInstanceArgs(config('geocoder.reader.arguments'));
} else {
$reader = config('geocoder.reader');
}

return $reader;
}

protected function getArguments(array $arguments, string $provider) : array
{
if ($provider === 'Geocoder\Provider\Chain\Chain') {
Expand All @@ -232,9 +244,11 @@ protected function getArguments(array $arguments, string $provider) : array
$adapter = $this->getAdapterClass($provider);

if ($adapter) {
$adapter = $this->requiresReader($provider)
? new $adapter(config('geocoder.reader'))
: new $adapter;
if ($this->requiresReader($provider)) {
$adapter = new $adapter($this->getReader());
} else {
$adapter = new $adapter;
}

array_unshift($arguments, $adapter);
}
Expand Down