diff --git a/README.md b/README.md index f4bed33..6b39109 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/config/geocoder.php b/config/geocoder.php index d04b40d..7049d01 100644 --- a/config/geocoder.php +++ b/config/geocoder.php @@ -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 diff --git a/src/ProviderAndDumperAggregator.php b/src/ProviderAndDumperAggregator.php index 714d0ad..62fe04a 100644 --- a/src/ProviderAndDumperAggregator.php +++ b/src/ProviderAndDumperAggregator.php @@ -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') { @@ -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); }